Skip to content

Commit

Permalink
cypress: add logout test
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Oct 23, 2024
1 parent 943b55c commit 8dacb76
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
18 changes: 18 additions & 0 deletions generators/cypress/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down
6 changes: 6 additions & 0 deletions generators/cypress/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' %>';
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
});
});

0 comments on commit 8dacb76

Please sign in to comment.