mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-05 16:16:49 +00:00
A window snapped to half the screen (640-800 px) or a 1366x768 laptop at 150 % (911 px) got the phone and tablet layout: bottom tab bar, folders in a drawer, Settings as a phone list with a Back arrow. The layout switched at the 64rem (1024 px) breakpoint. Now the phone layout starts below 600 px. From 600 to 1024 px the app is a compact desktop: app rail at the side, folder sidebar folded to its icons (the existing collapsed state, opened per session with its toggle), Settings with its two panes and a narrower page list. Below 840 px the split layout opens a message in the list's place, as the focused layout does. This holds in the browser and the desktop app, in the Pro shell (which now runs from 600 px) and under Mountain View. - `hooks/use-media-query.ts`: classifyWidth, PHONE_BELOW 600, FULL_DESKTOP 1024; the tablet class (`isTablet`) is gone, the store has `isCompact` instead. Plugins still see "tablet" for it. - `app/globals.css`: a `desk:` breakpoint at 37.5rem for the layout classes, and a `tap:` variant for 44px rows on phones and touch screens below 1024 px (was every window below 1024 px). - Touch screens below 1024 px keep swiping list rows (was phones only). - The boot skeletons, boot script, mail app, sidebar, reader, admin shell and calendar, contacts and files follow the new widths. Tests changed with the behaviour: the tablet cases in pro-gate, mail-app-mv-composer-move, mail-app-compose-handoff, mail-app-thread-expand-mark-read, mobile-tour-end and thread-list-item-columns now run on a phone or a compact desktop, as those widths no longer exist as a tablet. mail-app-short-window-tab-bar is replaced by mail-app-compact-layout: a phone on its side is a compact desktop with the rail at the side, so the short-window tab bar rule is gone. Class and media-query assertions follow desk:/tap: and 37.5rem; the 32px-text test uses 1100 px, since 1440 px at 32px is now a compact desktop.
102 lines
4.6 KiB
TypeScript
102 lines
4.6 KiB
TypeScript
import { render, screen } from '@testing-library/react';
|
|
import { renderToString } from 'react-dom/server';
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('next/navigation', () => ({ usePathname: () => '/admin' }));
|
|
vi.mock('@/components/layout/navigation-rail', () => ({ NavigationRail: () => null }));
|
|
vi.mock('@/components/settings/about-data-settings', () => ({ AboutFooter: () => null }));
|
|
vi.mock('@/lib/browser-navigation', () => ({
|
|
apiFetch: vi.fn(() => Promise.resolve({ ok: false })),
|
|
getPathPrefix: () => '',
|
|
withBasePath: (href: string) => href,
|
|
}));
|
|
|
|
import { AdminShell } from '../admin-shell';
|
|
import { useUpdateStore } from '@/stores/update-store';
|
|
|
|
function setDesktop(desktop: boolean) {
|
|
window.matchMedia = vi.fn((query: string) => ({
|
|
matches: desktop && query === '(width >= 37.5rem)',
|
|
media: query,
|
|
addEventListener: () => {},
|
|
removeEventListener: () => {},
|
|
})) as unknown as typeof window.matchMedia;
|
|
}
|
|
|
|
function shell(props: { authenticated: boolean; isStalwartAutoLogin: boolean }) {
|
|
return (
|
|
<AdminShell {...props} configReadOnly={false} onLogout={() => {}}>
|
|
<p>page</p>
|
|
</AdminShell>
|
|
);
|
|
}
|
|
|
|
describe('AdminShell', () => {
|
|
beforeEach(() => {
|
|
setDesktop(true);
|
|
Element.prototype.scrollTo = () => {};
|
|
});
|
|
|
|
// The server can't know the width: it draws the panel's skeleton, whose
|
|
// phone and desktop layouts CSS picks, rather than either real layout.
|
|
it('server-renders the panel skeleton, not a real layout', () => {
|
|
const html = renderToString(shell({ authenticated: false, isStalwartAutoLogin: false }));
|
|
const container = document.createElement('div');
|
|
container.innerHTML = html;
|
|
const region = container.querySelector('[data-boot-skeleton="admin"]');
|
|
expect(region).not.toBeNull();
|
|
expect(region!.querySelector('[role="status"]')?.textContent).toBe('common.loading');
|
|
expect(container.querySelectorAll('a[href], button, input')).toHaveLength(0);
|
|
expect(html).not.toContain('<p>page</p>');
|
|
});
|
|
|
|
// The shell's own names come from the translations, and the tab says
|
|
// which admin page is open.
|
|
it('names the page list and the search in the language of the user', () => {
|
|
render(shell({ authenticated: true, isStalwartAutoLogin: false }));
|
|
expect(screen.getByRole('navigation', { name: 'admin_pages' })).toBeTruthy();
|
|
expect(screen.getByRole('searchbox', { name: 'admin_search' })).toHaveAttribute('placeholder', 'admin_search');
|
|
expect(document.title).toMatch(/^.+ - admin - /);
|
|
});
|
|
|
|
it('draws the desktop sidebar once on the client', () => {
|
|
render(shell({ authenticated: true, isStalwartAutoLogin: false }));
|
|
expect(screen.getByText('back_to_mail')).toBeTruthy();
|
|
});
|
|
|
|
it('hides the session links until the check says which kind of admin this is', () => {
|
|
const { rerender } = render(shell({ authenticated: false, isStalwartAutoLogin: false }));
|
|
// Only their shapes hold the place while the check runs.
|
|
expect(screen.queryByRole('button', { name: 'Sign out of admin' })).toBeNull();
|
|
expect(screen.queryByRole('link', { name: 'Change password' })).toBeNull();
|
|
expect(screen.getByText('Sign out of admin').closest('[aria-hidden="true"]')).not.toBeNull();
|
|
rerender(shell({ authenticated: true, isStalwartAutoLogin: true }));
|
|
expect(screen.queryByText('Sign out of admin')).toBeNull();
|
|
rerender(shell({ authenticated: true, isStalwartAutoLogin: false }));
|
|
expect(screen.getByText('Sign out of admin')).toBeTruthy();
|
|
expect(screen.getByText('Change password')).toBeTruthy();
|
|
});
|
|
|
|
// The dot next to Version was a span with aria-label, which screen
|
|
// readers don't announce.
|
|
it('announces a waiting update on the Version entry', () => {
|
|
useUpdateStore.setState({
|
|
status: { updateAvailable: true, severity: 'minor', current: process.env.NEXT_PUBLIC_APP_VERSION ?? '', latest: '9.9.9' },
|
|
startPolling: () => {},
|
|
} as never);
|
|
render(shell({ authenticated: true, isStalwartAutoLogin: false }));
|
|
const dot = screen.getAllByRole('img', { name: 'update_available' })[0];
|
|
expect(dot.getAttribute('title')).toBe('update_available');
|
|
});
|
|
|
|
// Translated like the same dot on the navigation rail (shell namespace).
|
|
it('names an important update in the language of the user', () => {
|
|
useUpdateStore.setState({
|
|
status: { updateAvailable: true, severity: 'security', current: process.env.NEXT_PUBLIC_APP_VERSION ?? '', latest: '9.9.9' },
|
|
startPolling: () => {},
|
|
} as never);
|
|
render(shell({ authenticated: true, isStalwartAutoLogin: false }));
|
|
expect(screen.getAllByRole('img', { name: 'update_important' })[0].getAttribute('title')).toBe('update_important');
|
|
});
|
|
});
|