Skip to content

Commit 7641189

Browse files
committed
Add CHANGELOG, fix issues when running build:release
1 parent 8609784 commit 7641189

File tree

4 files changed

+138
-2
lines changed

4 files changed

+138
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
### Removed
1717

1818
### Changed
19+
- Add support for React 19.
20+
- Migrate storybook to v8.
21+
- Migrate Jest to v29.
22+
- Rewrite PopOver component using floating-ui
1923

2024
### Fixed
2125

src/components/ui/PopOver/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ export const PopOver: FC<React.PropsWithChildren<PopOverProps>> = ({
168168
const buttonProps = {
169169
ref: refs.setReference,
170170
className: classnames(className, 'ch-popover-toggle'),
171-
onClick: handlePopOverClick,
172171
'data-menu': isSubMenu ? 'submenu' : null,
173172
'aria-label': a11yLabel,
174173
'aria-haspopup': true,
175174
'aria-expanded': isOpen,
176175
'data-testid': 'popover-toggle',
177176
...getReferenceProps(),
177+
onClick: handlePopOverClick,
178178
};
179179

180180
return (

src/theme/themes.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
14
import React from 'react';
25
import type { Meta, StoryObj } from '@storybook/react';
36
import { ThemeProvider } from 'styled-components';

tst/components/ui/PopOver/index.test.tsx

Lines changed: 130 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ describe('PopOver', () => {
270270
const toggle = getByTestId('popover-toggle');
271271
click(toggle);
272272
const option1 = getByTestId('option 1');
273+
const menu = getByTestId('menu');
273274
act(() => {
274-
fireEvent.keyDown(document.activeElement || document.body, {
275+
fireEvent.keyDown(menu, {
275276
key: 'ArrowDown',
276277
keyCode: 40,
277278
which: 40,
@@ -314,4 +315,132 @@ describe('PopOver', () => {
314315
});
315316
await waitFor(() => expect(menu).not.toBeInTheDocument());
316317
});
318+
319+
describe('handlePopOverClick', () => {
320+
it('should call onPopOverClick with false when popover is opened (isOpen was false)', async () => {
321+
const onPopOverClick = jest.fn();
322+
const component = (
323+
<PopOver
324+
renderButton={popOverButton}
325+
children={testChild}
326+
a11yLabel="test-label"
327+
onPopOverClick={onPopOverClick}
328+
/>
329+
);
330+
const { getByTestId } = renderWithTheme(lightTheme, component);
331+
const toggle = getByTestId('popover-toggle');
332+
333+
click(toggle);
334+
335+
await waitFor(() => {
336+
expect(onPopOverClick).toHaveBeenCalledWith(false);
337+
expect(onPopOverClick).toHaveBeenCalledTimes(1);
338+
});
339+
});
340+
341+
it('should call onPopOverClick with true when popover is closed (isOpen was true)', async () => {
342+
const onPopOverClick = jest.fn();
343+
const component = (
344+
<PopOver
345+
renderButton={popOverButton}
346+
children={testChild}
347+
a11yLabel="test-label"
348+
onPopOverClick={onPopOverClick}
349+
/>
350+
);
351+
const { getByTestId } = renderWithTheme(lightTheme, component);
352+
const toggle = getByTestId('popover-toggle');
353+
354+
// First click to open
355+
click(toggle);
356+
// Second click to close
357+
click(toggle);
358+
359+
await waitFor(() => {
360+
expect(onPopOverClick).toHaveBeenNthCalledWith(1, false); // First call when opening
361+
expect(onPopOverClick).toHaveBeenNthCalledWith(2, true); // Second call when closing
362+
expect(onPopOverClick).toHaveBeenCalledTimes(2);
363+
});
364+
});
365+
366+
it('should toggle isOpen state without calling onPopOverClick when callback is not provided', () => {
367+
const component = (
368+
<PopOver
369+
renderButton={popOverButton}
370+
children={testChild}
371+
a11yLabel="test-label"
372+
/>
373+
);
374+
const { getByTestId, queryByTestId } = renderWithTheme(lightTheme, component);
375+
const toggle = getByTestId('popover-toggle');
376+
377+
// Initially closed
378+
expect(queryByTestId('menu')).not.toBeInTheDocument();
379+
380+
// Click to open
381+
click(toggle);
382+
expect(queryByTestId('menu')).toBeInTheDocument();
383+
384+
// Click to close
385+
click(toggle);
386+
expect(queryByTestId('menu')).not.toBeInTheDocument();
387+
});
388+
389+
it('should properly toggle state multiple times and call onPopOverClick with correct values', async () => {
390+
const onPopOverClick = jest.fn();
391+
const component = (
392+
<PopOver
393+
renderButton={popOverButton}
394+
children={testChild}
395+
a11yLabel="test-label"
396+
onPopOverClick={onPopOverClick}
397+
/>
398+
);
399+
const { getByTestId, queryByTestId } = renderWithTheme(lightTheme, component);
400+
const toggle = getByTestId('popover-toggle');
401+
402+
// Initial state: closed
403+
expect(queryByTestId('menu')).not.toBeInTheDocument();
404+
405+
// First click: open
406+
click(toggle);
407+
await waitFor(() => {
408+
expect(queryByTestId('menu')).toBeInTheDocument();
409+
expect(onPopOverClick).toHaveBeenNthCalledWith(1, false);
410+
});
411+
412+
// Second click: close
413+
click(toggle);
414+
await waitFor(() => {
415+
expect(queryByTestId('menu')).not.toBeInTheDocument();
416+
expect(onPopOverClick).toHaveBeenNthCalledWith(2, true);
417+
});
418+
419+
// Third click: open again
420+
click(toggle);
421+
await waitFor(() => {
422+
expect(queryByTestId('menu')).toBeInTheDocument();
423+
expect(onPopOverClick).toHaveBeenNthCalledWith(3, false);
424+
expect(onPopOverClick).toHaveBeenCalledTimes(3);
425+
});
426+
});
427+
428+
it('should not throw error when onPopOverClick is undefined', () => {
429+
const component = (
430+
<PopOver
431+
renderButton={popOverButton}
432+
children={testChild}
433+
a11yLabel="test-label"
434+
onPopOverClick={undefined}
435+
/>
436+
);
437+
const { getByTestId } = renderWithTheme(lightTheme, component);
438+
const toggle = getByTestId('popover-toggle');
439+
440+
expect(() => {
441+
click(toggle);
442+
}).not.toThrow();
443+
});
444+
});
445+
317446
});

0 commit comments

Comments
 (0)