Files
lucia-frontend/cypress/e2e/accountCrud.cy.js
2026-03-08 12:11:57 +08:00

97 lines
3.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("Account Management CRUD", () => {
beforeEach(() => {
loginWithFixtures();
cy.visit("/account-admin");
cy.wait("@getUsers");
});
it("shows Create New button", () => {
cy.get("#create_new_acct_btn").should("exist");
cy.get("#create_new_acct_btn").should("contain", "Create New");
});
it("opens create new account modal", () => {
cy.get("#create_new_acct_btn").click();
cy.get("#modal_container").should("be.visible");
cy.get("#modal_account_edit_or_create_new").should("be.visible");
// Should show account, name, password fields
cy.get("#input_account_field").should("exist");
cy.get("#input_name_field").should("exist");
cy.get("#input_first_pwd").should("exist");
});
it("create account confirm is disabled when fields are empty", () => {
cy.get("#create_new_acct_btn").click();
cy.get(".confirm-btn").should("be.disabled");
});
it("create account confirm enables when fields are filled", () => {
cy.get("#create_new_acct_btn").click();
cy.get("#input_account_field").type("newuser");
cy.get("#input_name_field").type("New User");
cy.get("#input_first_pwd").type("password1234");
cy.get(".confirm-btn").should("not.be.disabled");
});
it("cancel button closes the modal", () => {
cy.get("#create_new_acct_btn").click();
cy.get("#modal_container").should("be.visible");
cy.get(".cancel-btn").click();
cy.get("#modal_container").should("not.exist");
});
it("close (X) button closes the modal", () => {
cy.get("#create_new_acct_btn").click();
cy.get("#modal_container").should("be.visible");
cy.get('img[alt="X"]').click();
cy.get("#modal_container").should("not.exist");
});
it("double-click username opens account info modal", () => {
// Double-click on the first account username
cy.get(".account-cell").first().dblclick();
cy.get("#modal_container").should("be.visible");
});
it("delete button opens delete confirmation modal", () => {
// Click the delete icon for a non-current user
cy.get(".delete-account").first().click();
cy.get("#modal_container").should("be.visible");
cy.get("#modal_delete_acct_alert").should("be.visible");
});
it("delete modal has Yes and No buttons", () => {
cy.get(".delete-account").first().click();
cy.get("#calcel_delete_acct_btn").should("exist");
cy.get("#sure_to_delete_acct_btn").should("exist");
});
it("delete modal No button closes the modal", () => {
cy.get(".delete-account").first().click();
cy.get("#calcel_delete_acct_btn").click();
cy.get("#modal_container").should("not.exist");
});
it("shows checkboxes for Set as Admin and Activate in create modal", () => {
cy.get("#create_new_acct_btn").click();
cy.get("#account_create_checkboxes_section").should("be.visible");
cy.contains("Set as admin.").should("exist");
cy.contains("Activate now.").should("exist");
});
it("search bar filters user list", () => {
// Search filters by username, not display name
cy.get("#input_search").type("user1");
cy.get('img[alt="search"]').click();
// Should only show user1 (Alice Wang)
cy.contains("user1").should("exist");
});
});