Debian Codegraph @

install/freeipa-webui/cypress/e2e/common/authentication.ts

raw symbols SCIP
1 import { When, Given, Then } from "@badeball/cypress-cucumber-preprocessor";
2 import { navigateTo } from "./navigation";
3
4 const login = (username: string, password: string) => {
5 navigateTo("login");
6
7 cy.get("#pf-login-username-id").type(username);
8 cy.get("#pf-login-username-id").should("have.value", username);
9
10 cy.get("#pf-login-password-id").type(password);
11 cy.get("#pf-login-password-id").should("have.value", password);
12
13 cy.get("button[type='submit']").click();
14 };
15
16 export const loginAsAdmin = () => {
17 login(Cypress.env("ADMIN_LOGIN"), Cypress.env("ADMIN_PASSWORD"));
18 cy.dataCy("toolbar-username").should("have.text", "Administrator");
19 };
20
21 export const logout = () => {
22 logoutStep();
23 cy.location("pathname").should("match", new RegExp(`.*login$`));
24 };
25
26 const logoutStep = () => {
27 cy.dataCy("toolbar-username").click();
28 cy.dataCy("toolbar-username").should("have.attr", "aria-expanded", "true");
29 cy.dataCy("toolbar-button-logout").click();
30 };
31
32 Given("I am logged in as admin", () => {
33 loginAsAdmin();
34 });
35
36 When(
37 "I log in as {string} with password {string}",
38 (username: string, password: string) => login(username, password)
39 );
40
41 Then("I should be logged in as {string}", (username: string) => {
42 cy.dataCy("toolbar-username").should("have.text", username);
43 });
44
45 When("I log out", () => {
46 logoutStep();
47 });
48
49 Then("I should be logged out", () => {
50 cy.location("pathname").should("match", new RegExp(`.*login$`));
51 });