Skip to content

Commit 97c8cfc

Browse files
committed
test: update snapshot tests to wait for popper opacity transition
Update Jest snapshot tests to wait for popper elements to complete their opacity transition after the double requestAnimationFrame fix. This ensures snapshots are taken after poppers are fully visible (opacity: 1) rather than during the transition phase (opacity: 0). Signed-off-by: Mohamed Fall <ps.hackmaster@gmail.com>
1 parent 1bb6a2b commit 97c8cfc

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

packages/react-core/src/components/DatePicker/__tests__/DatePicker.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { screen, render } from '@testing-library/react';
1+
import { screen, render, waitFor } from '@testing-library/react';
22
import userEvent from '@testing-library/user-event';
33

44
import { HelperText, HelperTextItem } from '../../HelperText';
@@ -93,6 +93,11 @@ test('With popover opened', async () => {
9393

9494
await user.click(screen.getByRole('button', { name: 'Toggle date picker' }));
9595
await screen.findByRole('button', { name: 'Previous month' });
96+
// Wait for popper opacity transition after requestAnimationFrame
97+
await waitFor(() => {
98+
const popover = screen.getByRole('dialog');
99+
expect(popover).toHaveStyle({ opacity: '1' });
100+
});
96101

97102
expect(asFragment()).toMatchSnapshot();
98103
});

packages/react-core/src/components/Nav/__tests__/Nav.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { StrictMode } from 'react';
2-
import { render, screen } from '@testing-library/react';
2+
import { render, screen, waitFor } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import '@testing-library/jest-dom';
55

@@ -242,6 +242,11 @@ describe('Nav', () => {
242242
);
243243

244244
await user.hover(screen.getByText('My custom node'));
245+
// Wait for popper opacity transition after requestAnimationFrame
246+
await waitFor(() => {
247+
const flyout = screen.getByText('Flyout test').parentElement;
248+
expect(flyout).toHaveStyle({ opacity: '1' });
249+
});
245250
expect(asFragment()).toMatchSnapshot();
246251
});
247252

packages/react-core/src/components/SearchInput/__tests__/SearchInput.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { StrictMode } from 'react';
2-
import { render, screen } from '@testing-library/react';
2+
import { render, screen, waitFor } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44

55
import { SearchInput } from '../SearchInput';
@@ -151,6 +151,11 @@ describe('SearchInput', () => {
151151
expect(screen.getByTestId('test-id')).toContainElement(screen.getByText('First name'));
152152

153153
expect(props.onSearch).toHaveBeenCalled();
154+
// Wait for popper opacity transition after requestAnimationFrame
155+
await waitFor(() => {
156+
const panel = screen.getByText('First name').closest('.pf-v6-c-panel');
157+
expect(panel?.parentElement).toHaveStyle({ opacity: '1' });
158+
});
154159
expect(asFragment()).toMatchSnapshot();
155160
});
156161

0 commit comments

Comments
 (0)