Skip to content

Commit 69e74db

Browse files
committed
Update test case - single input, reset invalid form
1 parent 5b3c761 commit 69e74db

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

test/unit/providerSpec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,42 @@ describe('provider', function() {
161161
expect(errorSpy2).toHaveBeenCalled();
162162
}));
163163

164+
it('validate - single input', inject(function() {
165+
element = $compile('<form name="Form"><input type="text" name="required" ng-model="required" validator="required"/><input type="text" name="required2" ng-model="required2" validator="required"/></form>')($scope);
166+
167+
var submitSpy = jasmine.createSpy('submitSpy');
168+
var submitSpy2 = jasmine.createSpy('submitSpy2');
169+
var successSpy = jasmine.createSpy('successSpy');
170+
var errorSpy = jasmine.createSpy('errorSpy');
171+
172+
$scope.$on('requiredsubmit-' + $scope.Form.required.validationId, function() {
173+
submitSpy();
174+
});
175+
$scope.$on('required2submit-' + $scope.Form.required2.validationId, function() {
176+
submitSpy2();
177+
});
178+
$scope.$apply(function() {
179+
$scope.required = 'Required';
180+
$scope.required2 = 'Required';
181+
});
182+
validationProvider.validate($scope.Form.required)
183+
.success(function() {
184+
successSpy();
185+
})
186+
.error(function() {
187+
errorSpy();
188+
});
189+
190+
$timeout.flush();
191+
expect(submitSpy).toHaveBeenCalled();
192+
expect(submitSpy2).not.toHaveBeenCalled();
193+
expect(successSpy).toHaveBeenCalled();
194+
expect(errorSpy).not.toHaveBeenCalled();
195+
196+
}));
197+
198+
// TODO - Missing multiple input []
199+
164200
it('validate invalid form', inject(function() {
165201
console.error = function(msg) {
166202
expect(msg).toBe('This is not a regular Form name scope');
@@ -173,6 +209,18 @@ describe('provider', function() {
173209

174210
}));
175211

212+
it('reset invalid form', inject(function() {
213+
console.error = function(msg) {
214+
expect(msg).toBe('This is not a regular Form name scope');
215+
};
216+
217+
element = $compile('<form name="Form"><input type="text" name="required" ng-model="required" validator="required"></form>')($scope);
218+
$timeout.flush();
219+
220+
validationProvider.reset($scope.Form2);
221+
222+
}));
223+
176224
it('set/get validMethod', inject(function() {
177225
expect(validationProvider.getValidMethod()).toEqual(null);
178226

0 commit comments

Comments
 (0)