import { expect, test } from "@playwright/test"; test("saved spot appears on the plan page and can be removed or cleared", async ({ page }) => { await page.goto("/spots/vyunok-6331x6332"); await page.evaluate(() => localStorage.setItem("rf4spotter:fishing-plan", JSON.stringify([{ key: "/spots/vyunok-6331x6332", waterbody: "Вьюнок", coordinates: "6331:6332", baits: "Тестовая приманка", method: "Спиннинг", retrieve: "равномерная", risk: "Подтверждено", freshness: "2026-09-20T12:55:11.236309Z", confidence: "24" }]))); await page.goto("/plan"); await expect(page.getByRole("heading", { name: "Вьюнок" })).toBeVisible(); await expect(page.getByText("6331:6332")).toBeVisible(); await expect(page.getByText("Спиннинг · равномерная")).toBeVisible(); await expect(page.getByText(/Риск: Подтверждено/)).toBeVisible(); await expect(page.getByText("1 из 5 точек")).toBeVisible(); await page.getByRole("button", { name: "Убрать" }).click(); await expect(page.getByRole("heading", { name: "План пока пуст" })).toBeVisible(); await page.goto("/spots/vyunok-6331x6332"); await page.evaluate(() => localStorage.setItem("rf4spotter:fishing-plan", JSON.stringify([{ key: "/spots/vyunok-6331x6332", waterbody: "Вьюнок", coordinates: "6331:6332", baits: "Тестовая приманка", freshness: "", confidence: "" }]))); await page.goto("/plan"); await page.getByRole("button", { name: "Очистить план" }).click(); await expect(page.getByRole("heading", { name: "План пока пуст" })).toBeVisible(); }); test("plan can be restored from a shareable URL", async ({ page }) => { const shared = encodeURIComponent(JSON.stringify([{ key: "/spots/vyunok-6331x6332", waterbody: "Вьюнок", coordinates: "6331:6332", baits: "Тестовая приманка", freshness: "", confidence: "" }])); await page.goto(`/plan?plan=${shared}`); await expect(page.getByRole("heading", { name: "Вьюнок" })).toBeVisible(); await expect(page.getByRole("button", { name: "Поделиться планом" })).toBeVisible(); await expect(page.getByText("1 из 5 точек")).toBeVisible(); }); test("plan caps imported entries, stays printable and fits narrow viewports", async ({ page }) => { const plan = Array.from({ length: 6 }, (_, index) => ({ key: `/spots/vyunok-6331x633${index + 2}`, waterbody: "Вьюнок", coordinates: `6331:633${index + 2}`, baits: "Тестовая приманка", freshness: "", confidence: "", })); await page.goto("/plan"); await page.evaluate((value) => localStorage.setItem("rf4spotter:fishing-plan", JSON.stringify(value)), plan); await page.reload(); await expect(page.getByText("5 из 5 точек")).toBeVisible(); await expect(page.locator(".plan-card")).toHaveCount(5); for (const width of [320, 390]) { await page.setViewportSize({ width, height: 800 }); const overflow = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth); expect(overflow, `${width}px plan overflows`).toBeLessThanOrEqual(0); } await page.emulateMedia({ media: "print" }); await expect(page.getByRole("button", { name: "Печать / PDF" })).toBeHidden(); await expect(page.locator(".plan-card")).toHaveCount(5); }); test("plan preserves a real zero confidence and bounds imported text", async ({ page }) => { await page.goto("/plan"); await page.evaluate(() => localStorage.setItem("rf4spotter:fishing-plan", JSON.stringify([{ key: "/spots/" + "x".repeat(600), waterbody: "Вьюнок", coordinates: "6331:6332", baits: "Приманка", confidence: "0", risk: "Малая выборка", method: "Спиннинг", retrieve: "равномерная", oversized: "x".repeat(5000), }, { key: "/spots/vyunok-7450x7451", waterbody: "Вьюнок", coordinates: "7450:7451", confidence: "999", }]))); await page.reload(); await expect(page.getByText(/Доверие: 0%/)).toBeVisible(); const stored = await page.evaluate(() => JSON.parse(localStorage.getItem("rf4spotter:fishing-plan") || "[]")); expect(stored[0].key.length).toBeLessThanOrEqual(512); expect(stored[0].confidence).toBe("0"); expect(stored[1].confidence).toBe(""); expect(stored[0].oversized).toBeUndefined(); }); test("plan import deduplicates the same point before applying the five-item cap", async ({ page }) => { await page.goto("/plan"); await page.evaluate(() => localStorage.setItem("rf4spotter:fishing-plan", JSON.stringify([ { key: "/spots/vyunok-6331x6332", waterbody: "Вьюнок", coordinates: "6331:6332", confidence: "0" }, { key: "/spots/vyunok-6331x6332", waterbody: "Вьюнок", coordinates: "6331:6332", confidence: "80" }, { key: "/spots/vyunok-7450x7451", waterbody: "Вьюнок", coordinates: "7450:7451", confidence: "40" }, ]))); await page.reload(); await expect(page.getByText("2 из 5 точек")).toBeVisible(); await expect(page.locator(".plan-card")).toHaveCount(2); const stored = await page.evaluate(() => JSON.parse(localStorage.getItem("rf4spotter:fishing-plan") || "[]")); expect(stored.map((item: { key: string }) => item.key)).toEqual([ "/spots/vyunok-6331x6332", "/spots/vyunok-7450x7451", ]); }); test("plan explains empty and malformed share states", async ({ page }) => { await page.goto("/plan"); await page.getByRole("button", { name: "Поделиться планом" }).click(); await expect(page.locator("[data-plan-share-status]")).toHaveText("Сначала добавьте точку в план"); await page.goto("/plan?plan=not-json"); await expect(page.locator("[data-plan-share-status]")).toHaveText("Ссылка плана не распознана"); const emptyPlan = encodeURIComponent(JSON.stringify([])); await page.goto(`/plan?plan=${emptyPlan}`); await expect(page.locator("[data-plan-share-status]")).toHaveText("В ссылке нет сохранённых точек"); });