Skip to content

Commit 4551d81

Browse files
authored
Merge pull request #37589 from nextcloud/artonge/backport/stable26/fix/files_versions_cypress_tests
[stable26] Fix cypress tests for files_versions
2 parents 89895ef + e607eff commit 4551d81

File tree

10 files changed

+114
-64
lines changed

10 files changed

+114
-64
lines changed

.github/workflows/cypress.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
fail-fast: false
5858
matrix:
5959
# run multiple copies of the current job in parallel
60-
containers: ['component', 1, 2]
60+
containers: ["component", 1, 2]
6161

6262
name: runner ${{ matrix.containers }}
6363

@@ -91,6 +91,28 @@ jobs:
9191
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9292
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
9393

94+
- name: Extract NC logs
95+
if: failure() && matrix.containers != 'component'
96+
run: docker logs nextcloud-cypress-tests-server > nextcloud.log
97+
98+
- name: Upload NC logs
99+
uses: actions/upload-artifact@v3
100+
if: failure() && matrix.containers != 'component'
101+
with:
102+
name: nc_logs_${{ matrix.containers }}
103+
path: nextcloud.log
104+
105+
- name: Create data dir archive
106+
if: failure() && matrix.containers != 'component'
107+
run: docker exec nextcloud-cypress-tests-server tar -cvjf - data > data.tar
108+
109+
- name: Upload data dir archive
110+
uses: actions/upload-artifact@v3
111+
if: failure() && matrix.containers != 'component'
112+
with:
113+
name: nc_data_${{ matrix.containers }}
114+
path: data.tar
115+
94116
summary:
95117
runs-on: ubuntu-latest
96118
needs: [init, cypress]

