|
| 1 | +/// <reference path="../../support/commands.d.ts" /> |
| 2 | + |
1 | 3 | describe('Start', () => { |
2 | 4 | beforeEach(() => { |
3 | 5 | cy.visit(Cypress.config().baseUrl!); |
4 | 6 | }); |
5 | 7 |
|
6 | | - it('Open Modal on Search Button click', () => { |
7 | | - cy.get('.DocSearch-Button').click(); |
8 | | - cy.get('.DocSearch-Modal').should('be.visible'); |
9 | | - cy.get('.DocSearch-Input').should('be.focus'); |
10 | | - cy.percySnapshot('modal-opened'); |
| 8 | + it('Open modal on search button click', () => { |
| 9 | + cy.openModal(); |
| 10 | + cy.modalIsVisibleAndFocused(); |
11 | 11 | }); |
12 | 12 |
|
13 | | - it('Open Modal with key shortcut on Windows/Linux', () => { |
| 13 | + it('Open modal with key shortcut on Windows/Linux', () => { |
14 | 14 | cy.get('body').type('{ctrl}k'); |
15 | | - cy.get('.DocSearch-Modal').should('be.visible'); |
16 | | - cy.get('.DocSearch-Input').should('be.focus'); |
| 15 | + cy.modalIsVisibleAndFocused(); |
17 | 16 | }); |
18 | 17 |
|
19 | | - it('Open Modal with key shortcut on macOS', () => { |
| 18 | + it('Open modal with key shortcut on macOS', () => { |
20 | 19 | cy.get('body').type('{meta}k'); |
21 | | - cy.get('.DocSearch-Modal').should('be.visible'); |
22 | | - cy.get('.DocSearch-Input').should('be.focus'); |
| 20 | + cy.modalIsVisibleAndFocused(); |
23 | 21 | }); |
24 | 22 |
|
25 | | - it('Open Modal with forward slash key shortcut', () => { |
| 23 | + it('Open modal with forward slash key shortcut', () => { |
26 | 24 | cy.get('body').type('/'); |
27 | | - cy.get('.DocSearch-Modal').should('be.visible'); |
28 | | - cy.get('.DocSearch-Input').should('be.focus'); |
| 25 | + cy.modalIsVisibleAndFocused(); |
29 | 26 | }); |
30 | 27 | }); |
31 | 28 |
|
32 | 29 | describe('End', () => { |
33 | 30 | beforeEach(() => { |
34 | 31 | cy.visit(Cypress.config().baseUrl!); |
35 | | - cy.get('.DocSearch-Button').click(); |
| 32 | + cy.openModal(); |
36 | 33 | }); |
37 | 34 |
|
38 | | - it('Close Modal with Esc key', () => { |
39 | | - cy.get('body').type('{esc}'); |
40 | | - cy.get('.DocSearch-Modal').should('not.be.visible'); |
41 | | - cy.percySnapshot('modal-closed'); |
| 35 | + it('Close modal with Esc key', () => { |
| 36 | + cy.closeModal(); |
| 37 | + cy.modalIsNotVisible(); |
42 | 38 | }); |
43 | 39 |
|
44 | | - it('Close Modal by clicking outside its container', () => { |
| 40 | + it('Close modal by clicking outside its container', () => { |
45 | 41 | cy.get('.DocSearch-Container').click(); |
46 | | - cy.get('.DocSearch-Modal').should('not.be.visible'); |
| 42 | + cy.modalIsNotVisible(); |
47 | 43 | }); |
48 | 44 |
|
49 | | - it('Close Modal with key shortcut on Windows/Linux', () => { |
| 45 | + it('Close modal with key shortcut on Windows/Linux', () => { |
50 | 46 | cy.get('body').type('{ctrl}k'); |
51 | | - cy.get('.DocSearch-Modal').should('not.be.visible'); |
| 47 | + cy.modalIsNotVisible(); |
52 | 48 | }); |
53 | 49 |
|
54 | | - it('Close Modal with key shortcut on macOS', () => { |
| 50 | + it('Close modal with key shortcut on macOS', () => { |
55 | 51 | cy.get('body').type('{meta}k'); |
56 | | - cy.get('.DocSearch-Modal').should('not.be.visible'); |
| 52 | + cy.modalIsNotVisible(); |
57 | 53 | }); |
58 | 54 | }); |
59 | 55 |
|
60 | 56 | describe('Search', () => { |
61 | 57 | beforeEach(() => { |
62 | 58 | cy.visit(Cypress.config().baseUrl!); |
63 | | - cy.get('.DocSearch-Button').click(); |
| 59 | + cy.openModal(); |
64 | 60 | }); |
65 | 61 |
|
66 | | - it('Results are displayed after a Query', () => { |
67 | | - cy.get('.DocSearch-Input').type('get'); |
| 62 | + it('Results are displayed after a query', () => { |
| 63 | + cy.typeQueryMatching(); |
68 | 64 | cy.get('.DocSearch-Hits').should('be.visible'); |
69 | | - cy.percySnapshot('search-results'); |
70 | 65 | }); |
71 | 66 |
|
72 | 67 | it('Query can be cleared', () => { |
73 | | - cy.get('.DocSearch-Input').type('get'); |
| 68 | + cy.typeQueryMatching(); |
74 | 69 | cy.get('.DocSearch-Reset').click(); |
75 | | - cy.get('.DocSearch-Hits').should('not.be.visible'); |
| 70 | + cy.get('.DocSearch-Hits').should('not.exist'); |
76 | 71 | cy.contains('No recent searches').should('be.visible'); |
77 | 72 | }); |
78 | 73 |
|
79 | | - it('Keyboard Navigation leads to result', () => { |
80 | | - cy.get('.DocSearch-Input').type('get'); |
| 74 | + it('Keyboard navigation leads to result', () => { |
| 75 | + const currentURL = cy.url(); |
| 76 | + |
| 77 | + cy.typeQueryMatching(); |
81 | 78 | cy.get('.DocSearch-Input').type('{downArrow}{downArrow}{upArrow}'); |
82 | 79 | cy.get('.DocSearch-Input').type('{enter}'); |
83 | | - cy.url().should('include', '/docs/getalgoliahits'); |
84 | | - cy.percySnapshot('result-page-anchor'); |
| 80 | + cy.on('url:changed', (newUrl) => { |
| 81 | + expect(newUrl).not.equal(currentURL); |
| 82 | + }); |
85 | 83 | }); |
86 | 84 |
|
87 | | - it('Pointer Navigation leads to result', () => { |
88 | | - cy.get('.DocSearch-Input').type('get'); |
| 85 | + it('Pointer navigation leads to result', () => { |
| 86 | + const currentURL = cy.url(); |
| 87 | + |
| 88 | + cy.typeQueryMatching(); |
89 | 89 | cy.get('.DocSearch-Hits #docsearch-item-1 > a').click({ force: true }); |
90 | | - cy.url().should('include', '/docs/getalgoliahits'); |
| 90 | + cy.on('url:changed', (newUrl) => { |
| 91 | + expect(newUrl).not.equal(currentURL); |
| 92 | + }); |
91 | 93 | }); |
92 | 94 |
|
93 | | - it("No Results are displayed if query doesn't match", () => { |
94 | | - cy.get('.DocSearch-Input').type('zzzzz'); |
95 | | - cy.contains('No results for "zzzzz"').should('be.visible'); |
96 | | - cy.percySnapshot('no-results'); |
| 95 | + it("No results are displayed if query doesn't match", () => { |
| 96 | + cy.typeQueryNotMatching(); |
| 97 | + cy.contains('No results for').should('be.visible'); |
97 | 98 | }); |
98 | 99 | }); |
99 | 100 |
|
100 | 101 | describe('Recent and Favorites', () => { |
101 | 102 | beforeEach(() => { |
102 | 103 | cy.visit(Cypress.config().baseUrl!); |
103 | | - cy.get('.DocSearch-Button').click(); |
104 | | - cy.get('.DocSearch-Input').type('get'); |
105 | | - cy.get('.DocSearch-Hits #docsearch-item-0 > a').click({ force: true }); |
| 104 | + cy.openModal(); |
| 105 | + cy.typeQueryMatching(); |
| 106 | + cy.get('#docsearch-item-0 > a').click({ force: true }).wait(3000); |
| 107 | + cy.openModal(); |
| 108 | + cy.contains('Recent').should('be.visible'); |
106 | 109 | }); |
107 | 110 |
|
108 | 111 | it('Recent search is displayed after visiting a result', () => { |
109 | | - cy.get('.DocSearch-Button').click(); |
110 | | - cy.contains('Recent').should('be.visible'); |
111 | 112 | cy.get('#docsearch-item-0').should('be.visible'); |
112 | | - cy.percySnapshot('recent-search'); |
113 | 113 | }); |
114 | 114 |
|
115 | 115 | it('Recent search can be deleted', () => { |
116 | | - cy.get('.DocSearch-Button').click(); |
117 | 116 | cy.get('#docsearch-item-0') |
118 | 117 | .find('[title="Remove this search from history"]') |
119 | 118 | .trigger('click'); |
120 | 119 | cy.contains('No recent searches').should('be.visible'); |
121 | 120 | }); |
122 | 121 |
|
123 | 122 | it('Recent search can be favorited', () => { |
124 | | - cy.get('.DocSearch-Button').click(); |
125 | 123 | cy.get('#docsearch-item-0') |
126 | 124 | .find('[title="Save this search"]') |
127 | 125 | .trigger('click'); |
128 | | - cy.contains('Favorites').should('be.visible'); |
| 126 | + cy.contains('Favorite').should('be.visible'); |
129 | 127 | cy.get('#docsearch-item-0').should('be.visible'); |
130 | | - cy.percySnapshot('favorite'); |
131 | 128 | }); |
132 | 129 |
|
133 | 130 | it('Favorite can be deleted', () => { |
134 | | - cy.get('.DocSearch-Button').click(); |
135 | 131 | cy.get('#docsearch-item-0') |
136 | 132 | .find('[title="Save this search"]') |
137 | 133 | .trigger('click'); |
138 | | - cy.wait(2000); |
| 134 | + cy.contains('Favorite').should('be.visible'); |
139 | 135 | cy.get('#docsearch-item-0') |
140 | 136 | .find('[title="Remove this search from favorites"]') |
141 | 137 | .trigger('click'); |
|
0 commit comments