Skip to content

Commit b4d6364

Browse files
committed
fixup! fix(files): VirtualList rendering for scrolling calculations
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent fb62c4f commit b4d6364

File tree

2 files changed

+42
-55
lines changed

2 files changed

+42
-55
lines changed

cypress/e2e/files/FilesUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ export function enableGridMode() {
293293
export function calculateViewportHeight(rows: number): Cypress.Chainable<number> {
294294
cy.visit('/apps/files')
295295

296+
cy.get('[data-cy-files-list]')
297+
.should('be.visible')
298+
299+
cy.get('[data-cy-files-list-tbody] tr', { timeout: 5000 })
300+
.and('be.visible')
301+
296302
return cy.get('[data-cy-files-list]')
297303
.should('be.visible')
298304
.then((filesList) => {

cypress/e2e/files/scrolling.cy.ts

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,23 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { User } from '@nextcloud/cypress'
76
import { calculateViewportHeight, enableGridMode, getRowForFile } from './FilesUtils.ts'
87
import { beFullyInViewport, notBeFullyInViewport } from '../core-utils.ts'
98

10-
describe('files: Scrolling to selected file in file list', { testIsolation: true }, () => {
9+
describe('files: Scrolling to selected file in file list', () => {
1110
const fileIds = new Map<number, string>()
12-
let user: User
1311
let viewportHeight: number
1412

1513
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+
})
3519
})
3620

3721
beforeEach(() => {
3822
cy.viewport(1200, viewportHeight)
39-
cy.login(user)
4023
})
4124

4225
it('Can see first file in list', () => {
@@ -127,45 +110,17 @@ describe('files: Scrolling to selected file in file list', { testIsolation: true
127110
}
128111
})
129112

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)', () => {
131114
const fileIds = new Map<number, string>()
132-
let user: User
133115
let viewportHeight: number
134116

135117
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 })
164120
})
165121

166122
beforeEach(() => {
167-
cy.viewport(768, viewportHeight ?? 800)
168-
cy.login(user)
123+
cy.viewport(768, viewportHeight)
169124
})
170125

171126
// First row
@@ -296,3 +251,29 @@ function beOverlappedByTableHeader($el: JQuery<HTMLElement>, expected = true) {
296251
function notBeOverlappedByTableHeader($el: JQuery<HTMLElement>) {
297252
return beOverlappedByTableHeader($el, false)
298253
}
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

Comments
 (0)