summaryrefslogtreecommitdiffstats
path: root/cypress_test/integration_tests/common/mobile_helper.js
blob: 0b03959bd982a9952b266cd35b8111a5937b16ff (plain)
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/* global cy expect require Cypress */

var helper = require('./helper');

// Enable editing if we are in read-only mode.
function enableEditingMobile() {

	//https://stackoverflow.com/a/63519375/1592055
	const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/;
	Cypress.on('uncaught:exception', (err) => {
		/* returning false here prevents Cypress from failing the test */
		if (resizeObserverLoopErrRe.test(err.message)) {
			return false;
		}
	});

	cy.log('Enabling editing mode - start.');

	cy.get('#mobile-edit-button')
		.then(function(button) {
			if (button.css('display') !== 'none') {

				cy.get('#toolbar-mobile-back')
					.should('not.have.class', 'editmode-on');

				cy.get('#toolbar-mobile-back')
					.should('have.class', 'editmode-off');

				cy.get('#mobile-edit-button')
					.click();
			}
		});


	cy.get('#toolbar-mobile-back')
		.should('have.class', 'editmode-on');

	cy.get('#toolbar-mobile-back')
		.should('not.have.class', 'editmode-off');

	// Wait until all UI update is finished.
	cy.get('#toolbar-down')
		.should('be.visible');

	helper.doIfInCalc(function() {
		cy.get('#formulabar')
			.should('be.visible');
	});

	// In writer, we should have the blinking cursor visible
	// after stepping into editing mode.
	helper.doIfInWriter(function() {
		cy.get('.blinking-cursor')
			.should('be.visible');
	});

	cy.log('Enabling editing mode - end.');
}

function longPressOnDocument(posX, posY) {
	cy.log('Emulating a long press - start.');
	cy.log('Param - posX: ' + posX);
	cy.log('Param - posY: ' + posY);

	cy.get('.leaflet-pane.leaflet-map-pane')
		.then(function(items) {
			expect(items).have.length(1);

			var eventOptions = {
				force: true,
				button: 0,
				pointerType: 'mouse',
				x: posX - items[0].getBoundingClientRect().left,
				y: posY - items[0].getBoundingClientRect().top
			};

			cy.get('.leaflet-pane.leaflet-map-pane')
				.trigger('pointerdown', eventOptions)
				.trigger('pointermove', eventOptions);

			// This value is set in Map.TouchGesture.js.
			cy.wait(500);

			cy.get('.leaflet-pane.leaflet-map-pane')
				.trigger('pointerup', eventOptions);
		});

	cy.log('Emulating a long press - end.');
}

function openHamburgerMenu() {
	cy.log('Opening hamburger menu - start.');

	cy.get('#toolbar-hamburger')
		.should('not.have.class', 'menuwizard-opened');

	cy.get('#toolbar-hamburger .main-menu-btn-icon')
		.click({force: true});

	cy.get('#toolbar-hamburger')
		.should('have.class', 'menuwizard-opened');

	cy.get('#mobile-wizard-content')
		.should('not.be.empty');

	cy.log('Opening hamburger menu - end.');
}

function closeHamburgerMenu() {
	cy.log('Closing hamburger menu - start.');

	cy.get('#toolbar-hamburger')
		.should('have.class', 'menuwizard-opened');

	cy.get('#toolbar-hamburger .main-menu-btn-icon')
		.click({force: true});

	cy.get('#toolbar-hamburger')
		.should('not.have.class', 'menuwizard-opened');

	cy.get('#mobile-wizard-content')
		.should('be.empty');

	cy.log('Closing hamburger menu - end.');
}

function openMobileWizard() {
	cy.log('Opening mobile wizard - start.');

	helper.waitUntilIdle('#tb_actionbar_item_mobile_wizard');
	// Open mobile wizard
	cy.get('#tb_actionbar_item_mobile_wizard')
		.should('not.have.class', 'disabled')
		.click();

	cy.wait(1000);

	// Mobile wizard is opened and it has content
	cy.get('#mobile-wizard-content')
		.should('not.be.empty');
	cy.get('#tb_actionbar_item_mobile_wizard table')
		.should('have.class', 'checked');

	cy.log('Opening mobile wizard - end.');
}

