Skip to content

Commit

Permalink
Renew tokens asynchronously #157
Browse files Browse the repository at this point in the history
  • Loading branch information
hupf committed Nov 5, 2024
1 parent 7b338d8 commit c6c823e
Show file tree
Hide file tree
Showing 21 changed files with 1,024 additions and 410 deletions.
410 changes: 410 additions & 0 deletions cypress/e2e/auth.cy.ts

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions cypress/e2e/footer.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("Footer", () => {
});

it("renders the footer with links to contact, legal and imprint pages", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");

cy.get("bkd-footer").within(() => {
cy.get("a").contains("Kontakt");
Expand All @@ -19,7 +19,7 @@ describe("Footer", () => {
});

it("renders the static contact page", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get("bkd-footer").find("a").contains("Kontakt").click();

cy.get("h1").contains("Kontakt", {});
Expand All @@ -28,7 +28,7 @@ describe("Footer", () => {
});

it("renders the static legal page", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get("bkd-footer").find("a").contains("Rechtliche Hinweise").click();

cy.get("h1").contains("Rechtliche Hinweise", {});
Expand All @@ -37,7 +37,7 @@ describe("Footer", () => {
});

it("renders the static imprint page", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get("bkd-footer").find("a").contains("Impressum").click();

cy.get("h1").contains("Impressum", {});
Expand All @@ -52,7 +52,7 @@ describe("Footer", () => {
});

it("renders the footer with links to contact, legal and imprint pages", () => {
cy.visit("/index.html?locale=fr-CH");
cy.visitPortal("/index.html?locale=fr-CH");
cy.get("bkd-footer").within(() => {
cy.get("a").contains("Contact");
cy.get("a").contains("Mentions légales");
Expand All @@ -61,7 +61,7 @@ describe("Footer", () => {
});

it("renders the static contact page", () => {
cy.visit("/index.html?locale=fr-CH");
cy.visitPortal("/index.html?locale=fr-CH");
cy.get("bkd-footer").find("a").contains("Contact").click();

cy.get("h1").contains("Contact", {});
Expand All @@ -70,7 +70,7 @@ describe("Footer", () => {
});

it("renders the static legal page", () => {
cy.visit("/index.html?locale=fr-CH");
cy.visitPortal("/index.html?locale=fr-CH");
cy.get("bkd-footer").find("a").contains("Mentions légales").click();

cy.get("h1").contains("Mentions légales", {});
Expand All @@ -79,7 +79,7 @@ describe("Footer", () => {
});

it("renders the static imprint page", () => {
cy.visit("/index.html?locale=fr-CH");
cy.visitPortal("/index.html?locale=fr-CH");
cy.get("bkd-footer").find("a").contains("Impressum").click();

cy.get("h1").contains("Impressum", {});
Expand Down
44 changes: 34 additions & 10 deletions cypress/e2e/locale.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
describe("Locale", () => {
// Apparently, since token refresh is involved, we cannot test the
// language switching and must make sure that a token for the
// desired locale is already present
import { createToken } from "../support/commands";

describe("Locale", () => {
describe("with de-CH token", () => {
beforeEach(() =>
cy.login({
Expand All @@ -14,15 +12,41 @@ describe("Locale", () => {

it("uses de-CH", () => {
cy.resizeToDesktop();
cy.visit("/index.html");
cy.contains("Unterricht");
cy.contains("Bildungs- und Kulturdirektion");
cy.visitPortal("/index.html");
cy.contains("Unterricht").should("exist");
cy.iframeContains("Stundenplan");

cy.get("bkd-language-switcher").within(() => {
cy.contains("a", "de").should("have.class", "active");
cy.contains("a", "fr").should("not.have.class", "active");
});
});

it("switches to fr-CH token", () => {
cy.resizeToDesktop();
cy.visitPortal("/index.html");
cy.contains("Unterricht").should("exist");
cy.iframeContains("Stundenplan");

const token = createToken("Tutoring", { locale: "fr-CH" });
cy.intercept("https://eventotest.api/OAuth/Authorization/Test/Token", {
access_token: token,
refresh_token: token,
expires_in: 60 * 60,
});

// Switch to fr
cy.get("bkd-language-switcher").within(() => {
cy.contains("a", "fr").click();
});

cy.contains("Enseignement").should("exist");
cy.iframeContains("Horaire");
cy.get("bkd-language-switcher").within(() => {
cy.contains("a", "de").should("not.have.class", "active");
cy.contains("a", "fr").should("have.class", "active");
});
});
});

describe("with fr-CH token", () => {
Expand All @@ -36,9 +60,9 @@ describe("Locale", () => {

it("uses fr-CH", () => {
cy.resizeToDesktop();
cy.visit("/index.html?locale=fr-CH");
cy.contains("Enseignement");
cy.contains("Direction de l'instruction publique et de la culture");
cy.visitPortal("/index.html?locale=fr-CH");
cy.contains("Enseignement").should("exist");
cy.iframeContains("Horaire");

cy.get("bkd-language-switcher").within(() => {
cy.contains("a", "de").should("not.have.class", "active");
Expand Down
20 changes: 10 additions & 10 deletions cypress/e2e/navigationMenu.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("Navigation Menu", () => {
describe("desktop", () => {
beforeEach(() => {
cy.resizeToDesktop();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("renders main navigation", () => {
Expand Down Expand Up @@ -69,7 +69,7 @@ describe("Navigation Menu", () => {
describe("mobile", () => {
beforeEach(() => {
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("open/closes hamburger menu by click on hamburger", () => {
Expand Down Expand Up @@ -144,7 +144,7 @@ describe("Navigation Menu", () => {
beforeEach(() => {
cy.login({ roles: ["StudentRole"], permissions: [] });
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("only renders allowed groups & items", () => {
Expand All @@ -169,7 +169,7 @@ describe("Navigation Menu", () => {
permissions: [],
});
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("only renders allowed groups & items", () => {
Expand Down Expand Up @@ -206,7 +206,7 @@ describe("Navigation Menu", () => {
beforeEach(() => {
cy.login({ roles: ["ClassTeacherRole"], permissions: [] });
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("only renders allowed groups & items", () => {
Expand Down Expand Up @@ -237,7 +237,7 @@ describe("Navigation Menu", () => {
beforeEach(() => {
cy.login({ roles: ["AbsenceAdministratorRole"], permissions: [] });
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("only renders allowed groups & items", () => {
Expand Down Expand Up @@ -265,7 +265,7 @@ describe("Navigation Menu", () => {
beforeEach(() => {
cy.login({ roles: ["SubstituteAdministratorRole"], permissions: [] });
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("only renders allowed groups & items", () => {
Expand All @@ -292,7 +292,7 @@ describe("Navigation Menu", () => {
beforeEach(() => {
cy.login({ roles: [], permissions: ["PersonRight"] });
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("only renders allowed groups & items", () => {
Expand Down Expand Up @@ -320,7 +320,7 @@ describe("Navigation Menu", () => {
permissions: ["RegistrationRightWeiterbildungModulanlass"],
});
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("only renders allowed groups & items", () => {
Expand All @@ -345,7 +345,7 @@ describe("Navigation Menu", () => {
permissions: ["RegistrationRightWeiterbildungKurs"],
});
cy.resizeToMobile();
cy.visit("/index.html");
cy.visitPortal("/index.html");
});

it("only renders allowed groups & items", () => {
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/navigationRouting.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("Navigation & Routing", () => {
});

it("does not select any menu entry per default", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get("bkd-nav").as("desktopMenu").should("be.visible");

// No group activated
Expand Down Expand Up @@ -60,7 +60,7 @@ describe("Navigation & Routing", () => {
});

it("selects menu entry from URL", () => {
cy.visit("/index.html?module=presenceControl");
cy.visitPortal("/index.html?module=presenceControl");
cy.get("bkd-nav").as("desktopMenu").should("be.visible");

// Activates navigation group
Expand Down Expand Up @@ -117,7 +117,7 @@ describe("Navigation & Routing", () => {
});

it("redirects to home for invalid item key in URL", () => {
cy.visit("/index.html?module=asdf");
cy.visitPortal("/index.html?module=asdf");
cy.get("bkd-nav").as("desktopMenu").should("be.visible");

// No group activated
Expand Down Expand Up @@ -174,7 +174,7 @@ describe("Navigation & Routing", () => {
});

it("applies menu entry selection to URL", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get("bkd-nav").as("desktopMenu").should("be.visible");

// Group not active
Expand Down Expand Up @@ -242,7 +242,7 @@ describe("Navigation & Routing", () => {
});

it("visits profile (a specific sub app path of an item)", () => {
cy.visit(
cy.visitPortal(
"index.html?locale=de-CH&module=presenceControl#/presence-control/student/5389/absences?returnparams=date%3D2023-07-03%26viewMode%3Dgrid%26lesson%3D291257",
);
cy.get("bkd-nav").as("desktopMenu").should("be.visible");
Expand Down Expand Up @@ -280,7 +280,7 @@ describe("Navigation & Routing", () => {
});

it("selects menu item from URL and expands its group", () => {
cy.visit("/index.html?module=presenceControl");
cy.visitPortal("/index.html?module=presenceControl");
cy.get("iframe").should(
"have.attr",
"src",
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/notifications.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ describe("Notifications", () => {

describe("no notifications", () => {
it("renders bell without counter", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get('[aria-label="Benachrichtigungen"]').as("toggle");
cy.get("@toggle").get(".circle").should("be.hidden");
});

it("opens dropdown without notifications and delete button disabled", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get('[aria-label="Benachrichtigungen"]').as("toggle");
cy.get("@toggle").click();
cy.get("#notifications-dropdown").as("dropdown").should("exist");
Expand All @@ -68,13 +68,13 @@ describe("Notifications", () => {
});

it("renders bell with counter", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get('[aria-label="Benachrichtigungen"]').as("toggle");
cy.get("@toggle").get(".circle").should("be.visible").contains("4");
});

it("opens dropdown showing notifications and delete button enabled", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get('[aria-label="Benachrichtigungen"]').as("toggle");
cy.get("@toggle").click();
cy.get("#notifications-dropdown").as("dropdown").should("exist");
Expand All @@ -97,7 +97,7 @@ describe("Notifications", () => {
});

it("deletes all notifications", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get('[aria-label="Benachrichtigungen"]').as("toggle");
cy.get("@toggle").click();
cy.get("#notifications-dropdown").as("dropdown").should("exist");
Expand All @@ -110,7 +110,7 @@ describe("Notifications", () => {
});

it("delete single notification", () => {
cy.visit("/index.html");
cy.visitPortal("/index.html");
cy.get('[aria-label="Benachrichtigungen"]').as("toggle");
cy.get("@toggle").click();
cy.get("#notifications-dropdown").as("dropdown").should("exist");
Expand Down
Loading

0 comments on commit c6c823e

Please sign in to comment.