/
composer-test.js.es6
282 lines (236 loc) · 9.57 KB
/
composer-test.js.es6
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import { acceptance } from "helpers/qunit-helpers";
acceptance("Composer", { loggedIn: true });
test("Tests the Composer controls", () => {
visit("/");
andThen(() => {
ok(exists('#create-topic'), 'the create button is visible');
});
click('#create-topic');
andThen(() => {
ok(exists('.d-editor-input'), 'the composer input is visible');
ok(exists('.title-input .popup-tip.bad.hide'), 'title errors are hidden by default');
ok(exists('.d-editor-textarea-wrapper .popup-tip.bad.hide'), 'body errors are hidden by default');
});
click('a.toggle-preview');
andThen(() => {
ok(!exists('.d-editor-preview:visible'), "clicking the toggle hides the preview");
});
click('a.toggle-preview');
andThen(() => {
ok(exists('.d-editor-preview:visible'), "clicking the toggle shows the preview again");
});
click('#reply-control button.create');
andThen(() => {
ok(!exists('.title-input .popup-tip.bad.hide'), 'it shows the empty title error');
ok(!exists('.d-editor-wrapper .popup-tip.bad.hide'), 'it shows the empty body error');
});
fillIn('#reply-title', "this is my new topic title");
andThen(() => {
ok(exists('.title-input .popup-tip.good'), 'the title is now good');
});
fillIn('.d-editor-input', "this is the *content* of a post");
andThen(() => {
equal(find('.d-editor-preview').html().trim(), "<p>this is the <em>content</em> of a post</p>", "it previews content");
ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good');
});
andThen(() => {
// Testing keyboard events is tough!
const mac = /Mac|iPod|iPhone|iPad/.test(navigator.platform);
const event = document.createEvent('Event');
event.initEvent('keydown', true, true);
event[mac ? 'metaKey' : 'ctrlKey'] = true;
event.keyCode = 66;
find('#reply-control .d-editor-input')[0].dispatchEvent(event);
});
andThen(() => {
const example = I18n.t(`composer.bold_text`);
equal(find('#reply-control .d-editor-input').val().trim(),
`this is the *content* of a post**${example}**`,
"it supports keyboard shortcuts");
});
click('#reply-control a.cancel');
andThen(() => {
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
});
click('.modal-footer a:eq(1)');
andThen(() => {
ok(!exists('.bootbox.modal'), 'the confirmation can be cancelled');
});
});
test("Create a topic with server side errors", () => {
visit("/");
click('#create-topic');
fillIn('#reply-title', "this title triggers an error");
fillIn('.d-editor-input', "this is the *content* of a post");
click('#reply-control button.create');
andThen(() => {
ok(exists('.bootbox.modal'), 'it pops up an error message');
});
click('.bootbox.modal a.btn-primary');
andThen(() => {
ok(!exists('.bootbox.modal'), 'it dismisses the error');
ok(exists('.d-editor-input'), 'the composer input is visible');
});
});
test("Create a Topic", () => {
visit("/");
click('#create-topic');
fillIn('#reply-title', "Internationalization Localization");
fillIn('.d-editor-input', "this is the *content* of a new topic post");
click('#reply-control button.create');
andThen(() => {
equal(currentURL(), "/t/internationalization-localization/280", "it transitions to the newly created topic URL");
});
});
test("Create an enqueued Topic", () => {
visit("/");
click('#create-topic');
fillIn('#reply-title', "Internationalization Localization");
fillIn('.d-editor-input', "enqueue this content please");
click('#reply-control button.create');
andThen(() => {
ok(visible('#discourse-modal'), 'it pops up a modal');
equal(currentURL(), "/", "it doesn't change routes");
});
click('.modal-footer button');
andThen(() => {
ok(invisible('#discourse-modal'), 'the modal can be dismissed');
});
});
test("Create a Reply", () => {
visit("/t/internationalization-localization/280");
andThen(() => {
ok(!exists('article[data-post-id=12345]'), 'the post is not in the DOM');
});
click('#topic-footer-buttons .btn.create');
andThen(() => {
ok(exists('.d-editor-input'), 'the composer input is visible');
ok(!exists('#reply-title'), 'there is no title since this is a reply');
});
fillIn('.d-editor-input', 'this is the content of my reply');
click('#reply-control button.create');
andThen(() => {
equal(find('.cooked:last p').text(), 'this is the content of my reply');
});
});
test("Posting on a different topic", (assert) => {
visit("/t/internationalization-localization/280");
click('#topic-footer-buttons .btn.create');
fillIn('.d-editor-input', 'this is the content for a different topic');
visit("/t/1-3-0beta9-no-rate-limit-popups/28830");
andThen(function() {
assert.equal(currentURL(), "/t/1-3-0beta9-no-rate-limit-popups/28830");
});
click('#reply-control button.create');
andThen(function() {
assert.ok(visible('.reply-where-modal'), 'it pops up a modal');
});
click('.btn-reply-here');
andThen(() => {
assert.equal(find('.cooked:last p').text(), 'this is the content for a different topic');
});
});
test("Create an enqueued Reply", () => {
visit("/t/internationalization-localization/280");
click('#topic-footer-buttons .btn.create');
andThen(() => {
ok(exists('.d-editor-input'), 'the composer input is visible');
ok(!exists('#reply-title'), 'there is no title since this is a reply');
});
fillIn('.d-editor-input', 'enqueue this content please');
click('#reply-control button.create');
andThen(() => {
ok(find('.cooked:last p').text() !== 'enqueue this content please', "it doesn't insert the post");
});
andThen(() => {
ok(visible('#discourse-modal'), 'it pops up a modal');
});
click('.modal-footer button');
andThen(() => {
ok(invisible('#discourse-modal'), 'the modal can be dismissed');
});
});
test("Edit the first post", () => {
visit("/t/internationalization-localization/280");
ok(!exists('.topic-post:eq(0) .post-info.edits'), 'it has no edits icon at first');
click('.topic-post:eq(0) button[data-action=showMoreActions]');
click('.topic-post:eq(0) button[data-action=edit]');
andThen(() => {
equal(find('.d-editor-input').val().indexOf('Any plans to support'), 0, 'it populates the input with the post text');
});
fillIn('.d-editor-input', "This is the new text for the post");
fillIn('#reply-title', "This is the new text for the title");
click('#reply-control button.create');
andThen(() => {
ok(!exists('.d-editor-input'), 'it closes the composer');
ok(exists('.topic-post:eq(0) .post-info.edits'), 'it has the edits icon');
ok(find('#topic-title h1').text().indexOf('This is the new text for the title') !== -1, 'it shows the new title');
ok(find('.topic-post:eq(0) .cooked').text().indexOf('This is the new text for the post') !== -1, 'it updates the post');
});
});
test("Composer can switch between edits", () => {
visit("/t/this-is-a-test-topic/9");
click('.topic-post:eq(0) button[data-action=edit]');
andThen(() => {
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
});
click('.topic-post:eq(1) button[data-action=edit]');
andThen(() => {
equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text');
});
});
test("Composer with dirty edit can toggle to another edit", () => {
visit("/t/this-is-a-test-topic/9");
click('.topic-post:eq(0) button[data-action=edit]');
fillIn('.d-editor-input', 'This is a dirty reply');
click('.topic-post:eq(1) button[data-action=edit]');
andThen(() => {
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
});
click('.modal-footer a:eq(0)');
andThen(() => {
equal(find('.d-editor-input').val().indexOf('This is the second post.'), 0, 'it populates the input with the post text');
});
});
test("Composer can toggle between edit and reply", () => {
visit("/t/this-is-a-test-topic/9");
click('.topic-post:eq(0) button[data-action=edit]');
andThen(() => {
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
});
click('.topic-post:eq(0) button[data-action=reply]');
andThen(() => {
equal(find('.d-editor-input').val(), "", 'it clears the input');
});
click('.topic-post:eq(0) button[data-action=edit]');
andThen(() => {
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
});
});
test("Composer with dirty reply can toggle to edit", () => {
visit("/t/this-is-a-test-topic/9");
click('.topic-post:eq(0) button[data-action=reply]');
fillIn('.d-editor-input', 'This is a dirty reply');
click('.topic-post:eq(0) button[data-action=edit]');
andThen(() => {
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
});
click('.modal-footer a:eq(0)');
andThen(() => {
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
});
});
test("Composer draft with dirty reply can toggle to edit", () => {
visit("/t/this-is-a-test-topic/9");
click('.topic-post:eq(0) button[data-action=reply]');
fillIn('.d-editor-input', 'This is a dirty reply');
click('.toggler');
click('.topic-post:eq(0) button[data-action=edit]');
andThen(() => {
ok(exists('.bootbox.modal'), 'it pops up a confirmation dialog');
});
click('.modal-footer a:eq(0)');
andThen(() => {
equal(find('.d-editor-input').val().indexOf('This is the first post.'), 0, 'it populates the input with the post text');
});
});