From f26ee9c69d98b9208f709e0c7aa284755708adbd Mon Sep 17 00:00:00 2001 From: John Molakvoæ Date: Wed, 30 Nov 2022 17:45:58 +0100 Subject: Faster theming tests, better colours comparison and properly follow admin theming changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- cypress/support/commands.ts | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'cypress/support/commands.ts') diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 2b51f719452..eab26beda79 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -21,7 +21,7 @@ */ /* eslint-disable node/no-unpublished-import */ import axios from '@nextcloud/axios' -import { addCommands, type User} from '@nextcloud/cypress' +import { addCommands, User } from '@nextcloud/cypress' import { basename } from 'path' // Add custom commands @@ -33,7 +33,8 @@ declare global { // eslint-disable-next-line @typescript-eslint/no-namespace namespace Cypress { interface Chainable { - uploadFile(user: User, fixture: string, mimeType: string, target ?: string): Cypress.Chainable + uploadFile(user: User, fixture?: string, mimeType?: string, target ?: string): Cypress.Chainable, + resetTheming(): Cypress.Chainable, } } } @@ -50,7 +51,7 @@ Cypress.env('baseUrl', url) * @param {string} mimeType e.g. image/png * @param {string} [target] the target of the file relative to the user root */ -Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixture}`) => { +Cypress.Commands.add('uploadFile', (user, fixture = 'image.jpg', mimeType = 'image/jpeg', target = `/${fixture}`) => { cy.clearCookies() const fileName = basename(target) @@ -84,3 +85,29 @@ Cypress.Commands.add('uploadFile', (user, fixture, mimeType, target = `/${fixtur } }) }) + +/** + * Reset the admin theming entirely + */ + Cypress.Commands.add('resetTheming', () => { + const admin = new User('admin', 'admin') + + cy.clearCookies() + cy.login(admin) + + // Clear all settings + cy.request('/csrftoken').then(({ body }) => { + const requestToken = body.token + + axios({ + method: 'POST', + url: '/index.php/apps/theming/ajax/undoAllChanges', + headers: { + 'requesttoken': requestToken, + }, + }) + }) + + // Clear admin session + cy.clearCookies() +}) -- cgit v1.2.3