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

require('cypress-file-upload');

var helper = require('../../common/helper');
var mobileHelper = require('../../common/mobile_helper');
var calcMobileHelper = require('./calc_mobile_helper');

describe('Chart tests.', function() {
	var testFileName = 'chart.ods';

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

		mobileHelper.enableEditingMobile();

		calcMobileHelper.selectFirstColumn();

		insertChart();
	});

	afterEach(function() {
		helper.afterAll(testFileName);
	});

	function insertChart() {
		mobileHelper.openInsertionWizard();

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

		cy.get('.leaflet-drag-transform-marker')
			.should('have.length', 8);

		cy.get('svg .OLE2')
			.should('exist');

		cy.get('svg .OLE2 g g path')
			.should('have.length', 40);
	}

	function stepIntoChartEditing() {
		cy.get('.leaflet-drag-transform-marker')
			.should('exist');

		// Double click onto the chart shape
		cy.get('svg g .leaflet-interactive')
			.then(function(items) {
				expect(items).to.have.length(1);
				var boundingRect = items[0].getBoundingClientRect();
				var XPos = boundingRect.left + 10;
				var YPos = (boundingRect.top + boundingRect.bottom) / 2;

				cy.get('body')
					.dblclick(XPos, YPos);
			});

		cy.get('.leaflet-drag-transform-marker')
			.should('not.exist');
	}

	function exitChartEditing() {
		// Select cell on bottom
		cy.get('.spreadsheet-header-rows')
			.then(function(header) {
				var rect = header[0].getBoundingClientRect();
				var posX = rect.right + 10;
				var posY = rect.bottom - 10;

				var moveY = 0.0;
				cy.waitUntil(function() {
					cy.get('body')
						.click(posX, posY + moveY);

					moveY -= 1.0;
					var regex = /A[0-9]+$/;
					return cy.get('input#addressInput')
						.should('have.prop', 'value')
						.then(function(value) {
							return regex.test(value);
						});
				});
			});
	}

	function selectChartOnCenter() {
		cy.get('#document-container')
			.then(function(items) {
				expect(items).to.have.length(1);
				var boundingRect = items[0].getBoundingClientRect();
				var XPos = (boundingRect.left + boundingRect.right) / 2;
				var YPos = (boundingRect.top + boundingRect.bottom) / 2;
				cy.get('body')
					.click(XPos, YPos);
			});

		cy.get('.leaflet-drag-transform-marker')
			.should('be.visible');
	}

	it.skip('Change chart type.', function() {
		stepIntoChartEditing();

		mobileHelper.openMobileWizard();

		helper.clickOnIdle('#ChartTypePanel');

		helper.clickOnIdle('#cmb_chartType');

		helper.clickOnIdle('.ui-combobox-text', 'Pie');

		mobileHelper.closeMobileWizard();

		// TODO: crashes here

		exitChartEditing();

		selectChartOnCenter();

		cy.get('svg .OLE2 g g path')
			.should('have.length', 4);
	});
});