-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
Copy pathtextarea-curly-test.js
165 lines (128 loc) · 4.95 KB
/
textarea-curly-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
import { RenderingTestCase, moduleFor, classes, applyMixins, runTask } from 'internal-test-helpers';
import { assign } from '@ember/polyfills';
import { set } from '@ember/-internals/metal';
class TextAreaRenderingTest extends RenderingTestCase {
assertTextArea({ attrs, value } = {}) {
let mergedAttrs = assign({ class: classes('ember-view ember-text-area') }, attrs);
this.assertComponentElement(this.firstChild, {
tagName: 'textarea',
attrs: mergedAttrs,
});
if (value) {
this.assert.strictEqual(value, this.firstChild.value);
}
}
triggerEvent(type, options = {}) {
let event = document.createEvent('Events');
event.initEvent(type, true, true);
assign(event, options);
this.firstChild.dispatchEvent(event);
}
}
class BoundTextAreaAttributes {
constructor(cases) {
this.cases = cases;
}
generate({ attribute, first, second }) {
return {
[`@test ${attribute}`]() {
this.render(`{{textarea ${attribute}=value}}`, {
value: first,
});
this.assertTextArea({ attrs: { [attribute]: first } });
this.assertStableRerender();
runTask(() => set(this.context, 'value', second));
this.assertTextArea({ attrs: { [attribute]: second } });
runTask(() => set(this.context, 'value', first));
this.assertTextArea({ attrs: { [attribute]: first } });
},
};
}
}
applyMixins(
TextAreaRenderingTest,
new BoundTextAreaAttributes([
{ attribute: 'placeholder', first: 'Stuff here', second: 'Other stuff' },
{ attribute: 'name', first: 'Stuff here', second: 'Other stuff' },
{ attribute: 'title', first: 'Stuff here', second: 'Other stuff' },
{ attribute: 'maxlength', first: '1', second: '2' },
{ attribute: 'rows', first: '1', second: '2' },
{ attribute: 'cols', first: '1', second: '2' },
{ attribute: 'tabindex', first: '1', second: '2' },
])
);
moduleFor(
'Components test: {{textarea}}',
class extends TextAreaRenderingTest {
['@test Should insert a textarea'](assert) {
this.render('{{textarea}}');
assert.equal(this.$('textarea').length, 1);
this.assertStableRerender();
}
['@test Should respect disabled'](assert) {
this.render('{{textarea disabled=disabled}}', {
disabled: true,
});
assert.ok(this.$('textarea').is(':disabled'));
}
['@test Should respect disabled when false'](assert) {
this.render('{{textarea disabled=disabled}}', {
disabled: false,
});
assert.ok(this.$('textarea').is(':not(:disabled)'));
}
['@test Should become disabled when the context changes'](assert) {
this.render('{{textarea disabled=disabled}}');
assert.ok(this.$('textarea').is(':not(:disabled)'));
this.assertStableRerender();
runTask(() => set(this.context, 'disabled', true));
assert.ok(this.$('textarea').is(':disabled'));
runTask(() => set(this.context, 'disabled', false));
assert.ok(this.$('textarea').is(':not(:disabled)'));
}
['@test Should bind its contents to the specified value']() {
this.render('{{textarea value=model.val}}', {
model: { val: 'A beautiful day in Seattle' },
});
this.assertTextArea({ value: 'A beautiful day in Seattle' });
this.assertStableRerender();
runTask(() => set(this.context, 'model.val', 'Auckland'));
this.assertTextArea({ value: 'Auckland' });
runTask(() => set(this.context, 'model', { val: 'A beautiful day in Seattle' }));
this.assertTextArea({ value: 'A beautiful day in Seattle' });
}
['@test GH#14001 Should correctly handle an empty string bound value']() {
this.render('{{textarea value=message}}', { message: '' });
this.assert.strictEqual(this.firstChild.value, '');
this.assertStableRerender();
runTask(() => set(this.context, 'message', 'hello'));
this.assert.strictEqual(this.firstChild.value, 'hello');
runTask(() => set(this.context, 'message', ''));
this.assert.strictEqual(this.firstChild.value, '');
}
['@test should update the value for `cut` / `input` / `change` events']() {
this.render('{{textarea value=model.val}}', {
model: { val: 'A beautiful day in Seattle' },
});
this.assertTextArea({ value: 'A beautiful day in Seattle' });
this.assertStableRerender();
runTask(() => {
this.firstChild.value = 'Auckland';
this.triggerEvent('cut');
});
this.assertTextArea({ value: 'Auckland' });
runTask(() => {
this.firstChild.value = 'Hope';
this.triggerEvent('paste');
});
this.assertTextArea({ value: 'Hope' });
runTask(() => {
this.firstChild.value = 'Boston';
this.triggerEvent('input');
});
this.assertTextArea({ value: 'Boston' });
runTask(() => set(this.context, 'model', { val: 'A beautiful day in Seattle' }));
this.assertTextArea({ value: 'A beautiful day in Seattle' });
}
}
);