|
| 1 | +import { switchPerspective } from '../../integration-tests/cypress/support/constants'; |
| 2 | +import { app } from '../../integration-tests/cypress/support/pages/app'; |
| 3 | +import { checkDeveloperPerspective } from './checkDeveloperPerspective'; |
| 4 | + |
1 | 5 | export const nav = {
|
2 | 6 | sidenav: {
|
3 | 7 | switcher: {
|
4 |
| - shouldHaveText: (text: string) => |
5 |
| - /* eslint-disable-next-line cypress/unsafe-to-chain-command */ |
6 |
| - cy |
7 |
| - .byLegacyTestID('perspective-switcher-toggle') |
8 |
| - .scrollIntoView() |
9 |
| - .contains(text), |
10 |
| - changePerspectiveTo: (newPerspective: string) => |
11 |
| - /* eslint-disable-next-line cypress/unsafe-to-chain-command */ |
12 |
| - cy |
13 |
| - .byLegacyTestID('perspective-switcher-toggle') |
14 |
| - .click() |
15 |
| - .byLegacyTestID('perspective-switcher-menu-option') |
16 |
| - .contains(newPerspective) |
17 |
| - .click(), |
| 8 | + shouldHaveText: (text: string) => { |
| 9 | + cy.byLegacyTestID('perspective-switcher-toggle').then(($body) => { |
| 10 | + if (text === switchPerspective.Administrator) { |
| 11 | + // if the switcher is hidden it means we are in the admin perspective |
| 12 | + if ($body.attr('aria-hidden') === 'true') { |
| 13 | + cy.log('Admin is the only perspective available'); |
| 14 | + cy.byLegacyTestID('perspective-switcher-toggle').should( |
| 15 | + 'not.be.visible', |
| 16 | + ); |
| 17 | + return; |
| 18 | + } |
| 19 | + } |
| 20 | + cy.byLegacyTestID('perspective-switcher-toggle') |
| 21 | + .scrollIntoView() |
| 22 | + .contains(text); |
| 23 | + }); |
| 24 | + }, |
| 25 | + changePerspectiveTo: (newPerspective: string) => { |
| 26 | + app.waitForDocumentLoad(); |
| 27 | + switch (newPerspective) { |
| 28 | + case 'Administrator': |
| 29 | + case 'administrator': |
| 30 | + case 'Admin': |
| 31 | + case 'admin': |
| 32 | + cy.byLegacyTestID('perspective-switcher-toggle').then(($body) => { |
| 33 | + if ($body.attr('aria-hidden') === 'true') { |
| 34 | + cy.log('Admin is the only perspective available'); |
| 35 | + cy.byLegacyTestID('perspective-switcher-toggle').should( |
| 36 | + 'not.be.visible', |
| 37 | + ); |
| 38 | + return; |
| 39 | + } |
| 40 | + |
| 41 | + if ($body.text().includes('Administrator')) { |
| 42 | + cy.log('Already on admin perspective'); |
| 43 | + cy.byLegacyTestID('perspective-switcher-toggle') |
| 44 | + .scrollIntoView() |
| 45 | + .contains(newPerspective); |
| 46 | + } else { |
| 47 | + cy.byLegacyTestID('perspective-switcher-toggle') |
| 48 | + .click() |
| 49 | + .byLegacyTestID('perspective-switcher-menu-option') |
| 50 | + .contains(newPerspective) |
| 51 | + .click({ force: true }); |
| 52 | + } |
| 53 | + }); |
| 54 | + break; |
| 55 | + case 'Developer': |
| 56 | + case 'developer': |
| 57 | + case 'Dev': |
| 58 | + case 'dev': |
| 59 | + cy.byLegacyTestID('perspective-switcher-toggle') |
| 60 | + .should('be.visible') |
| 61 | + .then(($body) => { |
| 62 | + if ($body.text().includes('Developer')) { |
| 63 | + cy.log('Already on dev perspective'); |
| 64 | + cy.byLegacyTestID('perspective-switcher-toggle') |
| 65 | + .scrollIntoView() |
| 66 | + .contains(newPerspective); |
| 67 | + } else { |
| 68 | + checkDeveloperPerspective(); |
| 69 | + cy.byLegacyTestID('perspective-switcher-toggle') |
| 70 | + .click() |
| 71 | + .byLegacyTestID('perspective-switcher-menu-option') |
| 72 | + .contains(newPerspective) |
| 73 | + .click({ force: true }); |
| 74 | + } |
| 75 | + }); |
| 76 | + break; |
| 77 | + default: |
| 78 | + cy.byLegacyTestID('perspective-switcher-toggle') |
| 79 | + .click() |
| 80 | + .byLegacyTestID('perspective-switcher-menu-option') |
| 81 | + .contains(newPerspective) |
| 82 | + .click({ force: true }); |
| 83 | + } |
| 84 | + }, |
18 | 85 | },
|
19 | 86 | clusters: {
|
20 | 87 | shouldHaveText: (text: string) =>
|
21 | 88 | cy.byLegacyTestID('cluster-dropdown-toggle').contains(text),
|
22 | 89 | changeClusterTo: (newCluster: string) =>
|
23 |
| - /* eslint-disable-next-line cypress/unsafe-to-chain-command */ |
24 | 90 | cy
|
25 | 91 | .byLegacyTestID('cluster-dropdown-toggle')
|
26 | 92 | .click()
|
|
0 commit comments