forked from json-schema-form/angular-schema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf-field.directive.spec.js
80 lines (72 loc) · 1.88 KB
/
sf-field.directive.spec.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
chai.should();
var runSync = function (scope, tmpl) {
var directiveScope = tmpl.isolateScope();
var stub = sinon.stub(directiveScope, 'resolveReferences', function(schema, form) {
directiveScope.render(schema, form);
});
scope.$apply();
}
describe('sf-field.directive.js',function() {
beforeEach(module('schemaForm'));
beforeEach(
module(function($sceProvider){
$sceProvider.enabled(false);
})
);
var keyTests = [
{
name: 'array of objects',
targetKey: ['arrayOfObjects', 0, 'stringVal'],
schema: {
type: 'object',
properties: {
arrayOfObjects: {
type: 'array',
items: {
type: 'object',
properties: {
stringVal: {
type: 'string',
'x-schema-form': {
htmlClass: 'targetKey'
}
}
}
}
}
}
},
},
{
name: 'array of strings',
targetKey: ['arrayOfStrings', 0],
schema: {
type: 'object',
properties: {
arrayOfStrings: {
type: 'array',
items: {
type: 'string',
'x-schema-form': {
htmlClass: 'targetKey'
}
}
}
}
}
}
];
keyTests.forEach(function(keyTest) {
it('should generate correct form keys for ' + keyTest.name, function(done) {
inject(function($compile,$rootScope) {
var scope = $rootScope.$new();
scope.model = {};
scope.schema = keyTest.schema;
var tmpl = angular.element('<form sf-schema="schema" sf-model="model"></form>');
$compile(tmpl)(scope);
runSync(scope, tmpl);
tmpl.children().find('.targetKey').scope().form.key.should.deep.equal(keyTest.targetKey);
});
});
});
});