// PEP-160: the main «Создать проект» / «Создать задачу» buttons, their forms and where the user // lands after creating a task (openspec/specs/create-entry-points). import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { describe, test } from "node:test"; import { translator } from "@peppa/shared/i18n"; import { wording } from "@peppa/shared/wording"; // Loaded by URL: a static import would pull Next's global types into this package. const web = (path: string) => new URL(`../../../apps/web/${path}`, import.meta.url); const { boardAfterCreate } = (await import(web("lib/created.ts").href)) as { boardAfterCreate: (projectKey: string, taskKey: string, taskEpicId?: number | null, filterEpicId?: number | null) => string }; const source = (path: string) => readFileSync(web(path), "utf8"); describe("PEP-160: подтверждение и созданная запись на экране", () => { test("Scenario: Задача создана в выбранном эпике — доска с тем же фильтром и новой карточкой", () => { assert.equal(boardAfterCreate("SBS", "SBS-7", 3, 3), "/p/SBS?added=SBS-7&epic=3"); }); test("Scenario: Задача создана в другом эпике, чем фильтр, — фильтр снят", () => { assert.equal(boardAfterCreate("SBS", "SBS-8", undefined, 3), "/p/SBS?added=SBS-8"); assert.equal(boardAfterCreate("SBS", "SBS-9", 4, 3), "/p/SBS?added=SBS-9"); }); test("Доска без фильтра остаётся без фильтра", () => { assert.equal(boardAfterCreate("SBS", "SBS-10", 4, undefined), "/p/SBS?added=SBS-10"); assert.equal(boardAfterCreate("SBS", "SBS-11"), "/p/SBS?added=SBS-11"); }); }); describe("PEP-160: основные кнопки", () => { test("Scenario: У пользователя уже есть проекты — «Создать проект» в заголовке Главной и «Проектов»", () => { for (const page of ["app/(app)/page.tsx", "app/(app)/projects/page.tsx"]) { const header = source(page).split("")[0]!; assert.match(header, /actions=\{[\s\S]*variant="default"[\s\S]*href="\/projects\/new"[\s\S]*t\("Создать проект"\)/, page); } }); test("Scenario: Проектов ещё нет — кнопка и в пустом списке", () => { const empty = source("components/cards.tsx").split("if (!projects.length)")[1]!.split("")[0]!; assert.match(empty, /