From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../dashboard/frontend/cypress/support/commands.ts | 59 ++++++++++++++++++++++ .../frontend/cypress/support/eyes-index.d.ts | 1 + .../dashboard/frontend/cypress/support/index.ts | 11 ++++ 3 files changed, 71 insertions(+) create mode 100644 src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts create mode 100644 src/pybind/mgr/dashboard/frontend/cypress/support/eyes-index.d.ts create mode 100644 src/pybind/mgr/dashboard/frontend/cypress/support/index.ts (limited to 'src/pybind/mgr/dashboard/frontend/cypress/support') diff --git a/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts b/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts new file mode 100644 index 000000000..6ff17f9d6 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts @@ -0,0 +1,59 @@ +declare global { + namespace Cypress { + interface Chainable { + login(): void; + logToConsole(message: string, optional?: any): void; + text(): Chainable; + } + } +} +// Disabling tslint rule since cypress-cucumber has +// issues with absolute import paths. +// This can be removed when +// https://github.com/cypress-io/cypress-browserify-preprocessor/issues/53 +// is fixed. +/* tslint:disable*/ +import { CdHelperClass } from '../../src/app/shared/classes/cd-helper.class'; +import { Permissions } from '../../src/app/shared/models/permissions'; +/* tslint:enable*/ +let auth: any; + +const fillAuth = () => { + window.localStorage.setItem('dashboard_username', auth.username); + window.localStorage.setItem('dashboard_permissions', auth.permissions); + window.localStorage.setItem('user_pwd_expiration_date', auth.pwdExpirationDate); + window.localStorage.setItem('user_pwd_update_required', auth.pwdUpdateRequired); + window.localStorage.setItem('sso', auth.sso); +}; + +Cypress.Commands.add('login', () => { + const username = Cypress.env('LOGIN_USER') || 'admin'; + const password = Cypress.env('LOGIN_PWD') || 'admin'; + + if (auth === undefined) { + cy.request({ + method: 'POST', + url: 'api/auth', + headers: { Accept: CdHelperClass.cdVersionHeader('1', '0') }, + body: { username: username, password: password } + }).then((resp) => { + auth = resp.body; + auth.permissions = JSON.stringify(new Permissions(auth.permissions)); + auth.pwdExpirationDate = String(auth.pwdExpirationDate); + auth.pwdUpdateRequired = String(auth.pwdUpdateRequired); + auth.sso = String(auth.sso); + fillAuth(); + }); + } else { + fillAuth(); + } +}); + +// @ts-ignore +Cypress.Commands.add('text', { prevSubject: true }, (subject: any) => { + return subject.text(); +}); + +Cypress.Commands.add('logToConsole', (message: string, optional?: any) => { + cy.task('log', { message: `(${new Date().toISOString()}) ${message}`, optional }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/cypress/support/eyes-index.d.ts b/src/pybind/mgr/dashboard/frontend/cypress/support/eyes-index.d.ts new file mode 100644 index 000000000..59fc1eca4 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/cypress/support/eyes-index.d.ts @@ -0,0 +1 @@ +import '@applitools/eyes-cypress'; diff --git a/src/pybind/mgr/dashboard/frontend/cypress/support/index.ts b/src/pybind/mgr/dashboard/frontend/cypress/support/index.ts new file mode 100644 index 000000000..f2307131a --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/cypress/support/index.ts @@ -0,0 +1,11 @@ +import '@applitools/eyes-cypress/commands'; + +import './commands'; + +afterEach(() => { + cy.visit('#/403'); +}); + +Cypress.on('uncaught:exception', (err: Error) => { + return !err.message.includes('ResizeObserver loop limit exceeded'); +}); -- cgit v1.2.3