Skip to content

Commit a07e291

Browse files
committed
add clipboardcopy truncate integration test
Signed-off-by: gitdallas <5322142+gitdallas@users.noreply.github.com>
1 parent eb0989d commit a07e291

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { render, screen } from '@testing-library/react';
2+
import userEvent from '@testing-library/user-event';
3+
import { ClipboardCopy, ClipboardCopyVariant } from '../ClipboardCopy';
4+
5+
// This test file uses the real Truncate component for integration testing, instead of a mock
6+
7+
test('Tooltip appears on keyboard focus when using inline-compact variant with truncation', async () => {
8+
const user = userEvent.setup();
9+
const longText = 'This is a very long piece of content that should be truncated when the container is too small';
10+
11+
render(
12+
<ClipboardCopy
13+
variant={ClipboardCopyVariant.inlineCompact}
14+
truncation={{ maxCharsDisplayed: 20 }}
15+
data-testid="clipboard-copy"
16+
>
17+
{longText}
18+
</ClipboardCopy>
19+
);
20+
21+
expect(screen.queryByText(longText)).not.toBeInTheDocument();
22+
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
23+
24+
await user.tab();
25+
26+
const clipboardCopy = screen.getByTestId('clipboard-copy');
27+
expect(clipboardCopy).toHaveFocus();
28+
29+
const tooltip = screen.getByRole('tooltip');
30+
expect(tooltip).toBeInTheDocument();
31+
expect(tooltip).toHaveTextContent(longText);
32+
});

0 commit comments

Comments
 (0)