-
Notifications
You must be signed in to change notification settings - Fork 18
/
cafe-test.js
372 lines (334 loc) · 11.9 KB
/
cafe-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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/* eslint-disable no-undef */
import { Selector, t } from 'testcafe';
// https://github.com/DevExpress/testcafe/issues/6844
fixture('basic').page('http://localhost:3000');
// generic button selectors
const textButton = (text) => Selector('button').withExactText(text);
const titleButton = (title) => Selector('button').withAttribute('title', title);
const labelButton = (label) =>
Selector('button').withAttribute('aria-label', label);
// generic input selectors
const nameInput = (name) => Selector('input').withAttribute('name', name);
const placeholderInput = (placeholder) =>
Selector('input').withAttribute('placeholder', placeholder);
const valueInput = (name, value) =>
nameInput(name).withAttribute('value', value);
const typeSelect = (type) =>
Selector('button')
.withText(type)
.withAttribute('aria-label', `Select ${type}`);
const typeMenu = (type) =>
textButton(type).withAttribute('aria-label', 'Open Menu');
const select = async (type, index, name) => {
let selector = typeSelect(name || type);
if (index !== undefined) selector = selector.nth(index);
await t.click(selector).expect(typeMenu(type).exists).ok();
};
const add = async (type, search) => {
const addControl = titleButton('add a component');
const typeAddControl = labelButton(`Add ${type}`);
// open add layer
await t.click(addControl).expect(typeAddControl.exists).ok();
if (search) {
const addSearchInput = placeholderInput('search ...');
await t.typeText(addSearchInput, search).expect(typeAddControl.exists).ok();
}
// add type
await t.click(typeAddControl).expect(typeMenu(type).exists).ok();
};
const newControl = Selector('a').withAttribute('title', 'start a new design');
const designName = 'test design';
const createDesignControl = textButton('Create Design');
const useScreenControl = textButton('Use Template');
const empty = Selector('p').withExactText(
'This PageContent is currently empty. Add some content to it.',
);
const undoControl = titleButton('undo last change');
const redoControl = titleButton('redo last change');
const pageTitle = Selector('h1').withExactText('Test Page');
const closeLayerControl = textButton('Close Layer');
const openLayerControl = textButton('Open Layer');
const linkLabel = Selector('label').withExactText('link');
const testLayerOption = textButton('test layer').withAttribute(
'role',
'option',
);
const testAlternativeOption = textButton('test alternative').withAttribute(
'role',
'option',
);
const addActionsControl = labelButton('Add actions');
const backPageHeaderControl = textButton('back to Test Page');
const secondScreenControl = textButton('Second Screen');
const firstScreenLink = Selector('a').withExactText('First Screen Link');
const firstScreenOption = textButton('Test Screen').withAttribute(
'role',
'option',
);
// const secondScreenLink = Selector('a').withExactText('Second Screen Link');
const addDataControl = labelButton('add a data source');
const dataControl = textButton('data');
const dataSelectControl = dataControl.withAttribute(
'aria-label',
'Select data',
);
const dataArea = Selector('textarea').withAttribute('name', 'data');
const alphaTableHeader = Selector('th').withExactText('alpha');
// const closeControl = Selector('button').withAttribute('title', 'close');
test('create design', async (t) => {
// from the Start
await t.expect(newControl.exists).ok();
// NewDesign
await t.click(newControl).expect(nameInput('name').exists).ok();
// give it a name
await t
.typeText(nameInput('name'), designName)
.expect(createDesignControl.exists)
.ok();
// NewScreen
await t.click(createDesignControl).expect(useScreenControl.exists).ok();
// select a blank screen
await t.click(useScreenControl).expect(empty.exists).ok();
// rename screen
await select('Screen');
await t
.typeText(nameInput('name'), 'Test Screen', { replace: true })
.expect(textButton('Test Screen').exists)
.ok();
// add a PageHeader and give it a title
await select('PageContent');
await add('PageHeader', 'Page');
await t
.typeText(nameInput('title'), 'Test Page')
.expect(pageTitle.exists)
.ok();
// add a Layer with a Button that will close it
await select('PageContent');
await add('Layer');
await t.typeText(nameInput('name'), 'test layer');
await add('Button');
// set button label
await t
.typeText(nameInput('label'), 'Close Layer', { replace: true })
.expect(closeLayerControl.exists)
.ok();
// set button link
await t.click(linkLabel).expect(testLayerOption.exists).ok();
await t.click(testLayerOption).expect(testLayerOption.exists).notOk();
// close the Layer
await t.click(closeLayerControl).expect(closeLayerControl.exists).notOk();
// add actions to the PageHeader to open the layer
// tests property component editing
await select('PageHeader', undefined, 'Test Page');
// add actions
await t.click(addActionsControl).expect(backPageHeaderControl.exists).ok();
await add('Button');
await t
.typeText(nameInput('label'), 'Open Layer', { replace: true })
.expect(openLayerControl.exists)
.ok();
// set button link
await t.click(linkLabel).expect(testLayerOption.exists).ok();
await t.click(testLayerOption).expect(testLayerOption.exists).notOk();
// done with PageHeader actions
await t
.click(backPageHeaderControl)
.expect(backPageHeaderControl.exists)
.notOk();
// open the Layer
await t.click(openLayerControl).expect(closeLayerControl.exists).ok();
// close the Layer
await t.click(closeLayerControl).expect(closeLayerControl.exists).notOk();
// add an Alternative and link to it with two buttons inside
await select('PageContent');
await add('Alternative');
await t.typeText(nameInput('name'), 'test alternative');
// first Button
await add('Button');
await t
.typeText(nameInput('label'), 'First', { replace: true })
.expect(textButton('First').exists)
.ok();
// set button link to alternative
await t.click(linkLabel).expect(testAlternativeOption.exists).ok();
await t
.click(testAlternativeOption)
.expect(testAlternativeOption.exists)
.notOk();
// second Button
await select('Alternative', undefined, 'test alternative');
await add('Button');
await t
.typeText(nameInput('label'), 'Second', { replace: true })
.expect(Selector('button').withText('Second').exists) // not in canvas
.ok();
// set button link to alternative
await t.click(linkLabel).expect(testAlternativeOption.exists).ok();
await t
.click(testAlternativeOption)
.expect(testAlternativeOption.exists)
.notOk();
// click First
await t.click(textButton('First')).expect(textButton('Second').exists).ok();
// click Second
await t.click(textButton('Second')).expect(textButton('First').exists).ok();
// add a screen with a link to the first screen
await add('Screen');
// set screen name
await t
.typeText(nameInput('name'), 'Second Screen', { replace: true })
.expect(secondScreenControl.exists)
.ok();
// select simple page screen template
await t.click(useScreenControl).expect(empty.exists).ok();
// select the second screen's PageContent
await select('PageContent', 1);
await add('Anchor');
// set anchor label
await t
.typeText(nameInput('label'), 'First Screen Link', { replace: true })
.expect(firstScreenLink.exists)
.ok();
// ensure undo/redo changes have absorbed the anchor label change
await t.wait(1000);
// undo
await t.click(undoControl).expect(firstScreenLink.exists).notOk();
// redo
await t.click(redoControl).expect(firstScreenLink.exists).ok();
// set anchor link
await t.click(linkLabel).expect(firstScreenOption.exists).ok();
await t.click(firstScreenOption).expect(firstScreenOption.exists).notOk();
// follow link to first screen
// TODO: the following isn't working, seems like TestCafe isn't sending
// the 'shift' modifier
// // with shift key, shouldn't navigate
// await t
// .click(firstScreenLink, { modifiers: { shift: true } })
// .expect(pageTitle.exists)
// .notOk();
// without shift, should navigate
await t.click(firstScreenLink).expect(pageTitle.exists).ok();
// add data
// add
await t.click(addDataControl).expect(dataSelectControl.exists).ok();
await t.expect(dataArea.exists).ok();
// type data
await t
.typeText(dataArea, '[{"name": "alpha"},{"name": "beta"}]', {
replace: true,
})
.expect(dataSelectControl.exists)
.ok();
// select first screen's PageContent
await select('PageContent', 0);
await add('DataTable');
// set dataPath to data
await t
.typeText(nameInput('dataPath'), 'data', { replace: true })
.expect(alphaTableHeader.exists)
.ok();
// add column render for DataTable
// open columns Layer
await t
.click(Selector('button').withText('columns'))
.expect(Selector('h3').withExactText('columns').exists)
.ok();
// click name column
await t
.click(Selector('li').withText('name'))
.expect(labelButton('Add render').exists)
.ok();
// click +
await t
.click(labelButton('Add render'))
.expect(Selector('button').withText('back to DataTable').exists)
.ok();
// add Text
await add('Text');
// set text to name with prefix
await t
.typeText(
Selector('textarea').withAttribute('name', 'text'),
'senor {name}',
{ replace: true },
)
.expect(Selector('span').withExactText('senor {name}').exists)
.ok();
// go back to DataTable
await t
.click(Selector('button').withText('back to DataTable'))
.expect(Selector('th').withExactText('senor alpha').exists)
.ok();
// close design
await t.click(textButton(designName)).expect(textButton('close').exists).ok();
await t.click(textButton('close')).expect(newControl.exists).ok();
await t.expect(Selector('a').withText(designName).exists).ok();
// create another design
// NewDesign
await t.click(newControl).expect(nameInput('name').exists).ok();
// give it a name
await t
.typeText(nameInput('name'), 'Second Design')
.expect(valueInput('name', 'Second Design').exists)
.ok();
// include the first test design
await t
.click(nameInput('includes'))
.expect(textButton(designName).exists)
.ok();
await t
.click(textButton(designName))
.expect(valueInput('includes', designName).exists)
.ok();
await t.click(createDesignControl).expect(useScreenControl.exists).ok();
// NewScreen
// select included screen
const testScreenButton = Selector('button')
.withText('Test Screen')
.withText(designName);
await t
.click(Selector('label').withExactText('screen template'))
.expect(testScreenButton.exists)
.ok();
await t.click(testScreenButton).expect(testScreenButton.exists).ok();
await t.click(useScreenControl).expect(openLayerControl.exists).ok();
// delete design
await t
.click(textButton('Second Design'))
.expect(textButton('delete').exists)
.ok();
await t
.click(textButton('delete'))
.expect(textButton('Yes, delete').exists)
.ok();
await t.wait(500);
await t.click(textButton('Yes, delete')).expect(newControl.exists).ok();
await t.expect(Selector('a').withExactText('Second Design').exists).notOk();
await t.expect(Selector('a').withText(designName).exists).ok();
// duplicate design
// NewDesign
await t.click(newControl).expect(nameInput('name').exists).ok();
// give it a name
await t
.typeText(nameInput('name'), 'Third Design')
.expect(valueInput('name', 'Third Design').exists)
.ok();
// choose dplicate existing
await t
.click(Selector('label').withExactText('duplicate an existing design'))
.expect(nameInput('template').exists)
.ok();
await t
.click(nameInput('template'))
.expect(textButton(designName).exists)
.ok();
await t
.click(textButton(designName))
.expect(valueInput('template', designName).exists)
.ok();
await t
.click(titleButton('duplicate design'))
.expect(textButton('Test Screen').exists)
.ok();
await t.wait(1000);
});