diff options
author | Louis Chemineau <louis@chmn.me> | 2022-12-21 10:16:44 +0100 |
---|---|---|
committer | Louis (Rebase PR Action) <artonge@users.noreply.github.com> | 2023-01-26 10:12:23 +0000 |
commit | fd9937a171c3dc0d8615e113ccc72f699ab2cd78 (patch) | |
tree | 99603a6727f6f75c1066751fed4c21e5217eafe1 /cypress | |
parent | 305b1b6d2155fa2cd6e911a05ceae98950350226 (diff) | |
download | nextcloud-server-fd9937a171c3dc0d8615e113ccc72f699ab2cd78.tar.gz nextcloud-server-fd9937a171c3dc0d8615e113ccc72f699ab2cd78.zip |
Add cypress tests
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/dockerNode.ts | 1 | ||||
-rw-r--r-- | cypress/e2e/files_versions/filesVersionsUtils.ts | 81 | ||||
-rw-r--r-- | cypress/e2e/files_versions/version_creation.cy.ts | 45 | ||||
-rw-r--r-- | cypress/e2e/files_versions/version_download.cy.ts | 41 | ||||
-rw-r--r-- | cypress/e2e/files_versions/version_expiration.cy.ts | 65 | ||||
-rw-r--r-- | cypress/e2e/files_versions/version_naming.cy.ts | 57 | ||||
-rw-r--r-- | cypress/e2e/files_versions/version_restoration.cy.ts | 55 | ||||
-rw-r--r-- | cypress/support/commands.ts | 42 |
8 files changed, 381 insertions, 6 deletions
diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index af5619bbf80..58544118024 100644 --- a/cypress/dockerNode.ts +++ b/cypress/dockerNode.ts @@ -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 🎉') } diff --git a/cypress/e2e/files_versions/filesVersionsUtils.ts b/cypress/e2e/files_versions/filesVersionsUtils.ts new file mode 100644 index 00000000000..1aa7ebde316 --- /dev/null +++ b/cypress/e2e/files_versions/filesVersionsUtils.ts @@ -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`)) +}
\ 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 new file mode 100644 index 00000000000..d6655059143 --- /dev/null +++ b/cypress/e2e/files_versions/version_creation.cy.ts @@ -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') + }) + }) +}) diff --git a/cypress/e2e/files_versions/version_download.cy.ts b/cypress/e2e/files_versions/version_download.cy.ts new file mode 100644 index 00000000000..69f46915031 --- /dev/null +++ b/cypress/e2e/files_versions/version_download.cy.ts @@ -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') + }) +}) diff --git a/cypress/e2e/files_versions/version_expiration.cy.ts b/cypress/e2e/files_versions/version_expiration.cy.ts new file mode 100644 index 00000000000..fdac454884d --- /dev/null +++ b/cypress/e2e/files_versions/version_expiration.cy.ts @@ -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') + }) +}) diff --git a/cypress/e2e/files_versions/version_naming.cy.ts b/cypress/e2e/files_versions/version_naming.cy.ts new file mode 100644 index 00000000000..03edae131b6 --- /dev/null +++ b/cypress/e2e/files_versions/version_naming.cy.ts @@ -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)') + }) + }) +}) diff --git a/cypress/e2e/files_versions/version_restoration.cy.ts b/cypress/e2e/files_versions/version_restoration.cy.ts new file mode 100644 index 00000000000..0e09b0d8aa6 --- /dev/null +++ b/cypress/e2e/files_versions/version_restoration.cy.ts @@ -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') + }) +}) diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 0da637363de..d214bb2b45e 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -40,6 +40,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}`) +})
\ No newline at end of file |