feat(cv): qualify templates and reliable local import processing
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import { render, waitFor } from "@testing-library/react";
|
||||
|
||||
import CvTemplateThumbnail from "./components/CvTemplateThumbnail";
|
||||
import { CvTheme } from "./cvBuilder";
|
||||
import { cvBuilderApi, CvTheme } from "./cvBuilder";
|
||||
import { I18nProvider } from "./i18n/I18nProvider";
|
||||
|
||||
const theme = (id: string, layout: CvTheme["layout"], swatches: string[]): CvTheme => ({
|
||||
id,
|
||||
@@ -19,13 +20,20 @@ const theme = (id: string, layout: CvTheme["layout"], swatches: string[]): CvThe
|
||||
swatches,
|
||||
});
|
||||
|
||||
test("template thumbnails stay distinct and never replace themselves with sandboxed frames", () => {
|
||||
const minimal = render(<CvTemplateThumbnail theme={theme("minimal", "single", ["#111827", "#ffffff", "#ffffff"])} />);
|
||||
const minimalMarkup = minimal.container.innerHTML;
|
||||
test("template thumbnails retain distinct server-rendered samples in noninteractive sandboxed frames", async () => {
|
||||
const preview = jest.spyOn(cvBuilderApi, "themePreview").mockImplementation(async id => ({ html: `<html><body>${id} synthetic sample</body></html>` } as any));
|
||||
const minimal = render(<I18nProvider><CvTemplateThumbnail theme={theme("minimal", "single", ["#111827", "#ffffff", "#ffffff"])} /></I18nProvider>);
|
||||
await waitFor(() => expect(minimal.container.querySelector("iframe")?.srcdoc).toContain("minimal synthetic sample"));
|
||||
const minimalMarkup = minimal.container.querySelector("iframe")!.srcdoc;
|
||||
minimal.unmount();
|
||||
|
||||
const nordic = render(<CvTemplateThumbnail theme={theme("nordic", "sidebar-right", ["#3b6ea5", "#eef3f8", "#ffffff"])} />);
|
||||
const nordic = render(<I18nProvider><CvTemplateThumbnail theme={theme("nordic", "sidebar-right", ["#3b6ea5", "#eef3f8", "#ffffff"])} /></I18nProvider>);
|
||||
|
||||
expect(nordic.container.querySelector("iframe")).toBeNull();
|
||||
expect(nordic.container.innerHTML).not.toBe(minimalMarkup);
|
||||
await waitFor(() => expect(nordic.container.querySelector("iframe")?.srcdoc).toContain("nordic synthetic sample"));
|
||||
const frame = nordic.container.querySelector("iframe")!;
|
||||
expect(frame.getAttribute("sandbox")).toBe("");
|
||||
expect(frame.tabIndex).toBe(-1);
|
||||
expect(frame.srcdoc).not.toBe(minimalMarkup);
|
||||
expect(preview.mock.calls.map(([id]) => id)).toEqual(["minimal", "nordic"]);
|
||||
preview.mockRestore();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user