Add cypress tests

Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/35160/head
Louis Chemineau 1 year ago committed by Louis (Rebase PR Action)
parent 305b1b6d21
commit fd9937a171

@ -20,7 +20,8 @@
<NcListItem class="version"
:title="versionLabel"
:href="downloadURL"
:force-display-actions="true">
:force-display-actions="true"
data-files-versions-version>
<template #icon>
<img lazy="true"
:src="previewURL"

@ -16,7 +16,7 @@
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<ul>
<ul data-files-versions-versions-list>
<Version v-for="version in orderedVersions"
:key="version.mtime"
:version="version"

@ -122,6 +122,7 @@ 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 🎉')
}

@ -0,0 +1,81 @@
/**
* @copyright Copyright (c) 2022 Louis Chemineau <louis@chmn.me>
*
* @author Louis Chemineau <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import path from "path"
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')
cy.login(user)
}
export function openVersionsPanel(fileName: string) {
cy.get(`[data-file="${fileName}"]`).within(() => {
cy.get('[data-action="menu"]')
.click()
cy.get('.fileActionsMenu')
.get('.action-details')
.click()
})
cy.get('#app-sidebar-vue')
.get('[aria-controls="tab-version_vue"]')
.click()
}
export function openVersionMenu(index: number) {
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]')
.eq(index).within(() => {
cy.get('.action-item__menutoggle').filter(':visible')
.click()
})
})
}
export function clickPopperAction(actionName: string) {
cy.get('.v-popper__popper').filter(':visible')
.contains(actionName)
.click()
}
export function nameVersion(index: number, name: string) {
openVersionMenu(index)
clickPopperAction("Name this version")
cy.get(':focused').type(`${name}{enter}`)
}
export function assertVersionContent(index: number, expectedContent: string) {
const downloadsFolder = Cypress.config('downloadsFolder')
openVersionMenu(index)
clickPopperAction("Download version")
return cy.readFile(path.join(downloadsFolder, 'test.txt'))
.then((versionContent) => expect(versionContent).to.equal(expectedContent))
.then(() => cy.exec(`rm ${downloadsFolder}/test.txt`))
}

@ -0,0 +1,45 @@
/**
* @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me>
*
* @author Louis Chmn <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
describe('Versions creation', () => {
before(() => {
cy.createRandomUser()
.then((user) => {
uploadThreeVersions(user)
cy.login(user)
cy.visit('/apps/files')
openVersionsPanel('test.txt')
})
})
it('Opens the versions panel and sees the versions', () => {
openVersionsPanel('test.txt')
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 3)
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
cy.get('[data-files-versions-version]').eq(2).contains('Initial version')
})
})
})

@ -0,0 +1,41 @@
/**
* @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me>
*
* @author Louis Chmn <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { assertVersionContent, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
describe('Versions download', () => {
before(() => {
cy.createRandomUser()
.then((user) => {
uploadThreeVersions(user)
cy.login(user)
cy.visit('/apps/files')
openVersionsPanel('test.txt')
})
})
it('Download versions and assert there content', () => {
assertVersionContent(0, 'v3')
assertVersionContent(1, 'v2')
assertVersionContent(2, 'v1')
})
})

@ -0,0 +1,65 @@
/**
* @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me>
*
* @author Louis Chmn <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { assertVersionContent, nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
describe('Versions expiration', () => {
beforeEach(() => {
cy.createRandomUser()
.then((user) => {
uploadThreeVersions(user)
cy.login(user)
cy.visit('/apps/files')
openVersionsPanel('test.txt')
})
})
it('Expire all versions', () => {
cy.runOccCommand('versions:expire')
cy.visit('/apps/files')
openVersionsPanel('test.txt')
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')
})
it('Expire versions v2', () => {
nameVersion(2, 'v1')
cy.runOccCommand('versions:expire')
cy.visit('/apps/files')
openVersionsPanel('test.txt')
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 2)
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
cy.get('[data-files-versions-version]').eq(1).contains('v1')
})
assertVersionContent(0, 'v3')
assertVersionContent(1, 'v1')
})
})

@ -0,0 +1,57 @@
/**
* @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me>
*
* @author Louis Chmn <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { nameVersion, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
describe('Versions naming', () => {
before(() => {
cy.createRandomUser()
.then((user) => {
uploadThreeVersions(user)
cy.login(user)
cy.visit('/apps/files')
openVersionsPanel('test.txt')
})
})
it('Names the initial version as v1', () => {
nameVersion(2, 'v1')
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').eq(2).contains('v1')
cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
})
})
it('Names the second version as v2', () => {
nameVersion(1, 'v2')
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').eq(1).contains('v2')
})
})
it('Names the current version as v3', () => {
nameVersion(0, 'v3')
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').eq(0).contains('v3 (Current version)')
})
})
})

@ -0,0 +1,55 @@
/**
* @copyright Copyright (c) 2022 Louis Chmn <louis@chmn.me>
*
* @author Louis Chmn <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { assertVersionContent, clickPopperAction, openVersionMenu, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'
function restoreVersion(index: number) {
openVersionMenu(index)
clickPopperAction("Restore version")
}
describe('Versions restoration', () => {
before(() => {
cy.createRandomUser()
.then((user) => {
uploadThreeVersions(user)
cy.login(user)
cy.visit('/apps/files')
openVersionsPanel('test.txt')
})
})
it('Restores initial version', () => {
restoreVersion(2)
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]').should('have.length', 3)
cy.get('[data-files-versions-version]').eq(0).contains('Current version')
cy.get('[data-files-versions-version]').eq(2).contains('Initial version').should('not.exist')
})
})
it('Downloads versions and assert there content', () => {
assertVersionContent(0, 'v1')
assertVersionContent(1, 'v3')
assertVersionContent(2, 'v2')
})
})

@ -39,6 +39,12 @@ declare global {
*/
uploadFile(user: User, fixture?: string, mimeType?: string, target?: string): Cypress.Chainable<void>,
/**
* Upload a raw content to a given user storage.
* **Warning**: Using this function will reset the previous session
*/
uploadContent(user: User, content: Blob, mimeType: string, target: string): Cypress.Chainable<void>,
/**
* Reset the admin theming entirely.
* **Warning**: Using this function will reset the previous session
@ -51,6 +57,11 @@ declare global {
* **Warning**: Providing a user will reset the previous session.
*/
resetUserTheming(user?: User): Cypress.Chainable<void>,
/**
* Run an occ command in the docker container.
*/
runOccCommand(command: string): Cypress.Chainable<void>,
}
}
}
@ -68,19 +79,34 @@ Cypress.env('baseUrl', url)
* @param {string} [target] the target of the file relative to the user root
*/
Cypress.Commands.add('uploadFile', (user, fixture = 'image.jpg', mimeType = 'image/jpeg', target = `/${fixture}`) => {
cy.clearCookies()
const fileName = basename(target)
// get fixture
return cy.fixture(fixture, 'base64').then(async file => {
// convert the base64 string to a blob
const blob = Cypress.Blob.base64StringToBlob(file, mimeType)
cy.uploadContent(user, blob, mimeType, target)
})
})
/**
* cy.uploadedContent - uploads a raw content
* TODO: standardise in @nextcloud/cypress
*
* @param {User} user the owner of the file, e.g. admin
* @param {Blob} blob the content to upload
* @param {string} mimeType e.g. image/png
* @param {string} target the target of the file relative to the user root
*/
Cypress.Commands.add('uploadContent', (user, blob, mimeType, target) => {
cy.clearCookies()
.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 })
const file = new File([blob], fileName, { type: mimeType })
await axios({
url: `${rootPath}${filePath}`,
method: 'PUT',
@ -93,11 +119,11 @@ Cypress.Commands.add('uploadFile', (user, fixture = 'image.jpg', mimeType = 'ima
password: user.password,
},
}).then(response => {
cy.log(`Uploaded ${fixture} as ${fileName}`, response)
cy.log(`Uploaded content as ${fileName}`, response)
})
} catch (error) {
cy.log('error', error)
throw new Error(`Unable to process fixture ${fixture}`)
throw new Error(`Unable to process fixture`)
}
})
})
@ -157,3 +183,7 @@ Cypress.Commands.add('resetUserTheming', (user?: User) => {
cy.clearCookies()
}
})
Cypress.Commands.add('runOccCommand', (command: string) => {
cy.exec(`docker exec --user www-data nextcloud-cypress-tests-server php ./occ ${command}`)
})
Loading…
Cancel
Save