|
3 | 3 | * SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | */ |
5 | 5 |
|
6 | | -import type { User } from '@nextcloud/cypress' |
7 | 6 | import { calculateViewportHeight, enableGridMode, getRowForFile } from './FilesUtils.ts' |
8 | 7 | import { beFullyInViewport, notBeFullyInViewport } from '../core-utils.ts' |
9 | 8 |
|
10 | | -describe('files: Scrolling to selected file in file list', { testIsolation: true }, () => { |
| 9 | +describe('files: Scrolling to selected file in file list', () => { |
11 | 10 | const fileIds = new Map<number, string>() |
12 | | - let user: User |
13 | 11 | let viewportHeight: number |
14 | 12 |
|
15 | 13 | before(() => { |
16 | | - cy.createRandomUser().then(($user) => { |
17 | | - user = $user |
18 | | - |
19 | | - cy.rm(user, '/welcome.txt') |
20 | | - for (let i = 1; i <= 10; i++) { |
21 | | - cy.uploadContent(user, new Blob([]), 'text/plain', `/${i}.txt`) |
22 | | - .then((response) => fileIds.set(i, Number.parseInt(response.headers['oc-fileid']).toString())) |
23 | | - } |
24 | | - |
25 | | - cy.login(user) |
26 | | - cy.viewport(1200, 800) |
27 | | - // Calculate height to ensure that those 10 elements can not be rendered in one list (only 6 will fit the screen) |
28 | | - calculateViewportHeight(6) |
29 | | - .then((height) => { |
30 | | - // Set viewport height to the calculated height |
31 | | - cy.log(`Setting viewport height to ${height}px`) |
32 | | - viewportHeight = height |
33 | | - }) |
34 | | - }) |
| 14 | + initFilesAndViewport(fileIds) |
| 15 | + .then((_viewportHeight) => { |
| 16 | + cy.log(`Saving viewport height to ${_viewportHeight}px`) |
| 17 | + viewportHeight = _viewportHeight |
| 18 | + }) |
35 | 19 | }) |
36 | 20 |
|
37 | 21 | beforeEach(() => { |
38 | 22 | cy.viewport(1200, viewportHeight) |
39 | | - cy.login(user) |
40 | 23 | }) |
41 | 24 |
|
42 | 25 | it('Can see first file in list', () => { |
@@ -127,45 +110,17 @@ describe('files: Scrolling to selected file in file list', { testIsolation: true |
127 | 110 | } |
128 | 111 | }) |
129 | 112 |
|
130 | | -describe('files: Scrolling to selected file in file list (GRID MODE)', { testIsolation: true }, () => { |
| 113 | +describe('files: Scrolling to selected file in file list (GRID MODE)', () => { |
131 | 114 | const fileIds = new Map<number, string>() |
132 | | - let user: User |
133 | 115 | let viewportHeight: number |
134 | 116 |
|
135 | 117 | before(() => { |
136 | | - cy.wrap(Cypress.automation('remote:debugger:protocol', { |
137 | | - command: 'Network.clearBrowserCache', |
138 | | - })) |
139 | | - |
140 | | - cy.createRandomUser().then(($user) => { |
141 | | - user = $user |
142 | | - |
143 | | - cy.rm(user, '/welcome.txt') |
144 | | - for (let i = 1; i <= 12; i++) { |
145 | | - cy.uploadContent(user, new Blob([]), 'text/plain', `/${i}.txt`) |
146 | | - .then((response) => fileIds.set(i, Number.parseInt(response.headers['oc-fileid']).toString())) |
147 | | - } |
148 | | - |
149 | | - // Set grid mode |
150 | | - cy.login(user) |
151 | | - cy.visit('/apps/files') |
152 | | - enableGridMode() |
153 | | - |
154 | | - // 768px width will limit the columns to 3 |
155 | | - cy.viewport(768, 800) |
156 | | - // Calculate height to ensure that those 12 elements can not be rendered in one list (only 3 will fit the screen) |
157 | | - calculateViewportHeight(3) |
158 | | - .then((height) => { |
159 | | - // Set viewport height to the calculated height |
160 | | - cy.log(`Setting viewport height to ${height}px`) |
161 | | - viewportHeight = height |
162 | | - }) |
163 | | - }) |
| 118 | + initFilesAndViewport(fileIds, true) |
| 119 | + .then((_viewportHeight) => { viewportHeight = _viewportHeight }) |
164 | 120 | }) |
165 | 121 |
|
166 | 122 | beforeEach(() => { |
167 | | - cy.viewport(768, viewportHeight ?? 800) |
168 | | - cy.login(user) |
| 123 | + cy.viewport(768, viewportHeight) |
169 | 124 | }) |
170 | 125 |
|
171 | 126 | // First row |
@@ -296,3 +251,29 @@ function beOverlappedByTableHeader($el: JQuery<HTMLElement>, expected = true) { |
296 | 251 | function notBeOverlappedByTableHeader($el: JQuery<HTMLElement>) { |
297 | 252 | return beOverlappedByTableHeader($el, false) |
298 | 253 | } |
| 254 | + |
| 255 | +function initFilesAndViewport(fileIds: Map<number, string>, gridMode = false): Cypress.Chainable<number> { |
| 256 | + return cy.createRandomUser().then((user) => { |
| 257 | + cy.rm(user, '/welcome.txt') |
| 258 | + for (let i = 1; i <= 10; i++) { |
| 259 | + cy.uploadContent(user, new Blob([]), 'text/plain', `/${i}.txt`) |
| 260 | + .then((response) => fileIds.set(i, Number.parseInt(response.headers['oc-fileid']).toString())) |
| 261 | + } |
| 262 | + |
| 263 | + cy.login(user) |
| 264 | + cy.viewport(1200, 800) |
| 265 | + |
| 266 | + // If grid mode is requested, enable it |
| 267 | + if (gridMode) { |
| 268 | + enableGridMode() |
| 269 | + } |
| 270 | + |
| 271 | + // Calculate height to ensure that those 10 elements can not be rendered in one list (only 6 will fit the screen) |
| 272 | + return calculateViewportHeight(6) |
| 273 | + .then((height) => { |
| 274 | + // Set viewport height to the calculated height |
| 275 | + cy.log(`Setting viewport height to ${height}px`) |
| 276 | + cy.wrap(height) |
| 277 | + }) |
| 278 | + }) |
| 279 | +} |
0 commit comments