Skip to content

Commit 40d34e7

Browse files
update tests
1 parent 4b5f5eb commit 40d34e7

File tree

4 files changed

+78
-14
lines changed

4 files changed

+78
-14
lines changed

packages/react-core/src/components/Compass/__tests__/CompassNavContent.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ import styles from '@patternfly/react-styles/css/components/Compass/compass';
44

55
test('Renders with children', () => {
66
render(<CompassNavContent>Test content</CompassNavContent>);
7+
78
expect(screen.getByText('Test content')).toBeVisible();
89
});
910

1011
test('Renders with custom class name when className prop is provided', () => {
1112
render(<CompassNavContent className="custom-class">Test</CompassNavContent>);
13+
1214
expect(screen.getByText('Test')).toHaveClass('custom-class');
1315
});
1416

1517
test(`Renders with default ${styles.compassNavContent} class`, () => {
1618
render(<CompassNavContent>Test</CompassNavContent>);
17-
expect(screen.getByText('Test')).toHaveClass(styles.compassNavContent);
19+
20+
expect(screen.getByText('Test')).toHaveClass(styles.compassNavContent, { exact: true });
1821
});
1922

2023
test('Renders with additional props spread to the component', () => {
2124
render(<CompassNavContent aria-label="Test label">Test</CompassNavContent>);
25+
2226
expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
2327
});
2428

@@ -28,5 +32,6 @@ test('Matches the snapshot', () => {
2832
<div>Nav content wrapper</div>
2933
</CompassNavContent>
3034
);
35+
3136
expect(asFragment()).toMatchSnapshot();
3237
});

packages/react-core/src/components/Compass/__tests__/CompassNavHome.test.tsx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,85 @@ import styles from '@patternfly/react-styles/css/components/Compass/compass';
55

66
test('Renders with default aria-label', () => {
77
render(<CompassNavHome />);
8+
89
expect(screen.getByRole('button', { name: 'Home' })).toBeVisible();
910
});
1011

1112
test('Renders with custom aria-label when provided', () => {
1213
render(<CompassNavHome aria-label="Custom home" />);
14+
1315
expect(screen.getByRole('button', { name: 'Custom home' })).toBeVisible();
1416
});
1517

