summaryrefslogtreecommitdiff
path: root/cypress_test/integration_tests/mobile/impress/impress_focus_spec.js
blob: a33bede16a65ef85ebc42347dde6c50dbafa210a (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
/* global describe it cy beforeEach require afterEach expect */

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

describe('Impress focus tests', function() {
	beforeEach(function() {
		helper.beforeAllMobile('focus.odp', 'impress');
	});

	afterEach(function() {
		helper.afterAll('focus.odp');
	});

	it('Select text box, no editing', function() {

		helper.enableEditingMobile();

		impress.assertNotInTextEditMode();

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

		// Body has the focus -> can't type in the document
		cy.document().its('activeElement.tagName')
			.should('be.eq', 'BODY');

		// One tap on a text shape, on the whitespace area,
		// does not start editing.
		cy.get('#document-container')
			.then(function(items) {
				expect(items).have.length(1);

				// Click in the left-bottom corner where there is no text.
				let posX = items[0].getBoundingClientRect().left + items[0].getBoundingClientRect().width / 4;
				let posY = items[0].getBoundingClientRect().top + items[0].getBoundingClientRect().height / 2;
				cy.log('Got left-bottom quantile at (' + posX + ', ' + posY + ')');

				cy.get('#document-container')
					.click(posX, posY);
			});

		// No focus
		cy.document().its('activeElement.tagName')
			.should('be.eq', 'BODY');

		// Shape selection.
		cy.get('.leaflet-pane.leaflet-overlay-pane svg g')
			.should('exist');

		// But no editing.
		impress.assertNotInTextEditMode();
	});

	it('Double-click to edit', function() {

		helper.enableEditingMobile();

		impress.assertNotInTextEditMode();

		// Enter edit mode by double-clicking.
		cy.get('#document-container')
			.dblclick();

		impress.typeTextAndVerify('Hello Impress');

		// End editing.
		cy.get('#document-container')
			.type('{esc}').wait(500);

		impress.assertNotInTextEditMode();

		// Enter edit mode by double-clicking again.
		cy.get('#document-container')
			.dblclick();

		// Clear the text.
		helper.clearAllText();

		impress.typeTextAndVerify('Bazinga Impress');
	});

	it('Single-click to edit', function() {

		helper.enableEditingMobile();

		impress.assertNotInTextEditMode();

		cy.get('#document-container')
			.then(function(items) {
				expect(items).have.length(1);

				// Click in the top left corner where there is no text.
				let posX = items[0].getBoundingClientRect().width / 2;
				let posY = items[0].getBoundingClientRect().height / 2;
				cy.log('Got center coordinates at (' + posX + ', ' + posY + ')');

				// Start editing; click on the text.
				cy.get('#document-container')
					.click(posX, posY);

				impress.typeTextAndVerify('Hello Impress');

				// End editing.
				cy.get('#document-container')
					.type('{esc}').wait(500);

				impress.assertNotInTextEditMode();

				// Single-click to re-edit.
				cy.get('#document-container')
					.then(function(items) {
						expect(items).have.length(1);

						cy.get('#document-container')
							.click(posX, posY).wait(500);

						impress.assertInTextEditMode();

						// Clear the text.
						helper.clearAllText();

						impress.typeTextAndVerify('Bazinga Impress');

						// End editing.
						cy.get('#document-container')
							.type('{esc}').wait(500);

						impress.assertNotInTextEditMode();
					});
			});
	});
});