diff options
Diffstat (limited to 'cypress/e2e/files_versions/filesVersionsUtils.ts')
-rw-r--r-- | cypress/e2e/files_versions/filesVersionsUtils.ts | 115 |
1 files changed, 60 insertions, 55 deletions
diff --git a/cypress/e2e/files_versions/filesVersionsUtils.ts b/cypress/e2e/files_versions/filesVersionsUtils.ts index 789bfc97d4e..75c76b7e97c 100644 --- a/cypress/e2e/files_versions/filesVersionsUtils.ts +++ b/cypress/e2e/files_versions/filesVersionsUtils.ts @@ -1,29 +1,12 @@ /** - * @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/>. - * + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ +/* eslint-disable jsdoc/require-jsdoc */ +import type { User } from '@nextcloud/cypress' +import { createShare, type ShareSetting } from '../files_sharing/FilesSharingUtils' -import path from "path" -import type { User } from "@nextcloud/cypress" - -export function uploadThreeVersions(user: User, fileName: string) { +export const 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 @@ -36,50 +19,72 @@ export function uploadThreeVersions(user: User, fileName: string) { } export function openVersionsPanel(fileName: string) { - cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"]`).within(() => { - cy.get('[data-cy-files-list-row-actions] .action-item__menutoggle') - .click() + // Detect the versions list fetch + cy.intercept('PROPFIND', '**/dav/versions/*/versions/**').as('getVersions') + + // Open the versions tab + cy.window().then(win => { + win.OCA.Files.Sidebar.setActiveTab('version_vue') + win.OCA.Files.Sidebar.open(`/${fileName}`) }) - cy.get('.action-item__popper') - .get('[data-cy-files-list-row-action="details"]') - .click() + // Wait for the versions list to be fetched + cy.wait('@getVersions') + cy.get('#tab-version_vue').should('be.visible', { timeout: 10000 }) +} - cy.get('#app-sidebar-vue') - .get('[aria-controls="tab-version_vue"]') +export function toggleVersionMenu(index: number) { + cy.get('#tab-version_vue [data-files-versions-version]') + .eq(index) + .find('button') .click() +} +export function triggerVersionAction(index: number, actionName: string) { + toggleVersionMenu(index) + cy.get(`[data-cy-files-versions-version-action="${actionName}"]`).filter(':visible').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 nameVersion(index: number, name: string) { + cy.intercept('PROPPATCH', '**/dav/versions/*/versions/**').as('labelVersion') + triggerVersionAction(index, 'label') + cy.get(':focused').type(`${name}{enter}`) + cy.wait('@labelVersion') } -export function clickPopperAction(actionName: string) { - cy.get('.v-popper__popper').filter(':visible') - .contains(actionName) - .click() +export function restoreVersion(index: number) { + cy.intercept('MOVE', '**/dav/versions/*/versions/**').as('restoreVersion') + triggerVersionAction(index, 'restore') + cy.wait('@restoreVersion') } -export function nameVersion(index: number, name: string) { - openVersionMenu(index) - clickPopperAction('Name this version') - cy.get(':focused').type(`${name}{enter}`) +export function deleteVersion(index: number) { + cy.intercept('DELETE', '**/dav/versions/*/versions/**').as('deleteVersion') + triggerVersionAction(index, 'delete') + cy.wait('@deleteVersion') } -export function assertVersionContent(filename: string, index: number, expectedContent: string) { - const downloadsFolder = Cypress.config('downloadsFolder') +export function doesNotHaveAction(index: number, actionName: string) { + toggleVersionMenu(index) + cy.get(`[data-cy-files-versions-version-action="${actionName}"]`).should('not.exist') + toggleVersionMenu(index) +} - openVersionMenu(index) - clickPopperAction('Download version') +export function assertVersionContent(index: number, expectedContent: string) { + cy.intercept({ method: 'GET', times: 1, url: 'remote.php/**' }).as('downloadVersion') + triggerVersionAction(index, 'download') + cy.wait('@downloadVersion') + .then(({ response }) => expect(response?.body).to.equal(expectedContent)) +} - return cy.readFile(path.join(downloadsFolder, filename)) - .then((versionContent) => expect(versionContent).to.equal(expectedContent)) - .then(() => cy.exec(`rm ${downloadsFolder}/${filename}`)) -}
\ No newline at end of file +export function setupTestSharedFileFromUser(owner: User, randomFileName: string, shareOptions: Partial<ShareSetting>) { + return cy.createRandomUser() + .then((recipient) => { + cy.login(owner) + cy.visit('/apps/files') + createShare(randomFileName, recipient.userId, shareOptions) + cy.login(recipient) + cy.visit('/apps/files') + return cy.wrap(recipient) + }) +} |