Skip to content

Commit dde98e1

Browse files
committed
Add test based on #374 and #295
1 parent 7db0629 commit dde98e1

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/directives/sf-schema.directive.spec.js

+50
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,56 @@ describe('sf-schema.directive.js', function() {
19551955
});
19561956
});
19571957

1958+
it('should handle onChange for array type', function () {
1959+
//TODO confirmt the logic is sound
1960+
inject(function($compile,$rootScope){
1961+
var scope = $rootScope.$new();
1962+
scope.obj = {};
1963+
1964+
scope.schema = {
1965+
"type": "object",
1966+
"properties": {
1967+
"arr" : {
1968+
"type": "array",
1969+
"items": {
1970+
"type": "object",
1971+
"properties": {
1972+
"name": {
1973+
"type": "string",
1974+
"default": "Name"
1975+
}
1976+
}
1977+
}
1978+
}
1979+
}
1980+
};
1981+
1982+
var spy = sinon.spy();
1983+
scope.form = [{key : "arr", startEmpty : true, onChange: spy}];
1984+
1985+
var tmpl = angular.element('<form sf-schema="schema" sf-form="form" sf-model="obj"></form>');
1986+
1987+
$compile(tmpl)(scope);
1988+
runSync(scope, tmpl);
1989+
1990+
spy.should.have.been.called.once;
1991+
1992+
tmpl.find('button.btn-default').click();
1993+
1994+
// Test that "[{name: 'Name'}]" exists even if $$hashKey is defined
1995+
var test = sinon.match(function (value) {
1996+
if(value && value[0] && value[0].name === "Name") return true;
1997+
return false;
1998+
}, "[{name: 'Name'}]");
1999+
2000+
spy.should.have.been.calledWith(test);
2001+
2002+
tmpl.find('button.close').click();
2003+
spy.should.have.been.calledWith([]);
2004+
2005+
});
2006+
});
2007+
19582008
it('should load template by templateUrl, with template field type',function() {
19592009

19602010
inject(function($compile, $rootScope, $httpBackend) {

0 commit comments

Comments
 (0)