127 lines
4.3 KiB
JavaScript
127 lines
4.3 KiB
JavaScript
// The Lucia project.
|
|
// Copyright 2026-2026 DSP, inc. All rights reserved.
|
|
// Authors:
|
|
// imacat.yang@dsp.im (imacat), 2026/03/05
|
|
|
|
import { loginWithFixtures } from "../support/intercept";
|
|
|
|
describe("Edge Cases", () => {
|
|
describe("Empty states", () => {
|
|
it("files page handles empty file list", () => {
|
|
loginWithFixtures();
|
|
// Visit any page first to load the app and MSW
|
|
cy.visit("/files");
|
|
cy.contains("sample-process.xes").should("exist");
|
|
// Override files endpoint with empty array via MSW
|
|
cy.window().then((win) => {
|
|
const { http, HttpResponse } = win.__msw__;
|
|
win.__mswWorker__.use(
|
|
http.get("/api/files", () => HttpResponse.json([])),
|
|
);
|
|
});
|
|
// Revisit to trigger the new empty response
|
|
cy.visit("/files");
|
|
// Table should exist but have no file data
|
|
cy.get("table").should("exist");
|
|
cy.contains("sample-process.xes").should("not.exist");
|
|
});
|
|
|
|
it("account admin handles empty user list", () => {
|
|
loginWithFixtures();
|
|
cy.visit("/files");
|
|
cy.contains("sample-process.xes").should("exist");
|
|
// Override users endpoint with empty array via MSW
|
|
cy.window().then((win) => {
|
|
const { http, HttpResponse } = win.__msw__;
|
|
win.__mswWorker__.use(
|
|
http.get("/api/users", () => HttpResponse.json([])),
|
|
);
|
|
});
|
|
cy.visit("/account-admin");
|
|
// Create New button should exist even with no users
|
|
cy.get("#create_new_acct_btn").should("exist");
|
|
cy.contains("Test Admin").should("not.exist");
|
|
});
|
|
|
|
it("unauthenticated user is redirected to login", () => {
|
|
loginWithFixtures();
|
|
cy.visit("/files");
|
|
cy.contains("sample-process.xes").should("exist");
|
|
// Override my-account to return 401
|
|
cy.window().then((win) => {
|
|
const { http, HttpResponse } = win.__msw__;
|
|
win.__mswWorker__.use(
|
|
http.get("/api/my-account", () =>
|
|
new HttpResponse(null, { status: 401 }),
|
|
),
|
|
);
|
|
});
|
|
// Clear cookies to simulate logged out
|
|
cy.clearCookies();
|
|
cy.visit("/files");
|
|
cy.url().should("include", "/login");
|
|
});
|
|
|
|
it("unauthenticated user cannot access account-admin", () => {
|
|
cy.visit("/account-admin");
|
|
cy.url().should("include", "/login");
|
|
});
|
|
|
|
it("unauthenticated user cannot access my-account", () => {
|
|
cy.visit("/my-account");
|
|
cy.url().should("include", "/login");
|
|
});
|
|
});
|
|
|
|
describe("Login validation", () => {
|
|
it("shows error on failed login", () => {
|
|
// Visit login page first to load the app
|
|
cy.visit("/login");
|
|
cy.get("#login_btn_main_btn").should("exist");
|
|
// Override token endpoint to return 401
|
|
cy.window().then((win) => {
|
|
const { http, HttpResponse } = win.__msw__;
|
|
win.__mswWorker__.use(
|
|
http.post("/api/oauth/token", () =>
|
|
HttpResponse.json(
|
|
{ detail: "Invalid credentials" },
|
|
{ status: 401 },
|
|
),
|
|
),
|
|
);
|
|
});
|
|
cy.get("#account").type("wronguser");
|
|
cy.get("#password").type("wrongpass");
|
|
cy.get("#login_btn_main_btn").click();
|
|
cy.url().should("include", "/login");
|
|
});
|
|
|
|
it("confirm stays disabled with only account field filled", () => {
|
|
loginWithFixtures();
|
|
cy.visit("/account-admin");
|
|
cy.contains("Test Admin").should("exist");
|
|
cy.contains("button", "Create New").click();
|
|
cy.get("#input_account_field").type("onlyaccount");
|
|
cy.contains("button", "Confirm").should("be.disabled");
|
|
});
|
|
|
|
it("confirm stays disabled with only name field filled", () => {
|
|
loginWithFixtures();
|
|
cy.visit("/account-admin");
|
|
cy.contains("Test Admin").should("exist");
|
|
cy.contains("button", "Create New").click();
|
|
cy.get("#input_name_field").type("onlyname");
|
|
cy.contains("button", "Confirm").should("be.disabled");
|
|
});
|
|
|
|
it("confirm stays disabled with only password field filled", () => {
|
|
loginWithFixtures();
|
|
cy.visit("/account-admin");
|
|
cy.contains("Test Admin").should("exist");
|
|
cy.contains("button", "Create New").click();
|
|
cy.get("#input_first_pwd").type("onlypassword");
|
|
cy.contains("button", "Confirm").should("be.disabled");
|
|
});
|
|
});
|
|
});
|