diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts | 59 |
1 files changed, 59 insertions, 0 deletions
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<Subject> { + login(): void; + logToConsole(message: string, optional?: any): void; + text(): Chainable<string>; + } + } +} +// 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 }); +}); |