summaryrefslogtreecommitdiffstats
path: root/cypress_test/integration_tests/mobile/writer/searchbar_spec.js
blob: 90b35cf286c77471460e8f0c7bc840db79d9483a (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
/* global describe it cy beforeEach require afterEach*/

var helper = require('../../common/helper');
var searchHelper = require('../../common/search_helper');
var mobileHelper = require('../../common/mobile_helper');
var writerHelper = require('../../common/writer_helper');

describe('Searching via search bar.', function() {
	var origTestFileName = 'search_bar.odt';
	var testFileName;

	beforeEach(function() {
		testFileName = helper.beforeAll(origTestFileName, 'writer');

		mobileHelper.enableEditingMobile();

		searchHelper.showSearchBar();
	});

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

	it('Search existing word.', function() {
		searchHelper.tpyeIntoSearchField('a');

		// Part of the text should be selected
		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');
	});

	it('Search not existing word.', function() {
		writerHelper.selectAllTextOfDoc();

		searchHelper.tpyeIntoSearchField('q');

		helper.textSelectionShouldNotExist();
	});

	it('Search next / prev instance.', function() {
		searchHelper.tpyeIntoSearchField('a');

		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');

		cy.get('#copy-paste-container p b')
			.should('not.exist');

		// Search next instance
		searchHelper.searchNext();

		cy.get('#copy-paste-container p b')
			.should('exist');

		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');

		// Search prev instance
		searchHelper.searchPrev();

		cy.get('#copy-paste-container p b')
			.should('not.exist');

		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');
	});

	it('Search at the document end.', function() {
		searchHelper.tpyeIntoSearchField('a');

		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');

		cy.get('#copy-paste-container p b')
			.should('not.exist');

		// Search next instance
		searchHelper.searchNext();

		cy.get('#copy-paste-container p b')
			.should('exist');

		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');

		// Search next instance, which is in the beginning of the document.
		searchHelper.searchNext();

		cy.get('#copy-paste-container p b')
			.should('not.exist');

		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');
	});

	it('Cancel search.', function() {
		searchHelper.tpyeIntoSearchField('a');

		// Part of the text should be selected
		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');

		// Cancel search -> selection removed
		searchHelper.cancelSearch();

		helper.textSelectionShouldNotExist();

		cy.get('input#search-input')
			.should('be.visible');
	});

	it('Close search.', function() {
		searchHelper.tpyeIntoSearchField('a');

		// Part of the text should be selected
		helper.textSelectionShouldExist();

		cy.get('#copy-paste-container p')
			.should('have.text', '\na');

		// Close search -> search bar is closed
		searchHelper.closeSearchBar();
	});
});