function closeMobileWizard() {
	cy.log('Closing mobile wizard - start.');

	cy.get('#tb_actionbar_item_mobile_wizard table')
		.should('have.class', 'checked');

	cy.get('#tb_actionbar_item_mobile_wizard')
		.click();

	cy.get('#mobile-wizard')
		.should('not.be.visible');
	cy.get('#tb_actionbar_item_mobile_wizard table')
		.should('not.have.class', 'checked');

	cy.log('Closing mobile wizard - end.');
}

function executeCopyFromContextMenu(XPos, YPos) {
	cy.log('Executing copy from context menu - start.');
	cy.log('Param - XPos: ' + XPos);
	cy.log('Param - YPos: ' + YPos);

	longPressOnDocument(XPos, YPos);

	// Execute copy
	cy.contains('.menu-entry-with-icon', 'Copy')
		.click();

	// Close warning about clipboard operations
	cy.get('.vex-dialog-buttons .button-primary')
		.click();

	// Wait until it's closed
	cy.get('.vex-overlay')
		.should('not.exist');

	cy.log('Executing copy from context menu - end.');
}

function openInsertionWizard() {
	cy.log('Opening insertion wizard - start.');

	cy.get('#tb_actionbar_item_insertion_mobile_wizard')
		.should('not.have.class', 'disabled')
		.click();

	cy.get('#mobile-wizard-content')
		.should('not.be.empty');

	cy.get('#tb_actionbar_item_insertion_mobile_wizard table')
		.should('have.class', 'checked');

	cy.log('Opening insertion wizard - end.');
}

function openCommentWizard() {
	cy.log('Opening Comment wizard - start.');

	cy.get('#tb_actionbar_item_comment_wizard')
		.should('not.have.class', 'disabled')
		.click();

	cy.get('#tb_actionbar_item_comment_wizard table')
		.should('have.class', 'checked');

	cy.log('Opening Comment wizard - end.');
}

function closeInsertionWizard() {
	cy.log('Closing insertion wizard - start.');

	cy.get('#tb_actionbar_item_insertion_mobile_wizard table')
		.should('have.class', 'checked');

	cy.get('#tb_actionbar_item_insertion_mobile_wizard')
		.click();

	cy.get('#mobile-wizard')
		.should('not.be.visible');

	cy.get('#tb_actionbar_item_insertion_mobile_wizard table')
		.should('not.have.class', 'checked');

	cy.log('Closing insertion wizard - end.');
}

function selectFromColorPalette(paletteNum, groupNum, paletteAfterChangeNum, colorNum) {
	cy.log('Selecting a color from the color palette - start.');

	cy.get('#color-picker-' + paletteNum.toString() + '-basic-color-' + groupNum.toString())
		.click();

	cy.wait(1000);

	if (paletteAfterChangeNum !== undefined && colorNum !== undefined) {
		cy.get('#color-picker-' + paletteAfterChangeNum.toString() + '-tint-' + colorNum.toString())
			.click();
	}

	cy.wait(1000);

	cy.get('#mobile-wizard-back')
		.click();

	cy.log('Selecting a color from the color palette - end.');
}

function openTextPropertiesPanel() {
	openMobileWizard();

	helper.clickOnIdle('#TextPropertyPanel');

	cy.get('#Bold')
		.should('be.visible');
}

function selectHamburgerMenuItem(menuItems) {
	cy.log('Selecting hamburger menu item - start.');
	cy.log('Param - menuItems: ' + menuItems);

	openHamburgerMenu();

	for (var i = 0; i < menuItems.length; i++) {
		cy.contains('.menu-entry-with-icon', menuItems[i])
			.click();

		if (Cypress.env('INTEGRATION') !== 'nextcloud') {
			if (Cypress.$('.menu-entry-with-icon').length) {
				cy.get('.menu-entry-with-icon')
					.should('not.have.text', menuItems[i]);
			}
		}
	}
	cy.log('Selecting hamburger menu item - end.');
}

