forked from networked-aframe/networked-aframe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSchemas.test.js
211 lines (169 loc) · 4.59 KB
/
Schemas.test.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* global assert, process, setup, suite, test, teardown */
var Schemas = require('../../src/Schemas');
var helpers = require('./helpers');
require('../../src/NafIndex');
suite('Schemas', function() {
var schemas;
setup(function() {
schemas = new Schemas();
});
teardown(function() {
document.body.innerHTML = '';
});
suite('validateSchema', function() {
test('marks correct schema correct', function() {
var schema = {
template: '#template4',
components: [
'scale'
]
};
var result = schemas.validateSchema(schema);
assert.isTrue(result);
});
test('catches missing template property', function() {
var schema = {
components: [
'scale'
]
};
var result = schemas.validateSchema(schema);
assert.isFalse(result);
});
test('catches missing components property', function() {
var schema = {
template: '#template4'
};
var result = schemas.validateSchema(schema);
assert.isFalse(result);
});
});
suite('validateTemplate', function() {
test('catches template with more than one child', function() {
var schema = {
template: '#template4',
components: [
'position'
]
};
const template = helpers.addTemplateToDomWithChildren('template4', 2);
var result = schemas.validateTemplate(schema, template);
assert.isFalse(result);
});
test('catches template that is not a template tag', function() {
var schema = {
template: '#template',
components: [
'position'
]
};
const template = document.createElement('div');
template.id = 'template';
document.body.appendChild(template);
var result = schemas.validateTemplate(schema, template);
assert.isFalse(result);
})
});
suite('add', function() {
test('adds correct schema', function() {
helpers.addTemplateToDomWithChildren('template4', 1);
var schema = {
template: '#template4',
components: [
'scale'
]
};
schemas.add(schema);
var result = schemas.hasTemplate(schema.template);
assert.isTrue(result);
});
test('invalid schema not added', function() {
var schema = {
template: '#template4'
};
schemas.add(schema);
var result = schemas.hasTemplate(schema.template);
assert.isFalse(result);
});
test('invalid template not added', function() {
helpers.addTemplateToDomWithChildren('template4', 2);
var schema = {
template: '#template4',
components: [
'scale'
]
};
schemas.add(schema);
var result = schemas.hasTemplate(schema.template);
assert.isTrue(result);
});
});
suite('getComponents', function() {
test('gets correct components', function() {
var schema = {
template: '#template4',
components: [
'comp1',
'comp2'
]
};
schemas.add(schema);
var result = schemas.getComponents(schema.template);
assert.deepEqual(result, schema.components);
});
test('returns defaults for incorrect template', function() {
var schema = {
template: '#template4',
components: [
'comp1',
'comp2'
]
};
schemas.add(schema);
var result = schemas.getComponents('wrong');
assert.deepEqual(result, ['position', 'rotation']);
});
});
suite('clear', function() {
test('removes all schemas', function() {
helpers.addTemplateToDomWithChildren('template4', 1);
helpers.addTemplateToDomWithChildren('templasd', 1);
var schema1 = {
template: '#template4',
components: [
'comp1',
'comp2'
]
};
var schema2 = {
template: '#templasd',
components: [
'comp1',
'comp2'
]
};
schemas.add(schema1);
schemas.add(schema2);
schemas.clear();
var result1 = schemas.hasTemplate(schema1.template);
var result2 = schemas.hasTemplate(schema2.template);
assert.isFalse(result1);
assert.isFalse(result2);
});
});
suite('clear', function() {
test('removes all schemas', function() {
var schema = {
template: '#template4',
components: [
'comp1',
'comp2'
]
};
schemas.add(schema);
schemas.remove(schema.template);
var result = schemas.hasTemplate(schema.template);
assert.isFalse(result);
});
});
});