77 lines
2.9 KiB
TypeScript
77 lines
2.9 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { buildAppHash, parseAppHash } from './appRoute';
|
|
|
|
describe('parseAppHash', () => {
|
|
test('parses detail page keyword from hash query', () => {
|
|
expect(parseAppHash('#/detail?keyword=%E7%B2%A4AG18312&protocol=JT808')).toEqual({
|
|
page: 'detail',
|
|
keyword: '粤AG18312',
|
|
protocol: 'JT808',
|
|
filters: {}
|
|
});
|
|
});
|
|
|
|
test('parses history tab from hash query', () => {
|
|
expect(parseAppHash('#/history?keyword=VIN001&protocol=JT808&tab=raw')).toEqual({
|
|
page: 'history',
|
|
keyword: 'VIN001',
|
|
protocol: 'JT808',
|
|
filters: {
|
|
tab: 'raw'
|
|
}
|
|
});
|
|
});
|
|
|
|
test('parses vehicle list filters from hash query', () => {
|
|
expect(parseAppHash('#/vehicles?coverage=multi&serviceStatus=degraded&online=online&bindingStatus=bound&archiveStatus=incomplete&archiveMissing=phone&missingProtocol=YUTONG_MQTT')).toEqual({
|
|
page: 'vehicles',
|
|
filters: {
|
|
coverage: 'multi',
|
|
serviceStatus: 'degraded',
|
|
online: 'online',
|
|
bindingStatus: 'bound',
|
|
archiveStatus: 'incomplete',
|
|
archiveMissing: 'phone',
|
|
missingProtocol: 'YUTONG_MQTT'
|
|
}
|
|
});
|
|
});
|
|
|
|
test('parses quality governance filters from hash query', () => {
|
|
expect(parseAppHash('#/quality?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE')).toEqual({
|
|
page: 'quality',
|
|
keyword: '粤A',
|
|
protocol: 'VEHICLE_SERVICE',
|
|
filters: {
|
|
issueType: 'NO_SOURCE'
|
|
}
|
|
});
|
|
});
|
|
|
|
test('ignores unknown pages', () => {
|
|
expect(parseAppHash('#/unknown?keyword=VIN001')).toEqual({});
|
|
});
|
|
});
|
|
|
|
describe('buildAppHash', () => {
|
|
test('builds shareable vehicle page hash with encoded keyword', () => {
|
|
expect(buildAppHash({ page: 'history', keyword: '粤AG18312', protocol: 'GB32960' })).toBe('#/history?keyword=%E7%B2%A4AG18312&protocol=GB32960');
|
|
});
|
|
|
|
test('builds shareable raw history hash', () => {
|
|
expect(buildAppHash({ page: 'history', keyword: 'VIN001', protocol: 'JT808', filters: { tab: 'raw' } })).toBe('#/history?keyword=VIN001&protocol=JT808&tab=raw');
|
|
});
|
|
|
|
test('builds shareable vehicle list hash with filters', () => {
|
|
expect(buildAppHash({ page: 'vehicles', filters: { coverage: 'multi', serviceStatus: 'degraded', archiveStatus: 'incomplete', archiveMissing: 'phone', missingProtocol: 'YUTONG_MQTT' } })).toBe('#/vehicles?coverage=multi&serviceStatus=degraded&archiveStatus=incomplete&archiveMissing=phone&missingProtocol=YUTONG_MQTT');
|
|
});
|
|
|
|
test('builds shareable quality hash with filters', () => {
|
|
expect(buildAppHash({ page: 'quality', keyword: '粤A', protocol: 'VEHICLE_SERVICE', filters: { issueType: 'NO_SOURCE' } })).toBe('#/quality?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE');
|
|
});
|
|
|
|
test('builds page-only hash when keyword is empty', () => {
|
|
expect(buildAppHash({ page: 'quality', keyword: '' })).toBe('#/quality');
|
|
});
|
|
});
|