fix: bound rich page rendering

This commit is contained in:
2026-07-22 20:05:39 +02:00
parent f14d5dd68d
commit 54740cd554
4 changed files with 500 additions and 41 deletions

View File

@@ -100,7 +100,7 @@ describe('PageReader structured content', () => {
});
it('renders semantic formatting, links, tables, and a signed image resource', async () => {
const loadResource = vi.fn(async () => ({
const previewResource = vi.fn(async () => ({
id: 'resource-image',
kind: 'image' as const,
mediaType: 'image/png',
@@ -110,10 +110,14 @@ describe('PageReader structured content', () => {
}));
render(
<PageReader page={page} loading={false} loadResource={loadResource} />
<PageReader
page={page}
loading={false}
previewResource={previewResource}
/>
);
expect(screen.getByText('Styled').parentElement).toHaveStyle({
expect(screen.getByText('Styled')).toHaveStyle({
fontWeight: '700',
});
expect(screen.getByRole('link', { name: 'link' })).toHaveAttribute(
@@ -145,7 +149,7 @@ describe('PageReader structured content', () => {
<PageReader
page={page}
loading={false}
loadResource={async () => {
previewResource={async () => {
throw new Error('not renderable');
}}
downloadResource={downloadResource}
@@ -157,6 +161,53 @@ describe('PageReader structured content', () => {
);
expect(downloadResource).toHaveBeenCalledWith('resource-file', 'notes.txt');
});
it('does not turn a rejected image preview into an implicit download', async () => {
const previewResource = vi.fn(async () => {
throw new Error(
'This image can be downloaded but is not approved for automatic preview.'
);
});
const downloadResource = vi.fn(async () => undefined);
render(
<PageReader
page={page}
loading={false}
previewResource={previewResource}
downloadResource={downloadResource}
/>
);
expect(
await screen.findByText(/not approved for automatic preview/i)
).toBeVisible();
expect(previewResource).toHaveBeenCalledWith('resource-image');
expect(downloadResource).not.toHaveBeenCalled();
await userEvent.click(
screen.getByRole('button', { name: 'Download original image' })
);
expect(downloadResource).toHaveBeenCalledWith('resource-image', undefined);
});
it('shows an explicit notice when the display projection is truncated', () => {
render(
<PageReader
page={{
...page,
blocks: [textBlock('First', 'first'), textBlock('Second', 'second')],
}}
loading={false}
renderLimits={{ maxBlocks: 1 }}
/>
);
expect(screen.getByText('First')).toBeInTheDocument();
expect(screen.queryByText('Second')).not.toBeInTheDocument();
expect(screen.getByRole('status')).toHaveTextContent(
'safe browser display budget'
);
});
});
function textBlock(text: string, id: string) {