16-
test('Renders with default tooltip content', () => {
18+
test('Renders with default tooltip content', async () => {
19+
const user = userEvent.setup();
20+
1721
render(<CompassNavHome />);
18-
expect(screen.getByRole('button', { name: 'Home' })).toBeVisible();
22+
23+
const button = screen.getByRole('button');
24+
25+
user.hover(button);
26+
27+
await screen.findByRole('tooltip');
28+
29+
expect(screen.getByRole('tooltip')).toHaveTextContent('Home');
1930
});
2031

21-
test('Renders with custom tooltip content when provided', () => {
32+
test('Renders with custom tooltip content when provided', async () => {
33+
const user = userEvent.setup();
34+
2235
render(<CompassNavHome tooltipContent="Custom tooltip" />);
23-
expect(screen.getByRole('button', { name: 'Home' })).toBeVisible();
36+
37+
const button = screen.getByRole('button');
38+
39+
user.hover(button);
40+
41+
await screen.findByRole('tooltip');
42+
expect(screen.getByRole('tooltip')).toHaveTextContent('Custom tooltip');
2443
});
2544

2645
test('Renders with custom class name when className prop is provided', () => {
2746
const { container } = render(<CompassNavHome className="custom-class" />);
47+
2848
expect(container.firstChild).toHaveClass('custom-class');
2949
});
3050

3151
test(`Renders with default class`, () => {
3252
const { container } = render(<CompassNavHome />);
33-
expect(container.firstChild).toHaveClass(styles.compassNav + '-home');
53+
54+
expect(container.firstChild).toHaveClass(styles.compassNav + '-home', { exact: true });
3455
});
3556

3657
test('Calls onClick handler when button is clicked', async () => {
37-
const onClick = jest.fn();
3858
const user = userEvent.setup();
59+
const onClick = jest.fn();
60+
3961
render(<CompassNavHome onClick={onClick} />);
4062

4163
await user.click(screen.getByRole('button', { name: 'Home' }));
64+
4265
expect(onClick).toHaveBeenCalledTimes(1);
4366
});
4467

4568
test('Renders button with plain variant and circle shape', () => {
4669
render(<CompassNavHome />);
70+
4771
const button = screen.getByRole('button', { name: 'Home' });
72+
4873
expect(button).toHaveClass('pf-m-plain');
74+
expect(button).toHaveClass('pf-m-circle');
4975
});
5076

5177
test('Matches the snapshot', () => {
5278
const { asFragment } = render(<CompassNavHome />);
79+
5380
expect(asFragment()).toMatchSnapshot();
5481
});
5582

5683
test('Matches the snapshot with custom props', () => {
5784
const { asFragment } = render(
5885
<CompassNavHome aria-label="Custom home" tooltipContent="Go home" className="custom-class" />
5986
);
87+
6088
expect(asFragment()).toMatchSnapshot();
6189
});

packages/react-core/src/components/Compass/__tests__/CompassNavMain.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ import styles from '@patternfly/react-styles/css/components/Compass/compass';
44

55
test('Renders with children', () => {
66
render(<CompassNavMain>Test content</CompassNavMain>);
7+
78
expect(screen.getByText('Test content')).toBeVisible();
89
});
910

1011
test('Renders with custom class name when className prop is provided', () => {
1112
render(<CompassNavMain className="custom-class">Test</CompassNavMain>);
13+
1214
expect(screen.getByText('Test')).toHaveClass('custom-class');
1315
});
1416

1517
test(`Renders with default ${styles.compassNavMain} class`, () => {
1618
render(<CompassNavMain>Test</CompassNavMain>);
17-
expect(screen.getByText('Test')).toHaveClass(styles.compassNavMain);
19+
20+
expect(screen.getByText('Test')).toHaveClass(styles.compassNavMain, { exact: true });
1821
});
1922

2023
test('Renders with additional props spread to the component', () => {
2124
render(<CompassNavMain aria-label="Test label">Test</CompassNavMain>);
25+
2226
expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
2327
});
2428

@@ -28,5 +32,6 @@ test('Matches the snapshot', () => {
2832
<div>Main tabs content</div>
2933
</CompassNavMain>
3034
);
35+
3136
expect(asFragment()).toMatchSnapshot();
3237
});

packages/react-core/src/components/Compass/__tests__/CompassNavSearch.test.tsx

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,75 @@ test('Renders with custom aria-label when provided', () => {
1313
expect(screen.getByRole('button', { name: 'Custom search' })).toBeVisible();
1414
});
1515

16-
test('Renders with default tooltip content', () => {
16+
test('Renders with default tooltip content', async () => {
17+
const user = userEvent.setup();
18+
1719
render(<CompassNavSearch />);
18-
expect(screen.getByRole('button', { name: 'Search' })).toBeVisible();
20+
21+
const button = screen.getByRole('button');
22+
23+
user.hover(button);
24+
25+
await screen.findByRole('tooltip');
26+
27+
expect(screen.getByRole('tooltip')).toHaveTextContent('Search');
1928
});
2029

21-
test('Renders with custom tooltip content when provided', () => {
30+
test('Renders with custom tooltip content when provided', async () => {
31+
const user = userEvent.setup();
32+
2233
render(<CompassNavSearch tooltipContent="Custom tooltip" />);
23-
expect(screen.getByRole('button', { name: 'Search' })).toBeVisible();
34+
35+
const button = screen.getByRole('button');
36+
37+
user.hover(button);
38+
39+
await screen.findByRole('tooltip');
40+
41+
expect(screen.getByRole('tooltip')).toHaveTextContent('Custom tooltip');
2442
});
2543

2644
test('Renders with custom class name when className prop is provided', () => {
2745
const { container } = render(<CompassNavSearch className="custom-class" />);
46+
2847
expect(container.firstChild).toHaveClass('custom-class');
2948
});
3049

3150
test(`Renders with default class`, () => {
3251
const { container } = render(<CompassNavSearch />);
33-
expect(container.firstChild).toHaveClass(styles.compassNav + '-search');
52+
53+
expect(container.firstChild).toHaveClass(styles.compassNav + '-search', { exact: true });
3454
});
3555

3656
test('Calls onClick handler when button is clicked', async () => {
37-
const onClick = jest.fn();
3857
const user = userEvent.setup();
58+
const onClick = jest.fn();
59+
3960
render(<CompassNavSearch onClick={onClick} />);
4061

4162
await user.click(screen.getByRole('button', { name: 'Search' }));
63+
4264
expect(onClick).toHaveBeenCalledTimes(1);
4365
});
4466

4567
test('Renders button with plain variant and circle shape', () => {
4668
render(<CompassNavSearch />);
69+
4770
const button = screen.getByRole('button', { name: 'Search' });
71+
4872
expect(button).toHaveClass('pf-m-plain');
4973
});
5074

5175
test('Matches the snapshot', () => {
5276
const { asFragment } = render(<CompassNavSearch />);
77+
5378
expect(asFragment()).toMatchSnapshot();
5479
});
5580

5681
test('Matches the snapshot with custom props', () => {
5782
const { asFragment } = render(
5883
<CompassNavSearch aria-label="Custom search" tooltipContent="Search content" className="custom-class" />
5984
);
85+
6086
expect(asFragment()).toMatchSnapshot();
6187
});

0 commit comments

Comments
 (0)