-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
local-lookup-test.js
137 lines (95 loc) · 4.43 KB
/
local-lookup-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
import { moduleFor, RenderingTest } from '../../utils/test-case';
import { Component } from '../../utils/helpers';
// copied from ember-htmlbars/tests/integration/local-lookup-test.js
function buildResolver() {
let resolver = {
resolve() { },
expandLocalLookup(fullName, sourceFullName) {
let [sourceType, sourceName ] = sourceFullName.split(':');
let [type, name ] = fullName.split(':');
if (type !== 'template' && sourceType === 'template' && sourceName.slice(0, 11) === 'components/') {
sourceName = sourceName.slice(11);
}
if (type === 'template' && sourceType === 'template' && name.slice(0, 11) === 'components/') {
name = name.slice(11);
}
let result = `${type}:${sourceName}/${name}`;
return result;
}
};
return resolver;
}
moduleFor('Components test: local lookup', class extends RenderingTest {
getOwnerOptions() {
return {
_registryOptions: {
resolver: buildResolver()
}
};
}
['@htmlbars it can lookup a local template']() {
this.registerComponent('x-outer/x-inner', { template: 'Nested template says: {{yield}}' });
this.registerComponent('x-outer', { template: '{{#x-inner}}Hi!{{/x-inner}}' });
this.render('{{x-outer}}');
this.assertText('Nested template says: Hi!', 'Initial render works');
this.runTask(() => this.rerender());
this.assertText('Nested template says: Hi!', 'Re-render works');
}
['@htmlbars tagless blockless component can lookup local template'](assert) {
this.registerComponent('x-outer/x-inner', { template: 'Nested template says: {{yield}}' });
this.registerTemplate('components/x-outer', '{{#x-inner}}Hi!{{/x-inner}}');
this.registerComponent('x-outer', {
ComponentClass: Component.extend({ tagName: '' })
});
this.render('{{x-outer}}');
this.assertText('Nested template says: Hi!', 'Re-render works');
this.runTask(() => this.rerender());
this.assertText('Nested template says: Hi!', 'Re-render works');
}
['@htmlbars it can lookup a local component template']() {
this.registerTemplate('components/x-outer/x-inner', 'Nested template says: {{yield}}');
this.registerTemplate('components/x-outer', '{{#x-inner}}Hi!{{/x-inner}}');
this.render('{{x-outer}}');
this.assertText('Nested template says: Hi!', 'Initial render works');
this.runTask(() => this.rerender());
this.assertText('Nested template says: Hi!', 'Re-render works');
}
['@htmlbars it can lookup a local helper']() {
this.registerHelper('x-outer/x-helper', () => {
return 'Who dis?';
});
this.registerComponent('x-outer', { template: 'Who dat? {{x-helper}}' });
this.render('{{x-outer}}');
this.assertText('Who dat? Who dis?', 'Initial render works');
this.runTask(() => this.rerender());
this.assertText('Who dat? Who dis?', 'Re-render works');
}
['@htmlbars it overrides global helper lookup']() {
this.registerHelper('x-outer/x-helper', () => {
return 'Who dis?';
});
this.registerHelper('x-helper', () => {
return 'I dunno';
});
this.registerComponent('x-outer', { template: 'Who dat? {{x-helper}}' });
this.render('{{x-outer}} {{x-helper}}');
this.assertText('Who dat? Who dis? I dunno', 'Initial render works');
this.runTask(() => this.rerender());
this.assertText('Who dat? Who dis? I dunno', 'Re-render works');
}
['@htmlbars lookup without match issues standard assertion (with local helper name)']() {
this.registerComponent('x-outer', { template: '{{#x-inner}}Hi!{{/x-inner}}' });
expectAssertion(() => {
this.render('{{x-outer}}');
}, /A helper named "x-inner" could not be found/);
}
['@htmlbars overrides global lookup']() {
this.registerComponent('x-outer', { template: '{{#x-inner}}Hi!{{/x-inner}}' });
this.registerComponent('x-outer/x-inner', { template: 'Nested template says (from local): {{yield}}' });
this.registerComponent('x-inner', { template: 'Nested template says (from global): {{yield}}' });
this.render('{{#x-inner}}Hi!{{/x-inner}} {{x-outer}} {{#x-outer/x-inner}}Hi!{{/x-outer/x-inner}}');
this.assertText('Nested template says (from global): Hi! Nested template says (from local): Hi! Nested template says (from local): Hi!');
this.runTask(() => this.rerender());
this.assertText('Nested template says (from global): Hi! Nested template says (from local): Hi! Nested template says (from local): Hi!');
}
});