Skip to content

Commit cf7276a

Browse files
committed
add test for array onChange
1 parent a1e3d65 commit cf7276a

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

test/directives/schema-form-test.js

+43-1
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,49 @@ describe('directive',function(){
18271827
});
18281828
});
18291829

1830+
it('should handle onChange for array type', function () {
1831+
inject(function($compile,$rootScope){
1832+
var scope = $rootScope.$new();
1833+
scope.obj = {};
1834+
1835+
scope.schema = {
1836+
"type": "object",
1837+
"properties": {
1838+
"arr" : {
1839+
"type": "array",
1840+
"items": {
1841+
"type": "object",
1842+
"properties": {
1843+
"name": {
1844+
"type": "string",
1845+
"default": "Name"
1846+
}
1847+
}
1848+
}
1849+
}
1850+
}
1851+
};
1852+
1853+
scope.form = [{key : "arr", startEmpty : true, onChange: sinon.spy()}];
1854+
1855+
var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="obj"></form>');
1856+
1857+
$compile(tmpl)(scope);
1858+
$rootScope.$apply();
1859+
1860+
1861+
scope.form[0].onChange.should.not.have.been.called;
1862+
1863+
1864+
tmpl.find('button.btn-default').click();
1865+
scope.form[0].onChange.should.have.been.calledWith([{name : "Name"}]);
1866+
1867+
tmpl.find('button.close').click();
1868+
scope.form[0].onChange.should.have.been.calledWith([]);
1869+
1870+
});
1871+
});
1872+
18301873
it('should load template by templateUrl, with template field type',function() {
18311874

18321875
inject(function($compile, $rootScope, $httpBackend){
@@ -2358,7 +2401,6 @@ describe('directive',function(){
23582401
});
23592402
});
23602403

2361-
23622404
});
23632405

23642406
});

0 commit comments

Comments
 (0)