]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use random names in files_version e2e tests
authorLouis Chemineau <louis@chmn.me>
Tue, 28 Mar 2023 10:12:52 +0000 (12:12 +0200)
committerLouis Chemineau <louis@chmn.me>
Wed, 5 Apr 2023 09:51:45 +0000 (11:51 +0200)
Signed-off-by: Louis Chemineau <louis@chmn.me>
cypress/e2e/files_versions/filesVersionsUtils.ts
cypress/e2e/files_versions/version_creation.cy.ts
cypress/e2e/files_versions/version_download.cy.ts
cypress/e2e/files_versions/version_expiration.cy.ts
cypress/e2e/files_versions/version_naming.cy.ts
cypress/e2e/files_versions/version_restoration.cy.ts

index cc3fc04b2e1129444503c252ccf976b03b502d30..87252fc60f1179dd7d512ed8dcd8196ee7d84dac 100644 (file)
  */
 
 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
index d6655059143aa091ae084d0c3467136408a66467..d390d1c440621be7a84e050119e825abada1f464 100644 (file)
 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)
index 69f46915031d5fea14fb29d2b762dbeaa9b9b645..30299e9f8e130bbda29dd0c193ae38ccbdc76d75 100644 (file)
 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')
        })
 })
index fdac454884d36477ad50d3d0bb8cb16489bb6a33..e0c9e36d529282334cb1bf38b9a5dec6326bd802 100644 (file)
 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')
        })
 })
index 03edae131b6cb55bb3d8059aefad016e6db41523..4b662e31b946715a1bc5535b1e74ea829d90f911 100644 (file)
 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)
                        })
        })
 
index 74bb82c2c2de7affbf443ca34b98121211792571..115d30caa82eee2e41d66ab7f5abe6f00600ad01 100644 (file)
@@ -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')
        })
 })