fix(cypress): files_versions flakyness

Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
pull/43762/head
skjnldsv 3 months ago
parent 16b818bd1e
commit 5b757c33d8

@ -20,10 +20,10 @@
* *
*/ */
import path from "path" import type { User } from '@nextcloud/cypress'
import type { User } from "@nextcloud/cypress" import path from 'path'
export function uploadThreeVersions(user: User, fileName: string) { export const uploadThreeVersions = (user: User, fileName: string) => {
// A new version will not be created if the changes occur // A new version will not be created if the changes occur
// within less than one second of each other. // within less than one second of each other.
// eslint-disable-next-line cypress/no-unnecessary-waiting // eslint-disable-next-line cypress/no-unnecessary-waiting
@ -35,23 +35,22 @@ export function uploadThreeVersions(user: User, fileName: string) {
cy.login(user) cy.login(user)
} }
export function openVersionsPanel(fileName: string) { export const openVersionsPanel = (fileName: string) =>{
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"]`).within(() => { // Detect the versions list fetch
cy.get('[data-cy-files-list-row-actions] .action-item__menutoggle') cy.intercept('PROPFIND', '**/dav/versions/*/versions/**').as('getVersions')
.click()
})
cy.get('.action-item__popper')
.get('[data-cy-files-list-row-action="details"]')
.click()
cy.get('#app-sidebar-vue') // Open the versions tab
.get('[aria-controls="tab-version_vue"]') cy.window().then(win => {
.click() win.OCA.Files.Sidebar.setActiveTab('version_vue')
win.OCA.Files.Sidebar.open(`/${fileName}`)
})
// Wait for the versions list to be fetched
cy.wait('@getVersions')
cy.get('#tab-version_vue').should('be.visible', { timeout: 10000 })
} }
export function openVersionMenu(index: number) { export const openVersionMenu = (index: number) => {
cy.get('#tab-version_vue').within(() => { cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]') cy.get('[data-files-versions-version]')
.eq(index).within(() => { .eq(index).within(() => {
@ -61,19 +60,19 @@ export function openVersionMenu(index: number) {
}) })
} }
export function clickPopperAction(actionName: string) { export const clickPopperAction = (actionName: string) => {
cy.get('.v-popper__popper').filter(':visible') cy.get('.v-popper__popper').filter(':visible')
.contains(actionName) .contains(actionName)
.click() .click()
} }
export function nameVersion(index: number, name: string) { export const nameVersion = (index: number, name: string) => {
openVersionMenu(index) openVersionMenu(index)
clickPopperAction('Name this version') clickPopperAction('Name this version')
cy.get(':focused').type(`${name}{enter}`) cy.get(':focused').type(`${name}{enter}`)
} }
export function assertVersionContent(filename: string, index: number, expectedContent: string) { export const assertVersionContent = (filename: string, index: number, expectedContent: string) => {
const downloadsFolder = Cypress.config('downloadsFolder') const downloadsFolder = Cypress.config('downloadsFolder')
openVersionMenu(index) openVersionMenu(index)
@ -82,4 +81,4 @@ export function assertVersionContent(filename: string, index: number, expectedCo
return cy.readFile(path.join(downloadsFolder, filename)) return cy.readFile(path.join(downloadsFolder, filename))
.then((versionContent) => expect(versionContent).to.equal(expectedContent)) .then((versionContent) => expect(versionContent).to.equal(expectedContent))
.then(() => cy.exec(`rm ${downloadsFolder}/${filename}`)) .then(() => cy.exec(`rm ${downloadsFolder}/${filename}`))
} }

@ -22,9 +22,11 @@
import { assertVersionContent, clickPopperAction, openVersionMenu, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils' import { assertVersionContent, clickPopperAction, openVersionMenu, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
function restoreVersion(index: number) { const restoreVersion = (index: number) => {
cy.intercept('MOVE', '**/dav/versions/*/versions/**').as('restoreVersion')
openVersionMenu(index) openVersionMenu(index)
clickPopperAction('Restore version') clickPopperAction('Restore version')
cy.wait('@restoreVersion')
} }
describe('Versions restoration', () => { describe('Versions restoration', () => {

Loading…
Cancel
Save