Repository navigation
test(MobileNav): a native close of the drawer releases the page lock #8119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,6 +308,65 @@ describe('MobileNav close path edge cases', () => { | |
| expect(document.documentElement.style.overflow).toBe(''); | ||
| }); | ||
|
|
||
| it('releases the page when the dialog closed natively before isOpen turned false', () => { | ||
| vi.useFakeTimers(); | ||
| // A classic scrollbar, so the lock holds the gutter: jsdom does no layout. | ||
| const innerWidth = Object.getOwnPropertyDescriptor(window, 'innerWidth'); | ||
| const css = Object.getOwnPropertyDescriptor(window, 'CSS'); | ||
| Object.defineProperty(window, 'innerWidth', { | ||
| value: 1024, | ||
| configurable: true, | ||
| writable: true, | ||
| }); | ||
| Object.defineProperty(document.documentElement, 'clientWidth', { | ||
| value: 1009, | ||
| configurable: true, | ||
| }); | ||
| Object.defineProperty(window, 'CSS', { | ||
| value: { | ||
| supports: (property: string, value: string) => | ||
| property === 'scrollbar-gutter' && value === 'stable', | ||
| }, | ||
| configurable: true, | ||
| writable: true, | ||
| }); | ||
| try { | ||
| const {rerender} = render(<Drawer isOpen />); | ||
| const dialog = screen.getByTestId<HTMLDialogElement>('mobile-nav'); | ||
| // Whatever value the lock writes, the page is locked while open. | ||
| expect(document.documentElement.style.overflow).not.toBe(''); | ||
| expect(document.documentElement.style.scrollbarGutter).toBe('stable'); | ||
|
|
||
| // A `<form method="dialog">` submit or a close() through a ref closes | ||
| // the dialog before the app's state follows. | ||
| act(() => { | ||
| dialog.close(); | ||
| }); | ||
| act(() => { | ||
| rerender(<Drawer isOpen={false} />); | ||
| }); | ||
| act(() => { | ||
| vi.advanceTimersByTime(2000); | ||
| }); | ||
|
|
||
| expect(document.documentElement.style.overflow).toBe(''); | ||
| expect(document.documentElement.style.scrollbarGutter).toBe(''); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: the current expect(document.documentElement.style.overscrollBehaviorY).toBe('');
expect(document.body.style.overscrollBehaviorY).toBe(''); |
||
| } finally { | ||
| vi.useRealTimers(); | ||
| if (innerWidth) { | ||
| Object.defineProperty(window, 'innerWidth', innerWidth); | ||
| } | ||
| // @ts-expect-error -- drop the stub so jsdom's own value comes back | ||
| delete document.documentElement.clientWidth; | ||
| if (css) { | ||
| Object.defineProperty(window, 'CSS', css); | ||
| } else { | ||
| // @ts-expect-error -- jsdom has no CSS object of its own | ||
| delete window.CSS; | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| it('leaves no pending close timer behind after unmount', () => { | ||
| vi.useFakeTimers(); | ||
| try { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion cannot fail: jsdom reports
documentElement.clientWidthas 0, soholdScrollbarGutterreturns its no-op andscrollbarGutteris already''while the drawer is open. Stubbing a classic scrollbar (asstubViewport(1024, 1009)withCSS.supports('scrollbar-gutter', 'stable')inMobileNavScrollbarGutter.test.tsx) and assertingstablebefore the close would make the gutter half of the case real.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed at 0a17209: the case stubs a classic scrollbar, as
MobileNavScrollbarGutter.test.tsxdoes, and assertsstablewhile open and''after the native close. A control without the lock's gutter release fails here.