kt-template-admin/test/views/qqbot/account/napcat/NapcatRuntimeProfileDrawer.spec.tsx

91 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* @vitest-environment happy-dom */
/* eslint-disable vue/one-component-per-file, vue/require-default-prop */
import { flushPromises, mount } from '@vue/test-utils';
import { defineComponent, h } from 'vue';
import NapcatRuntimeProfileDrawer from '@test-source/apps/web-antdv-next/src/views/qqbot/account/napcat/NapcatRuntimeProfileDrawer';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { getQqbotNapcatRuntimeDetail } from '#/api/qqbot/napcat';
vi.mock('#/api/qqbot/napcat', () => ({
getQqbotNapcatRuntimeDetail: vi.fn(),
}));
vi.mock('antdv-next', () => ({
Drawer: defineComponent({
name: 'MockDrawer',
props: {
open: Boolean,
title: String,
},
setup(props, { slots }) {
return () =>
props.open
? h('aside', [h('h2', props.title as string), slots.default?.()])
: null;
},
}),
Spin: defineComponent({
name: 'MockSpin',
props: {
spinning: Boolean,
},
setup(_, { slots }) {
return () => h('div', slots.default?.());
},
}),
Tag: defineComponent({
name: 'MockTag',
props: {
color: String,
},
setup(_, { slots }) {
return () => h('span', slots.default?.());
},
}),
}));
describe('napcat runtime profile drawer', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('loads and renders sanitized runtime profile evidence', async () => {
vi.mocked(getQqbotNapcatRuntimeDetail).mockResolvedValue({
accountId: 'account-1',
inspectionTimeoutMs: 15_000,
protocolProfile: {
reverseWsUrl: 'ws://host/qqbot/onebot/reverse?token=[REDACTED]',
},
runtimeProfile: {
imageRef: 'kt-napcat-desktop-cn@sha256:profiledigest',
locale: 'zh_CN.UTF-8',
shmSize: '512m',
},
});
const wrapper = mount(NapcatRuntimeProfileDrawer, {
props: {
account: {
connectStatus: 'online',
connectionMode: 'reverse-ws',
enabled: true,
id: 'account-1',
name: ¸»è´¦å<C2A6>·',
selfId: '10001',
},
open: true,
},
});
await flushPromises();
expect(getQqbotNapcatRuntimeDetail).toHaveBeenCalledWith('account-1');
expect(wrapper.text()).toContain('NapCat è¿<C3A8>行æ€<C3A6>è¯<C3A8>æ<EFBFBD>®');
expect(wrapper.text()).toContain('kt-napcat-desktop-cn');
expect(wrapper.text()).toContain('zh_CN.UTF-8');
expect(wrapper.text()).toContain('[REDACTED]');
});
});