mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-04 08:15:41 +00:00
fix: stop Back doing nothing in Settings after the window crosses the phone width several times
This commit is contained in:
@@ -102,6 +102,37 @@ describe('Settings deep links on the phone', () => {
|
||||
expect(screen.getByText('appearance pane')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('adds one history entry however often the window crosses the phone breakpoint', () => {
|
||||
window.history.replaceState(null, '', '/settings');
|
||||
media.desktop = true;
|
||||
const { rerender } = render(<SettingsApp linkSegments={[]} />);
|
||||
const push = vi.spyOn(window.history, 'pushState');
|
||||
const resize = (desktop: boolean) => {
|
||||
media.desktop = desktop;
|
||||
rerender(<SettingsApp linkSegments={[]} />);
|
||||
};
|
||||
|
||||
resize(false);
|
||||
expect(push).toHaveBeenCalledTimes(1);
|
||||
resize(true);
|
||||
resize(false);
|
||||
resize(true);
|
||||
resize(false);
|
||||
expect(push).toHaveBeenCalledTimes(1);
|
||||
expect(screen.getByText('appearance pane')).toBeTruthy();
|
||||
|
||||
// Back from the page lands on the list...
|
||||
act(() => {
|
||||
window.history.replaceState(null, '', '/settings');
|
||||
window.dispatchEvent(new PopStateEvent('popstate'));
|
||||
});
|
||||
expect(screen.getByTestId('settings-tab-organize')).toBeTruthy();
|
||||
|
||||
// ...and a page opened from there has a Back of its own.
|
||||
fireEvent.click(screen.getByTestId('settings-tab-organize'));
|
||||
expect(push).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('opens a page at its top and keeps the place in the list', () => {
|
||||
window.history.replaceState(null, '', '/settings');
|
||||
render(<SettingsApp linkSegments={[]} />);
|
||||
|
||||
@@ -517,7 +517,12 @@ export function SettingsApp({ linkSegments: routeSegments }: SettingsAppProps =
|
||||
window.history.replaceState(window.history.state, '', listPath);
|
||||
}
|
||||
}
|
||||
window.history.pushState({ __settingsSubmenu: true }, '');
|
||||
// Once per open page: this runs again each time the window crosses the
|
||||
// phone breakpoint, and the entry from the last crossing is still there.
|
||||
// Back leaves that entry, so opening a page afterwards adds a new one.
|
||||
if (!(window.history.state as { __settingsSubmenu?: boolean } | null)?.__settingsSubmenu) {
|
||||
window.history.pushState({ __settingsSubmenu: true }, '');
|
||||
}
|
||||
|
||||
const handlePop = () => {
|
||||
setMobileShowContent(false);
|
||||
|
||||
Reference in New Issue
Block a user