MatrixValidationSpec.js
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Created by Techniv on 12/01/2017.
*/
describe('matrix-validation Spec', function(){
var $compile, $rootScope, $timeout, template;
beforeEach(module('matrixValidation'));
beforeEach(inject(function (_$compile_, _$rootScope_, _$timeout_) {
$compile = _$compile_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
}));
beforeEach(function () {
template = $compile(
'<form name="mForm" matrix-validator data-all="validator">\
<span ng-repeat="row in matrix" ng-init="rowId = $index">\
<input name="i{{rowId}}{{$index}}" ng-repeat="item in row track by $index" data-row="rowId" data-col="$index" ng-model="row[$index]">\
</span>\
</form>');
});
beforeEach(function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
});
it('test', function(done){
var $scope = $rootScope.$new();
$scope.matrix = [
[1,2,3],
[2,3,1],
[3,1,2]
];
$scope.validator = validator;
var element = template($scope);
$scope.$digest();
$timeout.flush();
var inputs = element.find('input');
for(var i = 0; i < inputs.length; i++){
var input = angular.element(inputs[i]);
var scope = input.scope();
var name = inputs[i].name;
var ngInput = scope.mForm[name];
expect(ngInput.$valid).toEqual(validator.last[scope.rowId][scope.$index]);
}
var input = angular.element(inputs[6]);
input.val(1);
input.triggerHandler('change');
setTimeout(function () {
expect(scope.mForm.i20.$valid).toBe(false);
expect(scope.mForm.i00.$valid).toBe(false);
done();
},500);
});
});