sdlc-hub/web/src/modules/jira/issues/modal.test.ts
Andrey Epifancev 8062dc7668 Веб: «Связи» на /app/jira/links, условные пункты меню (#108)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-24 19:41:32 +04:00

33 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from "vitest";
import { BOARD_CARD_STATE, cardState, listBackground, openCardState } from "./modal.ts";
describe("состояние окна в истории", () => {
it("список под прямым адресом карточки берёт проект из её адреса", () => {
expect(listBackground("?project=AWPCA")).toEqual({ pathname: "/jira/issues", search: "?project=AWPCA" });
expect(listBackground("")).toEqual({ pathname: "/jira/issues", search: "" });
});
it("со страницы — фон = адрес страницы, глубина 1", () => {
expect(openCardState({ pathname: "/jira/issues", search: "?sprint=S", state: null }))
.toEqual({ background: { pathname: "/jira/issues", search: "?sprint=S" }, depth: 1, direct: false });
});
it("из окна — тот же фон, глубина + 1, признак прямого адреса сохраняется", () => {
const LIST_BACKGROUND = listBackground("");
const s = { background: LIST_BACKGROUND, depth: 0, direct: true };
expect(openCardState({ pathname: "/jira/issues/A-1", search: "", state: s })).toEqual({ background: LIST_BACKGROUND, depth: 1, direct: true });
expect(openCardState({ pathname: "/jira/issues/A-2", search: "", state: BOARD_CARD_STATE }))
.toEqual({ background: { pathname: "/jira/links", search: "" }, depth: 2, direct: false });
});
it("чужое или битое state — не состояние окна", () => {
expect(cardState(null)).toBeNull();
expect(cardState({ background: "/jira/issues", depth: 1 })).toBeNull();
expect(cardState({ background: { pathname: "/jira/issues", search: "" }, depth: "1" })).toBeNull();
expect(cardState({ background: { pathname: "/jira/issues", search: "" }, depth: 1 }))
.toEqual({ background: { pathname: "/jira/issues", search: "" }, depth: 1, direct: false });
});
it("глубина — только целое неотрицательное, иначе 0", () => {
const bg = { pathname: "/jira/issues", search: "" };
for (const depth of [-1, 1.5, NaN, Infinity]) expect(cardState({ background: bg, depth })?.depth).toBe(0);
expect(cardState({ background: bg, depth: 3 })?.depth).toBe(3);
});
});