added type='button' to both guard portal btns so firefox won't normalize to type='submit'; fixed several FTs for new click-guard functionality on Role card select & room gear menu DEL & BYE btns; several restorations to landscape breakpoint incl. logged-ion display_name, copyright info; provided title to room_scroll.html; a slurry of other minor fixes
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Disco DeDisco
2026-03-23 19:31:57 -04:00
parent eecb6c2be6
commit 5607f70852
15 changed files with 365 additions and 65 deletions

View File

@@ -13,11 +13,15 @@ describe("RoleSelect", () => {
window.fetch = jasmine.createSpy("fetch").and.returnValue(
Promise.resolve({ ok: true })
);
// Default stub: auto-confirm so existing card-click tests pass unchanged.
// The click-guard integration describe overrides this with a capturing spy.
window.showGuard = (_anchor, _msg, onConfirm) => onConfirm && onConfirm();
});
afterEach(() => {
RoleSelect.closeFan();
testDiv.remove();
delete window.showGuard;
});
// ------------------------------------------------------------------ //
@@ -237,4 +241,145 @@ describe("RoleSelect", () => {
expect(document.querySelector(".role-select-backdrop")).toBeNull();
});
});
// ------------------------------------------------------------------ //
// click-guard integration //
// ------------------------------------------------------------------ //
// NOTE: cascade prevention (outside-click on backdrop not closing the //
// fan while the guard is active) relies on the guard portal's capture- //
// phase stopPropagation, which lives in base.html and requires //
// integration testing. The callback contract is fully covered below. //
// ------------------------------------------------------------------ //
describe("click-guard integration", () => {
let guardAnchor, guardMessage, guardConfirm, guardDismiss;
beforeEach(() => {
window.showGuard = jasmine.createSpy("showGuard").and.callFake(
(anchor, message, onConfirm, onDismiss) => {
guardAnchor = anchor;
guardMessage = message;
guardConfirm = onConfirm;
guardDismiss = onDismiss;
}
);
RoleSelect.openFan();
});
describe("clicking a card", () => {
let card;
beforeEach(() => {
card = document.querySelector("#id_role_select .card");
card.click();
});
it("calls window.showGuard", () => {
expect(window.showGuard).toHaveBeenCalled();
});
it("passes the card element as the anchor", () => {
expect(guardAnchor).toBe(card);
});
it("message contains the role name", () => {
const roleName = card.querySelector(".card-role-name").textContent.trim();
expect(guardMessage).toContain(roleName);
});
it("message contains the role code", () => {
expect(guardMessage).toContain(card.dataset.role);
});
it("message contains a <br>", () => {
expect(guardMessage).toContain("<br>");
});
it("does not immediately close the fan", () => {
expect(document.querySelector(".role-select-backdrop")).not.toBeNull();
});
it("does not immediately POST to the select_role URL", () => {
expect(window.fetch).not.toHaveBeenCalled();
});
it("adds .flipped to the card", () => {
expect(card.classList.contains("flipped")).toBe(true);
});
it("adds .guard-active to the card", () => {
expect(card.classList.contains("guard-active")).toBe(true);
});
it("mouseleave does not remove .flipped while guard is active", () => {
card.dispatchEvent(new MouseEvent("mouseleave"));
expect(card.classList.contains("flipped")).toBe(true);
});
});
describe("confirming the guard (OK)", () => {
let card;
beforeEach(() => {
card = document.querySelector("#id_role_select .card");
card.click();
guardConfirm();
});
it("removes .guard-active from the card", () => {
expect(card.classList.contains("guard-active")).toBe(false);
});
it("closes the fan", () => {
expect(document.querySelector(".role-select-backdrop")).toBeNull();
});
it("POSTs to the select_role URL", () => {
expect(window.fetch).toHaveBeenCalledWith(
"/epic/room/test-uuid/select-role",
jasmine.objectContaining({ method: "POST" })
);
});
it("appends a .card to #id_inv_role_card", () => {
expect(document.querySelector("#id_inv_role_card .card")).not.toBeNull();
});
});
describe("dismissing the guard (NVM or outside click)", () => {
let card;
beforeEach(() => {
card = document.querySelector("#id_role_select .card");
card.click();
guardDismiss();
});
it("removes .guard-active from the card", () => {
expect(card.classList.contains("guard-active")).toBe(false);
});
it("removes .flipped from the card", () => {
expect(card.classList.contains("flipped")).toBe(false);
});
it("leaves the fan open", () => {
expect(document.querySelector(".role-select-backdrop")).not.toBeNull();
});
it("does not POST to the select_role URL", () => {
expect(window.fetch).not.toHaveBeenCalled();
});
it("does not add a card to inventory", () => {
expect(document.querySelector("#id_inv_role_card .card")).toBeNull();
});
it("restores normal mouseleave behaviour on the card", () => {
card.dispatchEvent(new MouseEvent("mouseenter"));
card.dispatchEvent(new MouseEvent("mouseleave"));
expect(card.classList.contains("flipped")).toBe(false);
});
});
});
});