83 lines
2.5 KiB
JavaScript
83 lines
2.5 KiB
JavaScript
// The Lucia project.
|
|
// Copyright 2026-2026 DSP, inc. All rights reserved.
|
|
// Authors:
|
|
// imacat.yang@dsp.im (imacat), 2026/03/05
|
|
|
|
import { setupApiIntercepts } from "../support/intercept";
|
|
|
|
describe("Login Flow", () => {
|
|
beforeEach(() => {
|
|
setupApiIntercepts();
|
|
});
|
|
|
|
it("renders the login form", () => {
|
|
cy.visit("/login");
|
|
cy.get("h2").should("contain", "LOGIN");
|
|
cy.get("#account").should("exist");
|
|
cy.get("#password").should("exist");
|
|
cy.get("#login_btn_main_btn").should("be.disabled");
|
|
});
|
|
|
|
it("login button is disabled when fields are empty", () => {
|
|
cy.visit("/login");
|
|
cy.get("#login_btn_main_btn").should("be.disabled");
|
|
|
|
// Only username filled — still disabled
|
|
cy.get("#account").type("testuser");
|
|
cy.get("#login_btn_main_btn").should("be.disabled");
|
|
});
|
|
|
|
it("login button enables when both fields are filled", () => {
|
|
cy.visit("/login");
|
|
cy.get("#account").type("testadmin");
|
|
cy.get("#password").type("password123");
|
|
cy.get("#login_btn_main_btn").should("not.be.disabled");
|
|
});
|
|
|
|
it("successful login redirects to /files", () => {
|
|
cy.visit("/login");
|
|
cy.get("#account").type("testadmin");
|
|
cy.get("#password").type("password123");
|
|
cy.get("#login_btn_main_btn").click();
|
|
|
|
cy.url().should("include", "/files");
|
|
});
|
|
|
|
it("failed login shows error message", () => {
|
|
// Visit login first to load app + MSW
|
|
cy.visit("/login");
|
|
cy.get("#login_btn_main_btn").should("exist");
|
|
// Override the token endpoint to return 401 via MSW
|
|
cy.window().then((win) => {
|
|
const { http, HttpResponse } = win.__msw__;
|
|
win.__mswWorker__.use(
|
|
http.post("/api/oauth/token", () =>
|
|
HttpResponse.json(
|
|
{ detail: "Incorrect username or password" },
|
|
{ status: 401 },
|
|
)),
|
|
);
|
|
});
|
|
|
|
cy.get("#account").type("wronguser");
|
|
cy.get("#password").type("wrongpass");
|
|
cy.get("#login_btn_main_btn").click();
|
|
|
|
cy.contains("Incorrect account or password").should("be.visible");
|
|
});
|
|
|
|
it("toggles password visibility", () => {
|
|
cy.visit("/login");
|
|
cy.get("#password").type("secret123");
|
|
cy.get("#password").should("have.attr", "type", "password");
|
|
|
|
// Click the eye icon to show password
|
|
cy.get('label[for="passwordt"] span.cursor-pointer').click();
|
|
cy.get("#password").should("have.attr", "type", "text");
|
|
|
|
// Click again to hide
|
|
cy.get('label[for="passwordt"] span.cursor-pointer').click();
|
|
cy.get("#password").should("have.attr", "type", "password");
|
|
});
|
|
});
|