function selectAnnotationMenuItem(menuItem) {
	cy.log('Selecting annotation menu item - start.');

	cy.get('#mobile-wizard .wizard-comment-box .cool-annotation-menu')
		.click({force: true});

	cy.get('.context-menu-list')
		.should('exist');

	cy.contains('.context-menu-item', menuItem)
		.click();

	cy.log('Selecting annotation menu item - end.');
}

function selectListBoxItem(listboxSelector, item) {
	cy.log('Selecting an item from listbox - start.');

	helper.clickOnIdle(listboxSelector);

	helper.clickOnIdle('.mobile-wizard.ui-combobox-text', item);

	// Combobox entry contains the selected item
	cy.get(listboxSelector + ' .ui-header-right .entry-value')
		.should('have.text', item);

	cy.log('Selecting an item from listbox - end.');
}

function selectListBoxItem2(listboxSelector, item) {
	cy.log('Selecting an item from listbox 2 - start.');

	helper.clickOnIdle(listboxSelector);

	var endPos = listboxSelector.indexOf(' ');
	if (endPos < 0)
		endPos = listboxSelector.length;
	var parentId = listboxSelector.substring(0, endPos);

	helper.clickOnIdle(parentId + ' .ui-combobox-text', item);

	cy.wait(1000);

	cy.get(listboxSelector + ' .ui-header-left')
		.should('have.text', item);

	cy.log('Selecting an item from listbox 2 - end.');
}
function insertComment() {
	openInsertionWizard();

	cy.contains('.menu-entry-with-icon', 'Comment').click();

	cy.get('.cool-annotation-table').should('exist');

	cy.get('#new-mobile-comment-input-area').type('some text');

	cy.get('.vex-dialog-buttons .button-primary').click();

	cy.get('#comment-container-1').should('exist')
		.wait(300);

	cy.get('#annotation-content-area-1').should('have.text', 'some text');
}

function insertImage() {
	openInsertionWizard();

	// We can't use the menu item directly, because it would open file picker.
	cy.contains('.menu-entry-with-icon', 'Local Image...')
		.should('be.visible');

	cy.get('#insertgraphic[type=file]')
		.attachFile('/mobile/writer/image_to_insert.png');

	cy.get('.leaflet-pane.leaflet-overlay-pane svg g')
		.should('exist');
}

function deleteImage() {
	insertImage();
	var eventOptions = {
		force: true,
		button: 0,
		pointerType: 'mouse'
	};

	cy.get('.leaflet-control-buttons-disabled > .leaflet-interactive')
		.trigger('pointerdown', eventOptions)
		.wait(1000)
		.trigger('pointerup', eventOptions);

	cy.contains('.menu-entry-with-icon', 'Delete')
		.should('be.visible').click();

	cy.get('.leaflet-pane.leaflet-overlay-pane svg g')
		.should('not.exist');
}

module.exports.enableEditingMobile = enableEditingMobile;
module.exports.longPressOnDocument = longPressOnDocument;
module.exports.openHamburgerMenu = openHamburgerMenu;
module.exports.selectHamburgerMenuItem = selectHamburgerMenuItem;
module.exports.selectAnnotationMenuItem = selectAnnotationMenuItem;
module.exports.closeHamburgerMenu = closeHamburgerMenu;
module.exports.openMobileWizard = openMobileWizard;
module.exports.closeMobileWizard = closeMobileWizard;
module.exports.executeCopyFromContextMenu = executeCopyFromContextMenu;
module.exports.openInsertionWizard = openInsertionWizard;
module.exports.closeInsertionWizard = closeInsertionWizard;
module.exports.selectFromColorPalette = selectFromColorPalette;
module.exports.openTextPropertiesPanel = openTextPropertiesPanel;
module.exports.selectListBoxItem = selectListBoxItem;
module.exports.selectListBoxItem2 = selectListBoxItem2;
module.exports.openCommentWizard = openCommentWizard;
module.exports.insertImage = insertImage;
module.exports.deleteImage = deleteImage;
module.exports.insertComment = insertComment;