Skip to content

Commit a45f618

Browse files
ho991217jungpaeng
andauthored
fix: initializing current overlay after close all overlays (#119)
* test: add test for current overlay state when all overlays are closed * fix: Reset current overlay to null when closing all overlays * Create stupid-boxes-pay.md --------- Co-authored-by: Yongbeen Im <meis1541@naver.com> Co-authored-by: Yongbeen Im <been.im@toss.im>
1 parent a179aa3 commit a45f618

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

.changeset/stupid-boxes-pay.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"overlay-kit": patch
3+
---
4+
5+
fix: initializing current overlay after close all overlays

packages/src/context/reducer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export function overlayReducer(state: OverlayData, action: OverlayReducerAction)
114114
case 'CLOSE_ALL': {
115115
return {
116116
...state,
117+
current: null,
117118
overlayData: Object.keys(state.overlayData).reduce(
118119
(prev, curr) => ({
119120
...prev,

packages/src/event.test.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,39 @@ describe('overlay object', () => {
288288
});
289289
});
290290

291+
it('should not be able to get current overlay when all overlays are closed', async () => {
292+
const contents = {
293+
first: 'overlay-content-1',
294+
second: 'overlay-content-2',
295+
};
296+
297+
function Component() {
298+
const current = useCurrentOverlay();
299+
300+
useEffect(() => {
301+
// Open 2 overlays sequentially
302+
overlay.open(({ isOpen }) => isOpen && <div data-testid="overlay-1">{contents.first}</div>);
303+
overlay.open(({ isOpen }) => isOpen && <div data-testid="overlay-2">{contents.second}</div>);
304+
}, []);
305+
306+
return <div data-testid="current-overlay">{current}</div>;
307+
}
308+
309+
render(<Component />, { wrapper });
310+
311+
// Wait for all overlays to be mounted
312+
await waitFor(() => {
313+
expect(screen.getByTestId('overlay-1')).toBeInTheDocument();
314+
expect(screen.getByTestId('overlay-2')).toBeInTheDocument();
315+
});
316+
317+
// close all overlays
318+
overlay.closeAll();
319+
await waitFor(() => {
320+
expect(screen.getByTestId('current-overlay')).toHaveTextContent('');
321+
});
322+
});
323+
291324
it('should be able to unmount all overlays', async () => {
292325
const contents = {
293326
first: 'overlay-content-1',

0 commit comments

Comments
 (0)