refine mobile vehicle source evidence
This commit is contained in:
@@ -3,8 +3,11 @@ import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/re
|
||||
import { afterEach, expect, test, vi } from 'vitest';
|
||||
import { api } from '../../api/client';
|
||||
import type { VehicleSourceEvidence } from '../../api/types';
|
||||
import { useMobileLayout } from '../hooks/useMobileLayout';
|
||||
import { VehicleSourceEvidencePanel } from './VehicleSourceEvidencePanel';
|
||||
|
||||
vi.mock('../hooks/useMobileLayout', () => ({ useMobileLayout: vi.fn(() => false) }));
|
||||
|
||||
const evidence: VehicleSourceEvidence = {
|
||||
vin: 'VIN-001',
|
||||
plate: '粤A12345',
|
||||
@@ -40,6 +43,7 @@ const evidence: VehicleSourceEvidence = {
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.restoreAllMocks();
|
||||
vi.mocked(useMobileLayout).mockReturnValue(false);
|
||||
});
|
||||
|
||||
test('loads all source evidence only after the user expands it', async () => {
|
||||
@@ -59,3 +63,24 @@ test('loads all source evidence only after the user expands it', async () => {
|
||||
expect(screen.queryByText('13307795425')).not.toBeInTheDocument();
|
||||
client.clear();
|
||||
});
|
||||
|
||||
test('opens source evidence in a Semi bottom SideSheet on mobile without expanding the page card', async () => {
|
||||
vi.mocked(useMobileLayout).mockReturnValue(true);
|
||||
const sourceEvidence = vi.spyOn(api, 'vehicleSourceEvidence').mockResolvedValue(evidence);
|
||||
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
|
||||
const view = render(<QueryClientProvider client={client}><VehicleSourceEvidencePanel vin="VIN-001" /></QueryClientProvider>);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '查看全部来源' }));
|
||||
|
||||
await waitFor(() => expect(sourceEvidence).toHaveBeenCalledTimes(1));
|
||||
expect(view.container.querySelector('.v2-source-evidence.is-mobile-sheet')).toHaveClass('is-open');
|
||||
expect(view.container.querySelector('.v2-source-evidence > .semi-card-body > .v2-source-evidence-body')).not.toBeInTheDocument();
|
||||
expect(await screen.findByText('北斗平台')).toBeInTheDocument();
|
||||
expect(document.querySelector('.v2-source-evidence-sidesheet')).toBeInTheDocument();
|
||||
expect(document.querySelectorAll('.v2-source-evidence-sidesheet .v2-source-evidence-card')).toHaveLength(3);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '关闭来源证据' }));
|
||||
await waitFor(() => expect(view.container.querySelector('.v2-source-evidence')).not.toHaveClass('is-open'));
|
||||
client.clear();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user