20 lines
1.1 KiB
TypeScript
20 lines
1.1 KiB
TypeScript
import React from 'react';
|
|
import '@testing-library/jest-dom';
|
|
import { render, screen } from '@testing-library/react';
|
|
import CvTemplateThumbnail from './components/CvTemplateThumbnail';
|
|
import { cvBuilderApi, CvTheme } from './cvBuilder';
|
|
import { I18nProvider } from './i18n/I18nProvider';
|
|
|
|
test('template cards use the server-rendered sample in a sandboxed noninteractive preview', async () => {
|
|
const theme = { id: 'preview-test', name: 'Preview test', layout: 'single', swatches: [] } as unknown as CvTheme;
|
|
const request = jest.spyOn(cvBuilderApi, 'themePreview').mockResolvedValue({ themeId: theme.id, html: '<html><body><h1>Rendered sample</h1></body></html>', suggestedFileName: 'sample.pdf' });
|
|
try {
|
|
render(<I18nProvider><CvTemplateThumbnail theme={theme} /></I18nProvider>);
|
|
const iframe = await screen.findByTitle('Template sample preview');
|
|
expect(iframe).toHaveAttribute('srcdoc', expect.stringContaining('Rendered sample'));
|
|
expect(iframe).toHaveAttribute('sandbox', '');
|
|
expect(iframe).toHaveAttribute('tabindex', '-1');
|
|
expect(request).toHaveBeenCalledWith(theme.id);
|
|
} finally { request.mockRestore(); }
|
|
});
|