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
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// @vitest-environment jsdom
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { nextTick } from 'vue'
|
||||
import { defineComponent, nextTick } from 'vue'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import ArcoVue from '@arco-design/web-vue'
|
||||
|
||||
const mockPush = vi.hoisted(() => vi.fn())
|
||||
const mockFetchCurrentUser = vi.hoisted(() => vi.fn())
|
||||
@@ -27,30 +28,23 @@ vi.mock('@/api/client', () => ({
|
||||
getApiKey: mockGetApiKey,
|
||||
}))
|
||||
|
||||
vi.mock('naive-ui', async () => {
|
||||
const { defineComponent, h } = await import('vue')
|
||||
return {
|
||||
NModal: defineComponent({
|
||||
props: { show: Boolean, title: String },
|
||||
setup(props, { slots }) {
|
||||
return () => props.show
|
||||
? h('div', { class: 'modal' }, [
|
||||
h('h2', props.title),
|
||||
slots.default?.(),
|
||||
h('div', { class: 'modal-actions' }, slots.action?.()),
|
||||
])
|
||||
: null
|
||||
},
|
||||
}),
|
||||
NButton: defineComponent({
|
||||
emits: ['click'],
|
||||
setup(_props, { emit, slots }) {
|
||||
return () => h('button', { onClick: () => emit('click') }, slots.default?.())
|
||||
},
|
||||
}),
|
||||
}
|
||||
// a-modal teleports to body in jsdom, so render it inline through a stub keyed
|
||||
// by Arco's internal component name.
|
||||
const AModalStub = defineComponent({
|
||||
name: 'Modal',
|
||||
props: { visible: Boolean, title: String },
|
||||
emits: ['update:visible'],
|
||||
template: '<div v-if="visible" class="arco-modal-stub"><h2>{{ title }}</h2><slot /><div class="modal-actions"><slot name="footer" /></div></div>',
|
||||
})
|
||||
|
||||
const arcoGlobal = { plugins: [ArcoVue], stubs: { Modal: AModalStub } }
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
import DefaultCredentialPrompt from '@/components/auth/DefaultCredentialPrompt.vue'
|
||||
|
||||
describe('DefaultCredentialPrompt', () => {
|
||||
@@ -74,13 +68,14 @@ describe('DefaultCredentialPrompt', () => {
|
||||
requiresCredentialChange: true,
|
||||
})
|
||||
|
||||
const wrapper = mount(DefaultCredentialPrompt)
|
||||
const wrapper = mount(DefaultCredentialPrompt, { global: arcoGlobal })
|
||||
await flushPromises()
|
||||
await nextTick()
|
||||
|
||||
expect(mockFetchCurrentUser).toHaveBeenCalledOnce()
|
||||
expect(wrapper.text()).toContain('login.defaultCredentialMessage')
|
||||
await wrapper.findAll('button')[1].trigger('click')
|
||||
|
||||
await buttonByText(wrapper, 'login.defaultCredentialAction').trigger('click')
|
||||
expect(mockPush).toHaveBeenCalledWith({ name: 'hermes.settings', query: { tab: 'account' } })
|
||||
})
|
||||
|
||||
@@ -88,7 +83,7 @@ describe('DefaultCredentialPrompt', () => {
|
||||
routeState.fullPath = '/'
|
||||
routeState.name = 'login'
|
||||
|
||||
mount(DefaultCredentialPrompt)
|
||||
mount(DefaultCredentialPrompt, { global: arcoGlobal })
|
||||
await Promise.resolve()
|
||||
|
||||
expect(mockFetchCurrentUser).not.toHaveBeenCalled()
|
||||
|
||||
Reference in New Issue
Block a user