freetravel/test/filters.test.ts
Peppa 29341cdff1
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 3с
peppa/test test: success за 1с
peppa/build build: success за 2с
ci / checks (pull_request) Successful in 22s
deploy / deploy (pull_request) Successful in 13s
FRTVL-8: понятное состояние Телеграма, кнопки по шагам
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 23:13:40 +05:00

57 lines
2.8 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 { applyFilters, countriesOf, emptyMessage, runSummary } from "../public/filters.js";
const cards = [
{ country: "Швейцария", language: "russian" },
{ country: "Турция", language: "russian" },
];
describe("Requirement: Фильтры", () => {
it("Scenario: Фильтр по стране", () => {
expect(applyFilters(cards, { country: "Турция" })).toEqual([{ country: "Турция", language: "russian" }]);
});
it("Scenario: Фильтр без совпадений", () => {
const shown = applyFilters(cards, { language: "not_required" });
expect(shown).toEqual([]);
expect(emptyMessage(cards.length, shown.length)).toBe("Нет стажировок под выбранные фильтры");
});
it("без фильтров показывает всё, страны — по алфавиту", () => {
expect(applyFilters(cards, {})).toHaveLength(2);
expect(countriesOf(cards)).toEqual(["Турция", "Швейцария"]);
});
});
describe("Requirement: Список стажировок", () => {
it("Scenario: Пустой каталог", () => {
expect(emptyMessage(0, 0)).toBe("Пока ничего не найдено — нажмите «Найти новые»");
});
});
describe("Requirement: Запуск поиска со страницы — отчёт", () => {
it("показывает итог запуска и ошибку", () => {
expect(runSummary({ status: "ok", found: 3, added: 2, rejected: 1 })).toBe("найдено: 3, новых: 2, отброшено: 1");
expect(runSummary({ status: "error", found: 0, added: 0, rejected: 0, error: "нет сети" })).toBe(
"Поиск завершился ошибкой: нет сети",
);
expect(runSummary(null)).toBe("Поиск ещё не запускался");
});
});
import { settingsErrorMessage, telegramState } from "../public/filters.js";
describe("Requirement: Состояние Телеграма (FRTVL-8)", () => {
it("Scenario: три шага привязки", () => {
expect(telegramState({ linked: false }).step).toBe("unlinked");
expect(telegramState({ linked: false, linkUrl: "https://t.me/x" }).step).toBe("pending");
expect(telegramState({ linked: true }).status).toBe("Телеграм привязан");
});
it("Scenario: ошибки простыми словами", () => {
expect(settingsErrorMessage(401, undefined)).toContain("Неверный код доступа");
expect(settingsErrorMessage(500, "boom")).not.toContain("boom");
expect(settingsErrorMessage(409, "Нет действующего кода привязки")).toContain("Нет действующего кода привязки");
});
});