mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Merge pull request #37345 from nextcloud/artonge/fix_files_version_cypress_tests
Fix cypress tests for files_versions
This commit is contained in:
commit
44cb46c0f2
10 changed files with 113 additions and 63 deletions
24
.github/workflows/cypress.yml
vendored
24
.github/workflows/cypress.yml
vendored
|
|
@ -57,7 +57,7 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
# run multiple copies of the current job in parallel
|
||||
containers: ['component', 1, 2]
|
||||
containers: ["component", 1, 2]
|
||||
|
||||
name: runner ${{ matrix.containers }}
|
||||
|
||||
|
|
@ -91,6 +91,28 @@ jobs:
|
|||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
|
||||
|
||||
- name: Extract NC logs
|
||||
if: failure() && matrix.containers != 'component'
|
||||
run: docker logs nextcloud-cypress-tests-server > nextcloud.log
|
||||
|
||||
- name: Upload NC logs
|
||||
uses: actions/upload-artifact@v3
|
||||
if: failure() && matrix.containers != 'component'
|
||||
with:
|
||||
name: nc_logs_${{ matrix.containers }}
|
||||
path: nextcloud.log
|
||||
|
||||
- name: Create data dir archive
|
||||
if: failure() && matrix.containers != 'component'
|
||||
run: docker exec nextcloud-cypress-tests-server tar -cvjf - data > data.tar
|
||||
|
||||
- name: Upload data dir archive
|
||||
uses: actions/upload-artifact@v3
|
||||
if: failure() && matrix.containers != 'component'
|
||||
with:
|
||||
name: nc_data_${{ matrix.containers }}
|
||||
path: data.tar
|
||||
|
||||
summary:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [init, cypress]
|
||||
|
|
|
|||
|
|
@ -71,7 +71,9 @@ export default defineConfig({
|
|||
|
||||
// Remove container after run
|
||||
on('after:run', () => {
|
||||
stopNextcloud()
|
||||
if (!process.env.CI) {
|
||||
stopNextcloud()
|
||||
}
|
||||
})
|
||||
|
||||
// Before the browser launches
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ export const configureNextcloud = async function() {
|
|||
await runExec(container, ['php', 'occ', 'config:system:set', 'default_locale', '--value', 'en_US'], true)
|
||||
await runExec(container, ['php', 'occ', 'config:system:set', 'force_locale', '--value', 'en_US'], true)
|
||||
await runExec(container, ['php', 'occ', 'config:system:set', 'enforce_theme', '--value', 'light'], true)
|
||||
await runExec(container, ['php', 'occ', 'config:system:set', 'versions_retention_obligation', '--value', '0, 0'], true)
|
||||
|
||||
console.log('└─ Nextcloud is now ready to use 🎉')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,13 +21,17 @@
|
|||
*/
|
||||
|
||||
import path from "path"
|
||||
import type { User } from "@nextcloud/cypress"
|
||||
|
||||
export function uploadThreeVersions(user) {
|
||||
cy.uploadContent(user, new Blob(['v1'], { type: 'text/plain' }), 'text/plain', '/test.txt')
|
||||
cy.wait(1000)
|
||||
cy.uploadContent(user, new Blob(['v2'], { type: 'text/plain' }), 'text/plain', '/test.txt')
|
||||
cy.wait(1000)
|
||||
cy.uploadContent(user, new Blob(['v3'], { type: 'text/plain' }), 'text/plain', '/test.txt')
|
||||
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', `/${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)
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +56,7 @@ export function openVersionMenu(index: number) {
|
|||
cy.get('[data-files-versions-version]')
|
||||
.eq(index).within(() => {
|
||||
cy.get('.action-item__menutoggle').filter(':visible')
|
||||
.click()
|
||||
.click()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -65,17 +69,17 @@ export function clickPopperAction(actionName: string) {
|
|||
|
||||
export function nameVersion(index: number, name: string) {
|
||||
openVersionMenu(index)
|
||||
clickPopperAction("Name this version")
|
||||
clickPopperAction('Name this version')
|
||||
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")
|
||||
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}`))
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -23,35 +23,43 @@
|
|||
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('config:system:set versions_retention_obligation --value "0, 0"')
|
||||
cy.runOccCommand('versions:expire')
|
||||
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
|
||||
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', () => {
|
||||
nameVersion(2, 'v1')
|
||||
|
||||
cy.runOccCommand('config:system:set versions_retention_obligation --value "0, 0"')
|
||||
cy.runOccCommand('versions:expire')
|
||||
cy.runOccCommand('config:system:set versions_retention_obligation --value auto')
|
||||
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 +67,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')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -24,17 +24,21 @@ import { assertVersionContent, clickPopperAction, openVersionMenu, openVersionsP
|
|||
|
||||
function restoreVersion(index: number) {
|
||||
openVersionMenu(index)
|
||||
clickPopperAction("Restore version")
|
||||
clickPopperAction('Restore version')
|
||||
}
|
||||
|
||||
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')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -99,33 +99,32 @@ Cypress.Commands.add('uploadFile', (user, fixture = 'image.jpg', mimeType = 'ima
|
|||
*/
|
||||
Cypress.Commands.add('uploadContent', (user, blob, mimeType, target) => {
|
||||
cy.clearCookies()
|
||||
.then(async () => {
|
||||
const fileName = basename(target)
|
||||
.then(async () => {
|
||||
const fileName = basename(target)
|
||||
|
||||
// Process paths
|
||||
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
|
||||
const filePath = target.split('/').map(encodeURIComponent).join('/')
|
||||
try {
|
||||
const file = new File([blob], fileName, { type: mimeType })
|
||||
await axios({
|
||||
url: `${rootPath}${filePath}`,
|
||||
method: 'PUT',
|
||||
data: file,
|
||||
headers: {
|
||||
'Content-Type': mimeType,
|
||||
},
|
||||
auth: {
|
||||
username: user.userId,
|
||||
password: user.password,
|
||||
},
|
||||
}).then(response => {
|
||||
// Process paths
|
||||
const rootPath = `${Cypress.env('baseUrl')}/remote.php/dav/files/${encodeURIComponent(user.userId)}`
|
||||
const filePath = target.split('/').map(encodeURIComponent).join('/')
|
||||
try {
|
||||
const file = new File([blob], fileName, { type: mimeType })
|
||||
const response = await axios({
|
||||
url: `${rootPath}${filePath}`,
|
||||
method: 'PUT',
|
||||
data: file,
|
||||
headers: {
|
||||
'Content-Type': mimeType,
|
||||
},
|
||||
auth: {
|
||||
username: user.userId,
|
||||
password: user.password,
|
||||
},
|
||||
})
|
||||
cy.log(`Uploaded content as ${fileName}`, response)
|
||||
})
|
||||
} catch (error) {
|
||||
cy.log('error', error)
|
||||
throw new Error(`Unable to process fixture`)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
cy.log('error', error)
|
||||
throw new Error('Unable to process fixture')
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue