feat(platform): copy quality filter links
This commit is contained in:
@@ -43,6 +43,10 @@ function qualityParams(values: Record<string, string>) {
|
||||
return params;
|
||||
}
|
||||
|
||||
function qualityShareURL() {
|
||||
return `${window.location.origin}${window.location.pathname}${window.location.hash}`;
|
||||
}
|
||||
|
||||
async function copyText(value: string, label: string) {
|
||||
const text = value.trim();
|
||||
if (!text) {
|
||||
@@ -57,6 +61,10 @@ async function copyText(value: string, label: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function copyQualityShareURL() {
|
||||
await copyText(qualityShareURL(), '筛选链接');
|
||||
}
|
||||
|
||||
export function Quality({
|
||||
onOpenVehicle,
|
||||
onHealthLoaded,
|
||||
@@ -194,6 +202,7 @@ export function Quality({
|
||||
</Form.Select>
|
||||
<Space>
|
||||
<Button htmlType="submit" theme="solid" type="primary">筛选</Button>
|
||||
<Button icon={<IconCopy />} onClick={copyQualityShareURL}>复制筛选链接</Button>
|
||||
<Button onClick={() => {
|
||||
applyFilters({});
|
||||
}}>重置</Button>
|
||||
|
||||
@@ -854,6 +854,71 @@ test('applies shareable quality filters from hash', async () => {
|
||||
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/summary?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE'), undefined);
|
||||
});
|
||||
|
||||
test('copies shareable quality filter link', async () => {
|
||||
window.history.replaceState(null, '', '/#/quality?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE');
|
||||
const writeText = vi.fn().mockResolvedValue(undefined);
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
configurable: true,
|
||||
value: { writeText }
|
||||
});
|
||||
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||
const path = String(input);
|
||||
if (path.includes('/api/ops/health')) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
}
|
||||
if (path.includes('/api/quality/summary')) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
issueVehicleCount: 1,
|
||||
issueRecordCount: 1,
|
||||
errorCount: 0,
|
||||
warningCount: 1,
|
||||
protocols: [{ name: 'VEHICLE_SERVICE', count: 1 }],
|
||||
issueTypes: [{ name: 'NO_SOURCE', count: 1 }]
|
||||
},
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
}
|
||||
if (path.includes('/api/quality/issues')) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: { items: [], total: 1, limit: 20, offset: 0 },
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: { items: [], total: 0, limit: 20, offset: 0 },
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: /复制筛选链接/ }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/#/quality?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE'));
|
||||
});
|
||||
});
|
||||
|
||||
test('opens vehicle detail from shareable hash', async () => {
|
||||
window.history.replaceState(null, '', '/#/detail?keyword=%E7%B2%A4AG18312');
|
||||
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
|
||||
|
||||
@@ -45,6 +45,13 @@ class TestResizeObserver {
|
||||
Object.defineProperty(window, 'ResizeObserver', { value: TestResizeObserver });
|
||||
Object.defineProperty(globalThis, 'ResizeObserver', { value: TestResizeObserver });
|
||||
|
||||
Object.defineProperty(navigator, 'clipboard', {
|
||||
configurable: true,
|
||||
value: {
|
||||
writeText: () => Promise.resolve()
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
value: (query: string) => ({
|
||||
matches: false,
|
||||
|
||||
Reference in New Issue
Block a user