Files
jh-military-admin/tests/platform-compare-button.test.ts
T
dzc 7670ea22b2
build / task (16.x, npm, macOS-latest) (push) Canceled after 0s
build / task (16.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, npm, windows-latest) (push) Canceled after 0s
build / task (16.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (16.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (16.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (16.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (16.x, yarn, windows-latest) (push) Canceled after 0s
build / task (18.x, npm, macOS-latest) (push) Canceled after 0s
build / task (18.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, npm, windows-latest) (push) Canceled after 0s
build / task (18.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (18.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (18.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (18.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (18.x, yarn, windows-latest) (push) Canceled after 0s
build / task (20.x, npm, macOS-latest) (push) Canceled after 0s
build / task (20.x, npm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, npm, windows-latest) (push) Canceled after 0s
build / task (20.x, pnpm, macOS-latest) (push) Canceled after 0s
build / task (20.x, pnpm, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, pnpm, windows-latest) (push) Canceled after 0s
build / task (20.x, yarn, macOS-latest) (push) Canceled after 0s
build / task (20.x, yarn, ubuntu-latest) (push) Canceled after 0s
build / task (20.x, yarn, windows-latest) (push) Canceled after 0s
11
2026-11-04 12:31:49 +08:00

62 lines
2.8 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { mount, type VueWrapper } from '@vue/test-utils';
import { defineComponent, h } from 'vue';
import PlatformCompareButton from '../src/views/collection/video/components/platform-compare-button.vue';
import type { PlatformResourceType } from '../src/api/collection/videoPlatform';
const spies = vi.hoisted(() => ({ open: vi.fn(), permissions: new Set<string>() }));
vi.mock('/@/utils/authFunction', () => ({ auth: (permission: string) => spies.permissions.has(permission) }));
vi.mock('/@/views/collection/video/components/platform-resource-dialog.vue', () => ({
default: {
name: 'PlatformResourceDialog', emits: ['changed'],
setup: (_: unknown, { expose }: any) => { expose({ open: spies.open }); return () => null; },
},
}));
const wrappers: VueWrapper[] = [];
const Button = defineComponent({ setup: (_, { slots }) => () => h('button', slots.default?.()) });
const renderButton = (resourceType: PlatformResourceType) => {
const wrapper = mount(PlatformCompareButton, { props: { resourceType }, global: {
stubs: { ElButton: Button },
} });
wrappers.push(wrapper);
return wrapper;
};
beforeEach(() => {
spies.open.mockClear();
spies.permissions.clear();
});
afterEach(() => wrappers.splice(0).forEach(wrapper => wrapper.unmount()));
describe('ICC 数据对比快捷入口', () => {
it.each([
['PERSON', '人员', 'admin_sysPerson_view'],
['CAR', '车辆', 'car_carManage_view'],
['DEVICE', '设备', 'admin_deviceManage_view'],
['CHANNEL', '通道', 'admin_deviceManage_view'],
] as const)('%s 点击后打开相应全量差异弹窗,首次显示列表时不请求对比', async (type, label, permission) => {
spies.permissions.add(permission);
const wrapper = renderButton(type);
expect(spies.open).not.toHaveBeenCalled();
expect(wrapper.get('button').text()).toBe('ICC 数据对比');
expect(wrapper.get('button').attributes('title')).toBe(`对比 ICC 与本地已同步的全部${label}数据`);
await wrapper.get('button').trigger('click');
expect(spies.open).toHaveBeenCalledWith(type, 'DIFFERENCE', `ICC ${label}数据对比`);
});
it('仅有设备权限时,不展示人员、车辆的对比入口', () => {
spies.permissions.add('admin_deviceManage_view');
expect(renderButton('PERSON').find('button').exists()).toBe(false);
expect(renderButton('CAR').find('button').exists()).toBe(false);
expect(spies.open).not.toHaveBeenCalled();
});
it('差异修复完成后通知列表刷新', () => {
spies.permissions.add('admin_sysPerson_view');
const wrapper = renderButton('PERSON');
wrapper.findComponent({ name: 'PlatformResourceDialog' }).vm.$emit('changed');
expect(wrapper.emitted('changed')).toHaveLength(1);
});
});