// SourceList and SourceCard — the getting-started target (#398). No jsdom: // react-dom/server renders in vitest's node environment, and the markup says // which card carries the highlight. import { describe, it, expect, vi } from "vitest"; import { renderToStaticMarkup } from "react-dom/server"; vi.mock("react-i18next", async () => (await import("../../test/i18nMock")).i18nMock()); import SourceList from "./SourceList"; import { SOURCE_CARD_TARGET } from "./SourceCard"; import type { ScannedSource } from "../../shared/types"; const HIGHLIGHT = 'data-onboarding-highlight="true"'; const source = (name: string): ScannedSource => ({ folder_name: name, folder_path: `/releves/${name}`, files: [{ filename: "releve.csv", file_path: `/releves/${name}/releve.csv`, size_bytes: 10, modified_at: "" }], }); const SOURCES = [source("Desjardins"), source("Tangerine"), source("RBC")]; const markup = (onboardingTarget?: boolean, sources: ScannedSource[] = SOURCES) => renderToStaticMarkup( , ); /** The source cards, in order: each is a button. */ const cards = (html: string) => html.split(" { it("highlights the first card of the list, and only it", () => { const html = markup(true); expect(html.split(HIGHLIGHT).length - 1).toBe(1); const [first, ...others] = cards(html); expect(first).toContain(HIGHLIGHT); expect(first).toContain(`data-onboarding-target="${SOURCE_CARD_TARGET}"`); expect(first).toContain("Desjardins"); expect(others).toHaveLength(2); for (const card of others) expect(card).not.toContain("data-onboarding"); }); it("highlights the only card of a one-source list", () => { expect(markup(true, [source("Desjardins")]).split(HIGHLIGHT).length - 1).toBe(1); }); it("highlights nothing without the property", () => { expect(markup()).not.toContain("data-onboarding"); expect(markup(false)).not.toContain("data-onboarding"); }); }); describe("SourceList and SourceCard — displayed texts (#389)", () => { it("titles the list and counts each source's files through t", () => { const html = markup(); expect(html).toContain(">t(import.sources.title)<"); expect(cards(html)[0]).toContain("t(import.sources.fileCount[count=1])"); }); it("marks the files not yet imported through t", () => { const html = renderToStaticMarkup( ()]])} onSelectSource={vi.fn()} />, ); expect(html).toContain("t(import.sources.new)"); }); it("says the folder is empty through t", () => { expect(markup(false, [])).toContain(">t(import.sources.empty)<"); }); });