Skip to content

Commit a61e634

Browse files
committed
tests: sf-field tests for form.key generation
issue json-schema-form/angular-schema-form#870
1 parent 138b618 commit a61e634

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
chai.should();
2+
3+
var runSync = function (scope, tmpl) {
4+
var directiveScope = tmpl.isolateScope();
5+
var stub = sinon.stub(directiveScope, 'resolveReferences', function(schema, form) {
6+
directiveScope.render(schema, form);
7+
});
8+
scope.$apply();
9+
}
10+
11+
describe('sf-field.directive.js',function() {
12+
beforeEach(module('schemaForm'));
13+
beforeEach(
14+
module(function($sceProvider){
15+
$sceProvider.enabled(false);
16+
})
17+
);
18+
19+
var keyTests = [
20+
{
21+
name: 'array of objects',
22+
targetKey: ['arrayOfObjects', 0, 'stringVal'],
23+
schema: {
24+
type: 'object',
25+
properties: {
26+
arrayOfObjects: {
27+
type: 'array',
28+
items: {
29+
type: 'object',
30+
properties: {
31+
stringVal: {
32+
type: 'string',
33+
'x-schema-form': {
34+
htmlClass: 'targetKey'
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}
41+
},
42+
},
43+
44+
{
45+
name: 'array of strings',
46+
targetKey: ['arrayOfStrings', 0],
47+
schema: {
48+
type: 'object',
49+
properties: {
50+
arrayOfStrings: {
51+
type: 'array',
52+
items: {
53+
type: 'string',
54+
'x-schema-form': {
55+
htmlClass: 'targetKey'
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}
62+
];
63+
64+
keyTests.forEach(function(keyTest) {
65+
it('should generate correct form keys for ' + keyTest.name, function(done) {
66+
inject(function($compile,$rootScope) {
67+
var scope = $rootScope.$new();
68+
scope.model = {};
69+
scope.schema = keyTest.schema;
70+
71+
var tmpl = angular.element('<form sf-schema="schema" sf-model="model"></form>');
72+
73+
$compile(tmpl)(scope);
74+
runSync(scope, tmpl);
75+
76+
tmpl.children().find('.targetKey').scope().form.key.should.deep.equal(keyTest.targetKey);
77+
});
78+
});
79+
});
80+
});

0 commit comments

Comments
 (0)