Files
hermes-ui/tests/client/plugins-view.test.ts
T
toor 836d0228d2 Phase 007: migrate every remaining view from naive-ui to Arco Design Vue
The project now has exactly one UI library. Every naive-ui component in
packages/client/src is replaced by its Arco equivalent across 24 views and
roughly 80 components, and naive-ui is dropped from package.json along with
its transitive vueuc / @css-render / vdirs / seemly dependencies.

The migration is rendering-layer only. No store logic, no API contract, and
no /chat-run payload was touched.

Three classes of leftover were invisible to `grep naive-ui` and are now
covered by tests/client/no-naive-ui.test.ts, which asserts all three:
  - dead .n-* class names in style blocks
  - dead --n-* custom properties
  - naive-ui in package.json

Notable behavioural traps handled along the way, recorded in
docs/arco-migration-rules.md:
  - a-input-password defaults to masked; passing default-visibility="false"
    would have exposed API keys in clear text
  - a-upload fires a real XHR unless auto-upload is false
  - nested Trigger components fight over the first element child, so the
    group-chat settings dropdown was flattened
  - Arco renders tooltip default-slot text inline, which was silently
    collapsing the chat and group-chat toolbars
2026-10-18 22:57:25 +08:00

115 lines
3.3 KiB
TypeScript

// @vitest-environment jsdom
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import ArcoVue from '@arco-design/web-vue'
const messageMock = vi.hoisted(() => ({
success: vi.fn(),
error: vi.fn(),
}))
const profilesStoreMock = vi.hoisted(() => ({
activeProfileName: 'default',
profiles: [{ name: 'default' }],
fetchProfiles: vi.fn(),
}))
const fetchPluginsMock = vi.hoisted(() => vi.fn())
const setPluginEnabledMock = vi.hoisted(() => vi.fn())
vi.mock('@/stores/hermes/profiles', () => ({
useProfilesStore: () => profilesStoreMock,
}))
vi.mock('@/api/hermes/plugins', () => ({
fetchPlugins: fetchPluginsMock,
setPluginEnabled: setPluginEnabledMock,
}))
vi.mock('vue-i18n', () => ({
useI18n: () => ({
t: (key: string, values?: Record<string, any>) => values?.name ? `${key}:${values.name}` : key,
te: () => false,
}),
}))
vi.mock('@/composables/useMessage', () => ({ useMessage: () => messageMock }))
import PluginsView from '@/views/hermes/PluginsView.vue'
const arcoGlobal = { plugins: [ArcoVue] }
function buttonByText(wrapper: any, text: string) {
const button = wrapper.findAll('button').find((node: any) => node.text().trim() === text)
if (!button) throw new Error(`no button labelled "${text}"`)
return button
}
describe('PluginsView management actions', () => {
beforeEach(() => {
vi.clearAllMocks()
profilesStoreMock.activeProfileName = 'default'
profilesStoreMock.profiles = [{ name: 'default' }]
fetchPluginsMock.mockResolvedValue({
plugins: [{
key: 'local-plugin',
name: 'local-plugin',
kind: 'standalone',
source: 'user',
configStatus: 'not-enabled',
effectiveStatus: 'inactive',
version: '',
description: '',
author: '',
path: '/tmp/local-plugin',
providesTools: [],
providesHooks: [],
requiresEnv: [],
}],
warnings: [],
metadata: null,
})
setPluginEnabledMock.mockResolvedValue({ key: 'local-plugin', enabled: true })
})
it('enables manageable standalone plugins and refreshes the inventory', async () => {
const wrapper = mount(PluginsView, { global: arcoGlobal })
await flushPromises()
await buttonByText(wrapper, 'common.enable').trigger('click')
await flushPromises()
expect(setPluginEnabledMock).toHaveBeenCalledWith('local-plugin', true)
expect(messageMock.success).toHaveBeenCalledWith('plugins.enableSuccess:local-plugin')
expect(fetchPluginsMock).toHaveBeenCalledTimes(2)
})
it('leaves bundled plugins read-only', async () => {
fetchPluginsMock.mockResolvedValueOnce({
plugins: [{
key: 'bundled-plugin',
name: 'bundled-plugin',
kind: 'standalone',
source: 'bundled',
configStatus: 'auto',
effectiveStatus: 'auto-active',
version: '',
description: '',
author: '',
path: '',
providesTools: [],
providesHooks: [],
requiresEnv: [],
}],
warnings: [],
metadata: null,
})
const wrapper = mount(PluginsView, { global: arcoGlobal })
await flushPromises()
expect(wrapper.text()).toContain('plugins.managedElsewhere')
expect(wrapper.text()).not.toContain('common.disable')
})
})