import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it } from 'vitest';
import { PreviewModal } from '../../src/components/PreviewModal';
describe('PreviewModal', () => {
it('renders generated previews without same-origin sandbox access', () => {
const markup = renderToStaticMarkup(
window.parent.document.body.innerHTML="owned"',
},
]}
exportTitleFor={() => 'unsafe-preview'}
onClose={() => {}}
/>,
);
expect(markup).toContain('sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox"');
expect(markup).not.toContain('allow-same-origin');
expect(markup).toContain('srcDoc=');
});
it('keeps deck srcdoc handling for deck preview views', () => {
const markup = renderToStaticMarkup(
one',
deck: true,
},
]}
exportTitleFor={() => 'deck-preview'}
onClose={() => {}}
/>,
);
expect(markup).toContain('sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox"');
expect(markup).not.toContain('allow-same-origin');
expect(markup).toContain('od:slide');
});
it('includes popup flags in the sandbox attribute', () => {
const markup = renderToStaticMarkup(
Open Popup',
},
]}
exportTitleFor={() => 'popup-preview'}
onClose={() => {}}
/>,
);
expect(markup).toContain('allow-popups');
expect(markup).toContain('allow-popups-to-escape-sandbox');
});
it('keeps sidebar access on the stage without rendering a header button', () => {
const markup = renderToStaticMarkup(
Preview
' }]}
sidebar={{
label: 'Plugin info',
content: Manifest details
,
}}
exportTitleFor={() => 'plugin-preview'}
onClose={() => {}}
/>,
);
expect(markup).toContain('ds-modal-stage-handle is-expand');
expect(markup).toContain('aria-label="Show Plugin info"');
expect(markup).not.toContain('>Plugin info');
expect(markup).not.toContain('aria-pressed=');
});
});