Files
lincodex/frontend/src/pages/privacy/ui/privacy-page.test.tsx
T

187 lines
6.5 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 { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it, vi } from "vitest";
import type { CardAccess, HiddenOrganization, PrivacyEventList } from "../../../shared/api/schemas";
import { CardAccessHistory, OrganizationVisibility, PrivacyHistory } from "./privacy-page";
const orgA = {
id: "00000000-0000-4000-8000-000000000001",
name: "Компания А",
};
const orgB = {
id: "00000000-0000-4000-8000-000000000002",
name: "Компания Б",
};
function accessRecord(
id: string,
organization: typeof orgA | null,
kind: CardAccess["kind"] = "card_viewed",
): CardAccess {
return {
id,
kind,
occurred_at: "2026-10-01T10:00:00Z",
organization,
};
}
function hiddenOrganization(organization: typeof orgA): HiddenOrganization {
return { organization, hidden_at: "2026-10-02T10:00:00Z" };
}
describe("privacy page sections", () => {
it("shows who read the card and when, within the permitted detail", () => {
const markup = renderToStaticMarkup(
<CardAccessHistory
records={[
accessRecord("00000000-0000-4000-8000-000000000051", orgA, "contact_read"),
accessRecord("00000000-0000-4000-8000-000000000052", null),
]}
hiddenOrganizationIds={new Set([orgA.id])}
isLoading={false}
error={null}
hasMore={false}
isFetching={false}
onLoad={vi.fn()}
/>,
);
expect(markup).toContain("Открыты контактные данные");
expect(markup).toContain("Просмотрена карточка профиля");
expect(markup).toContain("Компания А");
expect(markup).toContain('dateTime="2026-10-01T10:00:00Z"');
expect(markup).toContain("Организация не раскрывается");
expect(markup).toContain("Сейчас профиль скрыт от этой организации");
expect(markup).toContain("Сотрудники, запросы, фильтры и место в выдаче здесь не сохраняются");
expect(markup).toContain("Показана вся история");
});
it("shows an empty access history and an empty settings history", () => {
const access = renderToStaticMarkup(
<CardAccessHistory
records={[]}
isLoading={false}
error={null}
hasMore={false}
isFetching={false}
onLoad={vi.fn()}
/>,
);
const settings = renderToStaticMarkup(
<PrivacyHistory
events={[]}
isLoading={false}
error={null}
hasMore={false}
isFetching={false}
onLoad={vi.fn()}
/>,
);
expect(access).toContain("История доступа пока пуста");
expect(settings).toContain("История настроек пока пуста");
});
it("does not offer hide actions until the hidden list is fully loaded", () => {
const markup = renderToStaticMarkup(
<OrganizationVisibility
accessRecords={[accessRecord("00000000-0000-4000-8000-000000000011", orgA)]}
accessLoading={false}
accessError={null}
accessHasMore={false}
accessFetching={false}
onLoadAccess={vi.fn()}
hiddenOrganizations={[hiddenOrganization(orgB)]}
hiddenLoading={false}
hiddenError={null}
hiddenHasMore
hiddenFetching={false}
onLoadHidden={vi.fn()}
pendingAction={null}
actionError={null}
actionMessage={null}
onHide={vi.fn()}
onUnhide={vi.fn()}
/>,
);
expect(markup).toContain("Компания Б");
expect(markup).toContain("Снова разрешить просмотр");
expect(markup).toContain(
"Список действий появится после загрузки всех страниц скрытых компаний",
);
expect(markup).not.toContain("Скрыть профиль</button>");
expect(markup).toContain("не восстанавливают прежний доступ к контактам");
});
it("shows only organizations from access history as hide candidates", () => {
const markup = renderToStaticMarkup(
<OrganizationVisibility
accessRecords={[
accessRecord("00000000-0000-4000-8000-000000000011", orgA),
accessRecord("00000000-0000-4000-8000-000000000012", orgB),
accessRecord("00000000-0000-4000-8000-000000000013", null),
]}
accessLoading={false}
accessError={null}
accessHasMore
accessFetching={false}
onLoadAccess={vi.fn()}
hiddenOrganizations={[]}
hiddenLoading={false}
hiddenError={null}
hiddenHasMore={false}
hiddenFetching={false}
onLoadHidden={vi.fn()}
pendingAction={null}
actionError={null}
actionMessage={null}
onHide={vi.fn()}
onUnhide={vi.fn()}
/>,
);
expect(markup).toContain("Компания А");
expect(markup).toContain("Компания Б");
expect(markup).toContain("Скрыть профиль");
expect(markup).toContain("Загрузить ранние записи");
expect(markup).toContain("новое приглашение и новое согласие C4");
});
it("does not describe a partial history page as the complete history", () => {
const event: PrivacyEventList["items"][number] = {
id: "00000000-0000-4000-8000-000000000021",
kind: "publication_opened",
occurred_at: "2026-10-04T10:00:00Z",
fields: ["categories"],
consent_id: "00000000-0000-4000-8000-000000000031",
organization: null,
};
const privacyMarkup = renderToStaticMarkup(
<PrivacyHistory
events={[event]}
isLoading={false}
error={null}
hasMore
isFetching={false}
onLoad={vi.fn()}
/>,
);
const accessMarkup = renderToStaticMarkup(
<CardAccessHistory
records={[accessRecord("00000000-0000-4000-8000-000000000041", orgA)]}
isLoading={false}
error={null}
hasMore
isFetching={false}
onLoad={vi.fn()}
/>,
);
expect(privacyMarkup).toContain("Показана только загруженная часть истории");
expect(privacyMarkup).not.toContain("Показана вся история");
expect(accessMarkup).toContain("Показана только загруженная часть истории");
expect(accessMarkup).not.toContain("Показана вся история");
});
});