From: Louis Chemineau Date: Tue, 28 Mar 2023 10:12:52 +0000 (+0200) Subject: Use random names in files_version e2e tests X-Git-Tag: v26.0.1rc1~20^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9d9934fd849697a585bd64d9eda63e0655dcb5b1;p=nextcloud-server.git Use random names in files_version e2e tests Signed-off-by: Louis Chemineau --- diff --git a/cypress/e2e/files_versions/filesVersionsUtils.ts b/cypress/e2e/files_versions/filesVersionsUtils.ts index cc3fc04b2e1..87252fc60f1 100644 --- a/cypress/e2e/files_versions/filesVersionsUtils.ts +++ b/cypress/e2e/files_versions/filesVersionsUtils.ts @@ -21,16 +21,17 @@ */ import path from "path" +import type { User } from "@nextcloud/cypress" -export function uploadThreeVersions(user) { +export function uploadThreeVersions(user: User, fileName: string) { // A new version will not be created if the changes occur // within less than one second of each other. // eslint-disable-next-line cypress/no-unnecessary-waiting - cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', '/test.txt') - .wait(10000) - .uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', '/test.txt') - .wait(10000) - .uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', '/test.txt') + cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', `/${fileName}`) + .wait(1100) + .uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', `/${fileName}`) + .wait(1100) + .uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', `/${fileName}`) cy.login(user) } @@ -72,13 +73,13 @@ export function nameVersion(index: number, name: string) { cy.get(':focused').type(`${name}{enter}`) } -export function assertVersionContent(index: number, expectedContent: string) { +export function assertVersionContent(filename: string, index: number, expectedContent: string) { const downloadsFolder = Cypress.config('downloadsFolder') openVersionMenu(index) clickPopperAction('Download version') - return cy.readFile(path.join(downloadsFolder, 'test.txt')) + return cy.readFile(path.join(downloadsFolder, filename)) .then((versionContent) => expect(versionContent).to.equal(expectedContent)) - .then(() => cy.exec(`rm ${downloadsFolder}/test.txt`)) + .then(() => cy.exec(`rm ${downloadsFolder}/${filename}`)) } \ No newline at end of file diff --git a/cypress/e2e/files_versions/version_creation.cy.ts b/cypress/e2e/files_versions/version_creation.cy.ts index d6655059143..d390d1c4406 100644 --- a/cypress/e2e/files_versions/version_creation.cy.ts +++ b/cypress/e2e/files_versions/version_creation.cy.ts @@ -23,18 +23,22 @@ import { openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils' describe('Versions creation', () => { + let randomFileName = '' + before(() => { + randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt' + cy.createRandomUser() .then((user) => { - uploadThreeVersions(user) + uploadThreeVersions(user, randomFileName) cy.login(user) cy.visit('/apps/files') - openVersionsPanel('test.txt') + openVersionsPanel(randomFileName) }) }) it('Opens the versions panel and sees the versions', () => { - openVersionsPanel('test.txt') + openVersionsPanel(randomFileName) cy.get('#tab-version_vue').within(() => { cy.get('[data-files-versions-version]').should('have.length', 3) diff --git a/cypress/e2e/files_versions/version_download.cy.ts b/cypress/e2e/files_versions/version_download.cy.ts index 69f46915031..30299e9f8e1 100644 --- a/cypress/e2e/files_versions/version_download.cy.ts +++ b/cypress/e2e/files_versions/version_download.cy.ts @@ -23,19 +23,23 @@ import { assertVersionContent, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils' describe('Versions download', () => { + let randomFileName = '' + before(() => { + randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt' + cy.createRandomUser() .then((user) => { - uploadThreeVersions(user) + uploadThreeVersions(user, randomFileName) cy.login(user) cy.visit('/apps/files') - openVersionsPanel('test.txt') + openVersionsPanel(randomFileName) }) }) it('Download versions and assert there content', () => { - assertVersionContent(0, 'v3') - assertVersionContent(1, 'v2') - assertVersionContent(2, 'v1') + assertVersionContent(randomFileName, 0, 'v3') + assertVersionContent(randomFileName, 1, 'v2') + assertVersionContent(randomFileName, 2, 'v1') }) }) diff --git a/cypress/e2e/files_versions/version_expiration.cy.ts b/cypress/e2e/files_versions/version_expiration.cy.ts index fdac454884d..e0c9e36d529 100644 --- a/cypress/e2e/files_versions/version_expiration.cy.ts +++ b/cypress/e2e/files_versions/version_expiration.cy.ts @@ -23,27 +23,31 @@ import { assertVersionContent, nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils' describe('Versions expiration', () => { + let randomFileName = '' + beforeEach(() => { + randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt' + cy.createRandomUser() .then((user) => { - uploadThreeVersions(user) + uploadThreeVersions(user, randomFileName) cy.login(user) cy.visit('/apps/files') - openVersionsPanel('test.txt') + openVersionsPanel(randomFileName) }) }) it('Expire all versions', () => { cy.runOccCommand('versions:expire') cy.visit('/apps/files') - openVersionsPanel('test.txt') + openVersionsPanel(randomFileName) cy.get('#tab-version_vue').within(() => { cy.get('[data-files-versions-version]').should('have.length', 1) cy.get('[data-files-versions-version]').eq(0).contains('Current version') }) - assertVersionContent(0, 'v3') + assertVersionContent(randomFileName, 0, 'v3') }) it('Expire versions v2', () => { @@ -51,7 +55,7 @@ describe('Versions expiration', () => { cy.runOccCommand('versions:expire') cy.visit('/apps/files') - openVersionsPanel('test.txt') + openVersionsPanel(randomFileName) cy.get('#tab-version_vue').within(() => { cy.get('[data-files-versions-version]').should('have.length', 2) @@ -59,7 +63,7 @@ describe('Versions expiration', () => { cy.get('[data-files-versions-version]').eq(1).contains('v1') }) - assertVersionContent(0, 'v3') - assertVersionContent(1, 'v1') + assertVersionContent(randomFileName, 0, 'v3') + assertVersionContent(randomFileName, 1, 'v1') }) }) diff --git a/cypress/e2e/files_versions/version_naming.cy.ts b/cypress/e2e/files_versions/version_naming.cy.ts index 03edae131b6..4b662e31b94 100644 --- a/cypress/e2e/files_versions/version_naming.cy.ts +++ b/cypress/e2e/files_versions/version_naming.cy.ts @@ -23,13 +23,17 @@ import { nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils' describe('Versions naming', () => { + let randomFileName = '' + before(() => { + randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt' + cy.createRandomUser() .then((user) => { - uploadThreeVersions(user) + uploadThreeVersions(user, randomFileName) cy.login(user) cy.visit('/apps/files') - openVersionsPanel('test.txt') + openVersionsPanel(randomFileName) }) }) diff --git a/cypress/e2e/files_versions/version_restoration.cy.ts b/cypress/e2e/files_versions/version_restoration.cy.ts index 74bb82c2c2d..115d30caa82 100644 --- a/cypress/e2e/files_versions/version_restoration.cy.ts +++ b/cypress/e2e/files_versions/version_restoration.cy.ts @@ -28,13 +28,17 @@ function restoreVersion(index: number) { } describe('Versions restoration', () => { + let randomFileName = '' + before(() => { + randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt' + cy.createRandomUser() .then((user) => { - uploadThreeVersions(user) + uploadThreeVersions(user, randomFileName) cy.login(user) cy.visit('/apps/files') - openVersionsPanel('test.txt') + openVersionsPanel(randomFileName) }) }) @@ -48,8 +52,8 @@ describe('Versions restoration', () => { }) it('Downloads versions and assert there content', () => { - assertVersionContent(0, 'v1') - assertVersionContent(1, 'v3') - assertVersionContent(2, 'v2') + assertVersionContent(randomFileName, 0, 'v1') + assertVersionContent(randomFileName, 1, 'v3') + assertVersionContent(randomFileName, 2, 'v2') }) })