sdlc-hub/web/src/modules/wiki/feed/group.test.ts
Andrey Epifancev 93eff7eac0 Веб: правки вики в общей ленте (#140)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 13:04:40 +04:00

25 lines
1.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 type { WikiChange } from "../api/queries.ts";
import { authorName, deltaText, groupByPage } from "./group.ts";
const c = (page_code: string, version: string): WikiChange => ({
at: "2026-10-28T09:00:00+00:00", page_code, title: page_code, path: null, version,
author: { login: null, name: null }, added: 1, removed: 0,
});
describe("группировка правок вики", () => {
it("по странице, по первому появлению; правки — в порядке ответа", () => {
const g = groupByPage([c("DOC-3", "V3"), c("DOC-2", "V2"), c("DOC-3", "V1")]);
expect(g.map((x) => x.code)).toEqual(["DOC-3", "DOC-2"]);
expect(g[0].changes.map((x) => x.version)).toEqual(["V3", "V1"]);
});
it("deltaText: плюс, косая черта, минус U+2212", () => {
expect(deltaText({ added: 40, removed: 12 })).toBe("+40 / −12");
});
it("authorName: имя, иначе логин, иначе «—»", () => {
expect(authorName({ login: "x", name: null })).toBe("x");
expect(authorName({ login: "x", name: "Икс" })).toBe("Икс");
expect(authorName({ login: null, name: null })).toBe("—");
});
});