freetravel/test/filters.test.ts
Peppa adcb85595a
All checks were successful
deploy / deploy (pull_request) Successful in 10s
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 2с
peppa/test test: success за 1с
peppa/build build: success за 2с
ci / checks (pull_request) Successful in 31s
FRTVL-17: понятные строки про ручной и ежедневный поиск
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 17:13:26 +05:00

72 lines
3.7 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, isExample, 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("Нет действующего кода привязки");
});
});
describe("Requirement: Примеры помечены", () => {
it("Scenario: пример — источник на example.org, настоящая — нет", () => {
expect(isExample({ sourceUrl: "https://example.org/mock/a" })).toBe(true);
expect(isExample({ sourceUrl: "https://hotel.com/jobs" })).toBe(false);
expect(isExample({ sourceUrl: "не адрес" })).toBe(false);
});
});
describe("Requirement: Бот не настроен (FRTVL-13)", () => {
it("Scenario: настоящий режим без имени бота — понятная подсказка", () => {
expect(telegramState({ linked: false, telegram: "telegram", botUsername: "" }).note).toContain("Бот не настроен");
expect(telegramState({ linked: false, telegram: "telegram", botUsername: "nternships_bot" }).note).toContain("Привязать Телеграм");
});
});