From 8dacb76061487015f6b53e1c55aced8eefe40a57 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 23 Oct 2024 06:09:37 -0300 Subject: [PATCH] cypress: add logout test --- .../__snapshots__/generator.spec.ts.snap | 18 +++++++++ generators/cypress/files.ts | 6 +++ .../cypress/e2e/account/login-page.cy.ts.ejs | 4 +- .../cypress/e2e/account/logout.cy.ts.ejs | 39 +++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 generators/cypress/templates/src/test/javascript/cypress/e2e/account/logout.cy.ts.ejs diff --git a/generators/cypress/__snapshots__/generator.spec.ts.snap b/generators/cypress/__snapshots__/generator.spec.ts.snap index 7a834104a09d..28ab8d8541a8 100644 --- a/generators/cypress/__snapshots__/generator.spec.ts.snap +++ b/generators/cypress/__snapshots__/generator.spec.ts.snap @@ -17,6 +17,9 @@ exports[`generator - cypress jwt-cypressAudit(false)-angular-withAdminUi(false)- "clientRoot/src/test/javascript/cypress/e2e/account/login-page.cy.ts": { "stateCleared": "modified", }, + "clientRoot/src/test/javascript/cypress/e2e/account/logout.cy.ts": { + "stateCleared": "modified", + }, "clientRoot/src/test/javascript/cypress/e2e/account/password-page.cy.ts": { "stateCleared": "modified", }, @@ -88,6 +91,9 @@ exports[`generator - cypress jwt-cypressAudit(true)-vue-withAdminUi(true)-cypres "clientRoot/src/test/javascript/cypress/e2e/account/login-page.cy.ts": { "stateCleared": "modified", }, + "clientRoot/src/test/javascript/cypress/e2e/account/logout.cy.ts": { + "stateCleared": "modified", + }, "clientRoot/src/test/javascript/cypress/e2e/account/password-page.cy.ts": { "stateCleared": "modified", }, @@ -156,6 +162,9 @@ exports[`generator - cypress oauth2-cypressAudit(false)-angular-withAdminUi(fals "package.json": { "stateCleared": "modified", }, + "src/test/javascript/cypress/e2e/account/logout.cy.ts": { + "stateCleared": "modified", + }, "src/test/javascript/cypress/e2e/administration/administration.cy.ts": { "stateCleared": "modified", }, @@ -209,6 +218,9 @@ exports[`generator - cypress oauth2-cypressAudit(true)-vue-withAdminUi(true)-cyp "package.json": { "stateCleared": "modified", }, + "src/test/javascript/cypress/e2e/account/logout.cy.ts": { + "stateCleared": "modified", + }, "src/test/javascript/cypress/e2e/administration/administration.cy.ts": { "stateCleared": "modified", }, @@ -339,6 +351,9 @@ exports[`generator - cypress session-cypressAudit(false)-angular-withAdminUi(fal "src/test/javascript/cypress/e2e/account/login-page.cy.ts": { "stateCleared": "modified", }, + "src/test/javascript/cypress/e2e/account/logout.cy.ts": { + "stateCleared": "modified", + }, "src/test/javascript/cypress/e2e/account/password-page.cy.ts": { "stateCleared": "modified", }, @@ -410,6 +425,9 @@ exports[`generator - cypress session-cypressAudit(true)-vue-withAdminUi(true)-cy "src/test/javascript/cypress/e2e/account/login-page.cy.ts": { "stateCleared": "modified", }, + "src/test/javascript/cypress/e2e/account/logout.cy.ts": { + "stateCleared": "modified", + }, "src/test/javascript/cypress/e2e/account/password-page.cy.ts": { "stateCleared": "modified", }, diff --git a/generators/cypress/files.ts b/generators/cypress/files.ts index d35a4c20e38c..4d8cb3b056b7 100644 --- a/generators/cypress/files.ts +++ b/generators/cypress/files.ts @@ -52,6 +52,12 @@ export const cypressFiles: WriteFileSection = { 'tsconfig.json', ], }, + { + condition: generator => !generator.applicationTypeMicroservice, + path: CYPRESS_TEMPLATE_SOURCE_DIR, + renameTo: (ctx, file) => `${ctx.cypressDir}${file}`, + templates: ['e2e/account/logout.cy.ts'], + }, { condition: generator => !generator.authenticationTypeOauth2, path: CYPRESS_TEMPLATE_SOURCE_DIR, diff --git a/generators/cypress/templates/src/test/javascript/cypress/e2e/account/login-page.cy.ts.ejs b/generators/cypress/templates/src/test/javascript/cypress/e2e/account/login-page.cy.ts.ejs index f5575e3c3796..3e075c280f95 100644 --- a/generators/cypress/templates/src/test/javascript/cypress/e2e/account/login-page.cy.ts.ejs +++ b/generators/cypress/templates/src/test/javascript/cypress/e2e/account/login-page.cy.ts.ejs @@ -24,7 +24,7 @@ import { submitLoginSelector, } from '../../support/commands'; -describe('login modal', () => { +describe('login page', () => { const username = Cypress.env('E2E_USERNAME') ?? '<%= skipUserManagement && (applicationTypeMonolith || applicationTypeGateway) ? 'admin' : 'user' %>'; const password = Cypress.env('E2E_PASSWORD') ?? '<%= skipUserManagement && (applicationTypeMonolith || applicationTypeGateway) ? 'admin' : 'user' %>'; @@ -78,7 +78,7 @@ describe('login modal', () => { cy.get(errorLoginSelector).should('be.visible'); }); - it('go to login page when successfully logs in', () => { + it('go to home page when successfully logs in', () => { cy.get(usernameLoginSelector).type(username); cy.get(passwordLoginSelector).type(password); cy.get(submitLoginSelector).click(); diff --git a/generators/cypress/templates/src/test/javascript/cypress/e2e/account/logout.cy.ts.ejs b/generators/cypress/templates/src/test/javascript/cypress/e2e/account/logout.cy.ts.ejs new file mode 100644 index 000000000000..9e625b3f7899 --- /dev/null +++ b/generators/cypress/templates/src/test/javascript/cypress/e2e/account/logout.cy.ts.ejs @@ -0,0 +1,39 @@ +<%# + Copyright 2013-2024 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +-%> +import { + accountMenuSelector, + navbarSelector, + loginItemSelector, +} from '../../support/commands'; + +describe('logout', () => { + const username = Cypress.env('E2E_USERNAME') ?? 'user'; + const password = Cypress.env('E2E_PASSWORD') ?? 'user'; + + it<%- clientFrameworkReact ? '.skip' : '' %>('go to home page when successfully logs out', () => { + cy.login(username, password); + cy.visit(''); + cy.clickOnLogoutItem(); + // Wait logout + cy.wait(500); // eslint-disable-line cypress/no-unnecessary-waiting + cy.visit(''); + cy.get(navbarSelector).get(accountMenuSelector).click(); + cy.get(navbarSelector).get(accountMenuSelector).get(loginItemSelector).should('be.visible'); + }); +});