mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-14 01:45:00 +03:00
89e200ead4
Zod 4: use the `error` param instead of the deprecated `message`. lint:deprecated missed these because tsgolint's no-deprecated does not resolve object-literal properties on a `string | Params` union. Geodata: key geo entry rows by page position. antd deprecates rowKey's index argument, and kind:value repeats within a page because the reader drops domain attributes (22 pairs in geosite_IR.dat, 108 in geosite_RU). Nord/PIA: the "All cities/regions" option used a null value, which antd warns on. Map it through a sentinel at the Select boundary so form state stays null, with tests that fail when the sentinel is not mapped back. Tests: - Run the oxlint guard through node; .bin/oxlint is a sh shim Windows cannot spawn, and the swallowed error left both guard cases vacuous. - Start unit workers with --no-experimental-webstorage; msw's localStorage probe made Node 25+ warn once per forked worker. - Set IS_REACT_ACT_ENVIRONMENT, which RTL never sets with globals: false, and settle the async updates it exposed inside act(). The row-cells memo test now fails when memo is removed. - Disable antd's click wave in Storybook; it re-rendered inside the next story's act() and tripped "not configured to support act". - Assert InboundFormModal's validation log instead of leaking it, and give the rule-form test a well-formed clients/list response.
77 lines
2.9 KiB
TypeScript
77 lines
2.9 KiB
TypeScript
import { act, fireEvent, screen } from '@testing-library/react';
|
|
import { MemoryRouter } from 'react-router';
|
|
import { afterEach, expect, test, vi } from 'vitest';
|
|
|
|
import AppSidebar from '@/layouts/AppSidebar';
|
|
import { renderWithProviders } from './test-utils';
|
|
|
|
vi.mock('@/api/queries/useAllSettings', () => ({
|
|
useAllSettings: () => ({ allSetting: {} }),
|
|
}));
|
|
|
|
afterEach(() => {
|
|
localStorage.clear();
|
|
});
|
|
|
|
// rc-menu registers its items in a microtask after render; settle it inside act().
|
|
async function renderSidebar() {
|
|
const view = renderWithProviders(
|
|
<MemoryRouter>
|
|
<AppSidebar />
|
|
</MemoryRouter>,
|
|
);
|
|
await act(async () => {});
|
|
return view;
|
|
}
|
|
|
|
test('keeps the sidebar expanded after pinning it from the header and restores the choice', async () => {
|
|
const first = await renderSidebar();
|
|
const sidebar = first.container.querySelector('.ant-layout-sider');
|
|
const sidebarRoot = first.container.querySelector('.ant-sidebar');
|
|
|
|
expect(sidebar?.classList.contains('ant-layout-sider-collapsed')).toBe(true);
|
|
|
|
fireEvent.mouseEnter(sidebarRoot!);
|
|
|
|
const pinButton = screen.getByRole('button', { name: 'Pin sidebar' });
|
|
expect(pinButton.closest('.brand-actions')).not.toBeNull();
|
|
|
|
fireEvent.click(pinButton);
|
|
fireEvent.mouseLeave(sidebarRoot!);
|
|
|
|
expect(sidebar?.classList.contains('ant-layout-sider-collapsed')).toBe(false);
|
|
expect(sidebarRoot?.getAttribute('style')).toContain('--sider-rail: 220px');
|
|
expect(localStorage.getItem('sidebar-pinned')).toBe('true');
|
|
|
|
first.unmount();
|
|
|
|
const second = await renderSidebar();
|
|
const restoredSidebar = second.container.querySelector('.ant-layout-sider');
|
|
const restoredSidebarRoot = second.container.querySelector('.ant-sidebar');
|
|
|
|
expect(restoredSidebar?.classList.contains('ant-layout-sider-collapsed')).toBe(false);
|
|
expect(restoredSidebarRoot?.getAttribute('style')).toContain('--sider-rail: 220px');
|
|
expect(screen.getByRole('button', { name: 'Pin sidebar' })).not.toBeNull();
|
|
});
|
|
|
|
test('returns to the compact rail after unpinning', async () => {
|
|
const view = await renderSidebar();
|
|
const sidebar = view.container.querySelector('.ant-layout-sider');
|
|
const sidebarRoot = view.container.querySelector('.ant-sidebar');
|
|
|
|
fireEvent.mouseEnter(sidebarRoot!);
|
|
fireEvent.click(screen.getByRole('button', { name: 'Pin sidebar' }));
|
|
fireEvent.click(screen.getByRole('button', { name: 'Pin sidebar' }));
|
|
fireEvent.mouseLeave(sidebarRoot!);
|
|
|
|
expect(sidebar?.classList.contains('ant-layout-sider-collapsed')).toBe(true);
|
|
expect(sidebarRoot?.getAttribute('style')).toContain('--sider-rail: 72px');
|
|
expect(localStorage.getItem('sidebar-pinned')).toBe('false');
|
|
});
|
|
|
|
test('labels the palette shortcut with the modifier the platform actually uses', async () => {
|
|
const view = await renderSidebar();
|
|
const chip = view.container.querySelector('.sidebar-command-kbd');
|
|
expect(chip?.textContent).toBe('CtrlK');
|
|
});
|