From 870ab2cab97ebe01f97ab652880c1dc227c72390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Mart=C3=ADn?= Date: Tue, 14 May 2024 00:38:58 +0200 Subject: [PATCH] Adding logout function and refactoring its use. Adding login as admin to delete user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Martín --- cypress/e2e/unit-tests.spec.ts | 12 +++++++----- index.ts | 10 ++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/unit-tests.spec.ts b/cypress/e2e/unit-tests.spec.ts index 63f65b8..ca33b3f 100644 --- a/cypress/e2e/unit-tests.spec.ts +++ b/cypress/e2e/unit-tests.spec.ts @@ -88,15 +88,17 @@ describe('Cypress Library e2e tests', () => { cy.login(); cypressLib.burgerMenuToggle(); cypressLib.createUser('mytestuserwithrole', 'mytestpassword', 'User-Base', true); - // Log out - cy.get('.user.user-menu').click() - cy.contains('Log Out').should('be.visible').click(); - // Log in with new user + // Log out with admin role and login with "User-Base" role to check + // "User-base" does not have these options available + cypressLib.logout(); cy.login('mytestuserwithrole', 'mytestpassword'); cypressLib.burgerMenuToggle(); - // Check "User-base" does not have these options available cy.contains('Continue Delivery').should('not.exist'); cy.contains('Cluster Management').should('not.exist'); + // Log out as user and login back as admin to delete created user + cypressLib.logout(); + cy.login(); + cypressLib.burgerMenuToggle(); cypressLib.deleteUser('mytestuserwithrole'); }); diff --git a/index.ts b/index.ts index 007d235..751ede1 100644 --- a/index.ts +++ b/index.ts @@ -179,6 +179,16 @@ export function deleteUser(username) { cy.contains(username).should('not.exist'); } +/** + * Logout with the current user + * @remarks : Useful when testing role changes + */ +export function logout() { + cy.get('.user.user-menu').click() + cy.contains('Log Out').should('be.visible').click(); + cy.contains('You have been logged out.').should('be.visible') +} + /** * Enable the extension support * @remarks : Disable the Rancher Repo if you provide your own repo