test: Cover grouped text preview clamp

This commit is contained in:
Danny Avila 2026-05-14 00:04:20 -04:00
parent d0f6881544
commit 2e34c7ec2f

View file

@ -222,4 +222,40 @@ describe('AttachmentGroup', () => {
expect(container.querySelector('pre')?.textContent).toBe('{"ok":true}');
expect(screen.getByTestId('file-container')).toHaveTextContent('output.json');
});
it('keeps long grouped text previews clamped until the nested preview is expanded', () => {
setScrollHeight(800);
const longJson = Array.from({ length: 1000 }, (_, index) => `{"line":${index}}`).join('\n');
const attachments = [
textAttachment({
file_id: 'archive',
filename: 'archive.zip',
type: 'application/zip',
text: undefined as unknown as string,
}),
textAttachment({
file_id: 'json',
filename: 'output.json',
filepath: '/files/output.json',
text: longJson,
}),
] as TAttachment[];
const { container } = render(<AttachmentGroup attachments={attachments} />);
const groupToggle = screen.getByRole('button', { name: 'com_ui_show_n_files' });
fireEvent.click(groupToggle);
expect(screen.getByText('output.json')).toBeInTheDocument();
const pre = container.querySelector('pre');
expect(pre).not.toBeNull();
expect(pre).toHaveStyle({ maxHeight: '320px' });
const previewToggle = screen.getByRole('button', { name: 'Show all' });
expect(previewToggle).toHaveAttribute('aria-expanded', 'false');
fireEvent.click(previewToggle);
expect(screen.getByRole('button', { name: 'Collapse' })).toHaveAttribute(
'aria-expanded',
'true',
);
});
});