cypress.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ export default defineConfig({
7171

7272
// Remove container after run
7373
on('after:run', () => {
74-
stopNextcloud()
74+
if (!process.env.CI) {
75+
stopNextcloud()
76+
}
7577
})
7678

7779
// Before the browser launches

cypress/dockerNode.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ export const configureNextcloud = async function() {
122122
await runExec(container, ['php', 'occ', 'config:system:set', 'default_locale', '--value', 'en_US'], true)
123123
await runExec(container, ['php', 'occ', 'config:system:set', 'force_locale', '--value', 'en_US'], true)
124124
await runExec(container, ['php', 'occ', 'config:system:set', 'enforce_theme', '--value', 'light'], true)
125-
await runExec(container, ['php', 'occ', 'config:system:set', 'versions_retention_obligation', '--value', '0, 0'], true)
126125

127126
console.log('└─ Nextcloud is now ready to use 🎉')
128127
}

cypress/e2e/files_versions/filesVersionsUtils.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
*/
2222

2323
import path from "path"
24+
import type { User } from "@nextcloud/cypress"
2425

25-
export function uploadThreeVersions(user) {
26-
cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', '/test.txt')
27-
cy.wait(1000)
28-
cy.uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', '/test.txt')
29-
cy.wait(1000)
30-
cy.uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', '/test.txt')
26+
export function uploadThreeVersions(user: User, fileName: string) {
27+
// A new version will not be created if the changes occur
28+
// within less than one second of each other.
29+
// eslint-disable-next-line cypress/no-unnecessary-waiting
30+
cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
31+
.wait(1100)
32+
.uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
33+
.wait(1100)
34+
.uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', `/${fileName}`)
3135
cy.login(user)
3236
}
3337

@@ -52,7 +56,7 @@ export function openVersionMenu(index: number) {
5256
cy.get('[data-files-versions-version]')
5357
.eq(index).within(() => {
5458
cy.get('.action-item__menutoggle').filter(':visible')
55-
.click()
59+
.click()
5660
})
5761
})
5862
}
@@ -65,17 +69,17 @@ export function clickPopperAction(actionName: string) {
6569

6670
export function nameVersion(index: number, name: string) {
6771
openVersionMenu(index)
68-
clickPopperAction("Name this version")
72+
clickPopperAction('Name this version')
6973
cy.get(':focused').type(`${name}{enter}`)
7074
}
7175

72-
export function assertVersionContent(index: number, expectedContent: string) {
76+
export function assertVersionContent(filename: string, index: number, expectedContent: string) {
7377
const downloadsFolder = Cypress.config('downloadsFolder')
7478

7579
openVersionMenu(index)
76-
clickPopperAction("Download version")
80+
clickPopperAction('Download version')
7781

78-
return cy.readFile(path.join(downloadsFolder, 'test.txt'))
82+
return cy.readFile(path.join(downloadsFolder, filename))
7983
.then((versionContent) => expect(versionContent).to.equal(expectedContent))
80-
.then(() => cy.exec(`rm ${downloadsFolder}/test.txt`))
84+
.then(() => cy.exec(`rm ${downloadsFolder}/${filename}`))
8185
}

cypress/e2e/files_versions/version_creation.cy.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,22 @@
2323
import { openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
2424

2525
describe('Versions creation', () => {
26+
let randomFileName = ''
27+
2628
before(() => {
29+
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
30+
2731
cy.createRandomUser()
2832
.then((user) => {
29-
uploadThreeVersions(user)
33+
uploadThreeVersions(user, randomFileName)
3034
cy.login(user)
3135
cy.visit('/apps/files')
32-
openVersionsPanel('test.txt')
36+
openVersionsPanel(randomFileName)
3337
})
3438
})
3539

3640
it('Opens the versions panel and sees the versions', () => {
37-
openVersionsPanel('test.txt')
41+
openVersionsPanel(randomFileName)
3842

3943
cy.get('#tab-version_vue').within(() => {
4044
cy.get('[data-files-versions-version]').should('have.length', 3)

cypress/e2e/files_versions/version_download.cy.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,23 @@
2323
import { assertVersionContent, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
2424

2525
describe('Versions download', () => {
26+
let randomFileName = ''
27+
2628
before(() => {
29+
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
30+
2731
cy.createRandomUser()
2832
.then((user) => {
29-
uploadThreeVersions(user)
33+
uploadThreeVersions(user, randomFileName)
3034
cy.login(user)
3135
cy.visit('/apps/files')
32-
openVersionsPanel('test.txt')
36+
openVersionsPanel(randomFileName)
3337
})
3438
})
3539

3640
it('Download versions and assert there content', () => {
37-
assertVersionContent(0, 'v3')
38-
assertVersionContent(1, 'v2')
39-
assertVersionContent(2, 'v1')
41+
assertVersionContent(randomFileName, 0, 'v3')
42+
assertVersionContent(randomFileName, 1, 'v2')
43+
assertVersionContent(randomFileName, 2, 'v1')
4044
})
4145
})

cypress/e2e/files_versions/version_expiration.cy.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,51 @@
2323
import { assertVersionContent, nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
2424

2525
describe('Versions expiration', () => {
26+
let randomFileName = ''
27+
2628
beforeEach(() => {
29+
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
30+
2731
cy.createRandomUser()
2832
.then((user) => {
29-
uploadThreeVersions(user)
33+
uploadThreeVersions(user, randomFileName)
3034
cy.login(user)
3135
cy.visit('/apps/files')
32-
openVersionsPanel('test.txt')
36+
openVersionsPanel(randomFileName)
3337
})
3438
})
3539

3640
it('Expire all versions', () => {
41+
cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
3742
cy.runOccCommand('versions:expire')
43+
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
3844
cy.visit('/apps/files')
39-
openVersionsPanel('test.txt')
45+
openVersionsPanel(randomFileName)
4046

4147
cy.get('#tab-version_vue').within(() => {
4248
cy.get('[data-files-versions-version]').should('have.length', 1)
4349
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
4450
})
4551

46-
assertVersionContent(0, 'v3')
52+
assertVersionContent(randomFileName, 0, 'v3')
4753
})
4854

4955
it('Expire versions v2', () => {
5056
nameVersion(2, 'v1')
5157

58+
cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
5259
cy.runOccCommand('versions:expire')
60+
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
5361
cy.visit('/apps/files')
54-
openVersionsPanel('test.txt')
62+
openVersionsPanel(randomFileName)
5563

5664
cy.get('#tab-version_vue').within(() => {
5765
cy.get('[data-files-versions-version]').should('have.length', 2)
5866
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
5967
cy.get('[data-files-versions-version]').eq(1).contains('v1')
6068
})
6169

62-
assertVersionContent(0, 'v3')
63-
assertVersionContent(1, 'v1')
70+
assertVersionContent(randomFileName, 0, 'v3')
71+
assertVersionContent(randomFileName, 1, 'v1')
6472
})
6573
})

cypress/e2e/files_versions/version_naming.cy.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@
2323
import { nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
2424

2525
describe('Versions naming', () => {
26+
let randomFileName = ''
27+
2628
before(() => {
29+
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
30+
2731
cy.createRandomUser()
2832
.then((user) => {
29-
uploadThreeVersions(user)
33+
uploadThreeVersions(user, randomFileName)
3034
cy.login(user)
3135
cy.visit('/apps/files')
32-
openVersionsPanel('test.txt')
36+
openVersionsPanel(randomFileName)
3337
})
3438
})
3539

cypress/e2e/files_versions/version_restoration.cy.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@ import { assertVersionContent, clickPopperAction, openVersionMenu, openVersionsP
2424

2525
function restoreVersion(index: number) {
2626
openVersionMenu(index)
27-
clickPopperAction("Restore version")
27+
clickPopperAction('Restore version')
2828
}
2929

3030
describe('Versions restoration', () => {
31+
let randomFileName = ''
32+
3133
before(() => {
34+
randomFileName = Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, 10) + '.txt'
35+
3236
cy.createRandomUser()
3337
.then((user) => {
34-
uploadThreeVersions(user)
38+
uploadThreeVersions(user, randomFileName)
3539
cy.login(user)
3640
cy.visit('/apps/files')
37-
openVersionsPanel('test.txt')
41+
openVersionsPanel(randomFileName)
3842
})
3943
})
4044

@@ -48,8 +52,8 @@ describe('Versions restoration', () => {
4852
})
4953

5054
it('Downloads versions and assert there content', () => {
51-
assertVersionContent(0, 'v1')
52-
assertVersionContent(1, 'v3')
53-
assertVersionContent(2, 'v2')
55+
assertVersionContent(randomFileName, 0, 'v1')
56+
assertVersionContent(randomFileName, 1, 'v3')
57+
assertVersionContent(randomFileName, 2, 'v2')
5458
})
5559
})

cypress/support/commands.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,33 +99,32 @@ Cypress.Commands.add('uploadFile', (user, fixture = 'image.jpg', mimeType = 'ima
9999
*/
100100
Cypress.Commands.add('uploadContent', (user, blob, mimeType, target) => {
101101
cy.clearCookies()
102-
.then(async () => {
103-
const fileName = basename(target)
104-
105-
// Process paths
106-
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
107-
const filePath = target.split('/').map(encodeURIComponent).join('/')
108-
try {
109-
const file = new File([blob], fileName, { type: mimeType })
110-
await axios({
111-
url: `${rootPath}${filePath}`,
112-
method: 'PUT',
113-
data: file,
114-
headers: {
115-
'Content-Type': mimeType,
116-
},
117-
auth: {
118-
username: user.userId,
119-
password: user.password,
120-
},
121-
}).then(response => {
102+
.then(async () => {
103+
const fileName = basename(target)
104+
105+
// Process paths
106+
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
107+
const filePath = target.split('/').map(encodeURIComponent).join('/')
108+
try {
109+
const file = new File([blob], fileName, { type: mimeType })
110+
const response = await axios({
111+
url: `${rootPath}${filePath}`,
112+
method: 'PUT',
113+
data: file,
114+
headers: {
115+
'Content-Type': mimeType,
116+
},
117+
auth: {
118+
username: user.userId,
119+
password: user.password,
120+
},
121+
})
122122
cy.log(`Uploaded content as ${fileName}`, response)
123-
})
124-
} catch (error) {
125-
cy.log('error', error)
126-
throw new Error(`Unable to process fixture`)
127-
}
128-
})
123+
} catch (error) {
124+
cy.log('error', error)
125+
throw new Error('Unable to process fixture')
126+
}
127+
})
129128
})
130129

131130
/**

0 commit comments

Comments
 (0)