summaryrefslogtreecommitdiffstats
path: root/cypress_test/integration_tests/mobile/calc/formulabar_spec.js
blob: 4ade2f85493bfba8193d8606999e6884e073ec15 (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
/* global describe it cy beforeEach require afterEach expect */

var helper = require('../../common/helper');
var calcHelper = require('../../common/calc_helper');
var mobileHelper = require('../../common/mobile_helper');

require('cypress-wait-until');

describe('Change alignment settings.', function() {
	var testFileName = 'formulabar.ods';

	beforeEach(function() {
		helper.beforeAll(testFileName, 'calc');

		mobileHelper.enableEditingMobile();
	});

	afterEach(function() {
		helper.afterAll(testFileName, this.currentTest.state);
	});

	it('Select a cell by address', function() {
		// Select first cell by clicking on it
		calcHelper.clickOnFirstCell();

		// Select a different cell using address input.
		cy.get('input#addressInput')
			.clear()
			.type('B2{enter}');

		cy.get('input#addressInput')
			.should('have.prop', 'value', 'B2');

		cy.get('.spreadsheet-cell-resize-marker[style=\'visibility: visible; transform: translate3d(-8px, -8px, 0px); z-index: -8;\']')
			.should('not.exist');

		cy.get('input#addressInput')
			.clear()
			.type('A1{enter}');

		cy.get('input#addressInput')
			.should('have.prop', 'value', 'A1');

		cy.get('.spreadsheet-cell-resize-marker[style=\'visibility: visible; transform: translate3d(-8px, -8px, 0px); z-index: -8;\']')
			.should('exist');
	});

	it('Select a cell range by address', function() {
		// Select first cell by clicking on it.
		calcHelper.clickOnFirstCell();

		// Select a cell range using address input.
		cy.get('input#addressInput')
			.clear()
			.type('B2:B3{enter}');

		cy.get('input#addressInput')
			.should('have.prop', 'value', 'B2:B3');

		cy.get('.spreadsheet-cell-resize-marker[style=\'visibility: visible; transform: translate3d(-8px, -8px, 0px); z-index: -8;\']')
			.should('not.exist');

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

		// Select first cell by clicking on it.
		calcHelper.clickOnFirstCell();

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

		// Select a cell range again using address input.
		cy.get('input#addressInput')
			.clear()
			.type('B2:B3{enter}');

		cy.get('input#addressInput')
			.should('have.prop', 'value', 'B2:B3');

		cy.get('.spreadsheet-cell-resize-marker[style=\'visibility: visible; transform: translate3d(-8px, -8px, 0px); z-index: -8;\']')
			.should('not.exist');

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

	it('Check input field content', function() {
		// First cell has some long content
		calcHelper.clickOnFirstCell();

		calcHelper.typeIntoFormulabar('{end}');

		cy.get('#calc-inputbar .lokdialog-cursor')
			.should(function(cursor) {
				expect(cursor.offset().left).to.be.equal(294);
			});

		// A2 cell is empty
		cy.get('input#addressInput')
			.clear()
			.type('A2{enter}');

		calcHelper.typeIntoFormulabar('{end}');

		cy.get('#calc-inputbar .lokdialog-cursor')
			.should(function(cursor) {
				expect(cursor.offset().left).to.be.equal(103);
			});

		// Change first cell content
		calcHelper.dblClickOnFirstCell();
		
		helper.typeIntoDocument('xxx');

		calcHelper.typeIntoFormulabar('{end}');

		cy.get('#calc-inputbar .lokdialog-cursor')
			.should(function(cursor) {
				expect(cursor.offset().left).to.be.equal(318);
			});
	});

	it('Edit cell via formula bar', function() {
		// First cell has some long content
		calcHelper.clickOnFirstCell();

		calcHelper.selectAllMobile();

		cy.get('#copy-paste-container table td:nth-of-type(1)')
			.should('have.text', 'long line long line long line');

		// Change first cell content via formula bar
		calcHelper.clickOnFirstCell();

		calcHelper.typeIntoFormulabar('{end}xxxxxxx{enter}');

		calcHelper.selectAllMobile();

		cy.get('#copy-paste-container table td:nth-of-type(1)')
			.should('have.text', 'long line long line long linexxxxxxx');
	});

	it('Accept formula bar change', function() {
		// First cell has some long content
		calcHelper.clickOnFirstCell();

		calcHelper.selectAllMobile();

		cy.get('#copy-paste-container table td:nth-of-type(1)')
			.should('have.text', 'long line long line long line');

		// Change first cell content via formula bar
		calcHelper.clickOnFirstCell();

		calcHelper.typeIntoFormulabar('{end}{backspace}{backspace}{backspace}');

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

		calcHelper.selectAllMobile();

		cy.get('#copy-paste-container table td:nth-of-type(1)')
			.should('have.text', 'long line long line long l');
	});

	it('Reject formula bar change', function() {
		// First cell has some long content
		calcHelper.clickOnFirstCell();

		calcHelper.selectAllMobile();

		cy.get('#copy-paste-container table td:nth-of-type(1)')
			.should('have.text', 'long line long line long line');

		// Change first cell content via formula bar
		calcHelper.clickOnFirstCell();

		calcHelper.typeIntoFormulabar('{end}{backspace}{backspace}{backspace}');

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

		cy.wait(2000);

		calcHelper.selectAllMobile();

		cy.get('#copy-paste-container table td:nth-of-type(1)')
			.should('have.text', 'long line long line long line');
	});

	it('Switch oneline-multiline mode of input bar', function() {
		helper.initAliasToNegative('inputOriginalHeight');

		cy.get('#calc-inputbar')
			.invoke('height')
			.as('inputOriginalHeight');

		cy.get('@inputOriginalHeight')
			.should('be.greaterThan', 0);

		// Switch to multiline mode.
		var arrowPos = [250, 10];
		cy.get('#calc-inputbar')
			.click(arrowPos[0], arrowPos[1]);

		cy.get('@inputOriginalHeight')
			.then(function(inputOriginalHeight) {
				cy.get('#calc-inputbar')
					.should(function(inputbar) {
						expect(inputbar.height()).to.be.greaterThan(inputOriginalHeight);
					});
			});

		cy.get('#calc-inputbar')
			.should(function(inputbar) {
				expect(inputbar.height()).to.be.equal(111);
			});

		// Switch back to one-line mode.
		cy.get('#calc-inputbar')
			.click(arrowPos[0], arrowPos[1]);

		cy.get('@inputOriginalHeight')
			.then(function(inputOriginalHeight) {
				cy.get('#calc-inputbar')
					.should(function(inputbar) {
						expect(inputbar.height()).to.be.equal(inputOriginalHeight);
					});
			});
	});

	it('Check formula help', function() {
		cy.get('#tb_formulabar_item_functiondialog')
			.click();

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

		cy.contains('.ui-header.level-0.mobile-wizard', 'Logical')
			.click();

		cy.contains('.func-entry', 'AND')
			.find('.func-info-icon')
			.click();

		cy.get('#mobile-wizard-title')
			.should('be.visible')
			.should('have.text', 'AND');

		cy.get('.ui-content.level-1.mobile-wizard[title=\'AND\'] .func-info-sig')
			.should('be.visible')
			.should('contain.text', 'AND( Logical value 1, Logical value 2, ...');

		cy.get('.ui-content.level-1.mobile-wizard[title=\'AND\'] .func-info-desc')
			.should('be.visible')
			.should('have.text', 'Returns TRUE if all arguments are TRUE.');
	});

	it('Add formula to cell', function() {
		calcHelper.clickOnFirstCell();

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

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

		// Select average
		cy.contains('.ui-header.level-0.mobile-wizard', 'Statistical')
			.click();

		cy.contains('.ui-content.level-0.mobile-wizard[title=\'Statistical\'] .func-entry', 'AVERAGE')
			.find('.ui-header-left')
			.click();

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

		cy.get('#calc-inputbar .lokdialog-cursor')
			.should('be.visible');

		// Add a range
		calcHelper.typeIntoFormulabar('B2:B4{enter}');

		// Close mobile wizard with formulas.
		cy.get('#mobile-wizard-back')
			.click();

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

		calcHelper.selectAllMobile();

		cy.get('#copy-paste-container table td:nth-of-type(1)')
			.should('have.text', '5');
	});
});