577 lines
32 KiB
TypeScript
577 lines
32 KiB
TypeScript
import { h, ref } from 'vue'
|
|
import { createMemoryHistory, createRouter } from 'vue-router'
|
|
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { NConfigProvider, NDrawer, NMenu, NModal, NPopover, NScrollbar, NTooltip } from 'naive-ui'
|
|
import App from '@/App.vue'
|
|
import WorkspacePage from '@/components/ui/WorkspacePage.vue'
|
|
import AppDialog from '@/components/ui/AppDialog.vue'
|
|
import AppDrawer from '@/components/ui/AppDrawer.vue'
|
|
import WorkspaceTools from '@/components/ui/WorkspaceTools.vue'
|
|
import ProjectLayout from '@/features/projects/ProjectLayout.vue'
|
|
import ConfirmAction from '@/features/workflows/ConfirmAction.vue'
|
|
import ThemeToggle from '@/components/ui/ThemeToggle.vue'
|
|
import { projectsApi } from '@/features/projects/api'
|
|
import { workflowExecutionApi } from '@/features/workflows/execution-api'
|
|
import { readFileSync } from 'node:fs'
|
|
import { drawerPanel } from '@/testing/naive'
|
|
import { readAllStyles } from '@/testing/styles'
|
|
|
|
let wrapper: VueWrapper | undefined
|
|
/** 导航布局测试没有后台任务,明确模拟项目级只读任务发现。 */
|
|
beforeEach(() => {
|
|
vi.spyOn(workflowExecutionApi, 'latest').mockResolvedValue(null)
|
|
})
|
|
afterEach(() => {
|
|
wrapper?.unmount()
|
|
wrapper = undefined
|
|
localStorage.clear()
|
|
document.body.innerHTML = ''
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
describe('管理后台组件边界', () => {
|
|
it('Tabs suffix 与标签共用导航行,窄屏换行但不产生外层滚动', () => {
|
|
// DOM 测试不计算坐标;保护对齐尺寸与容器断点,视觉验收仍需浏览器。
|
|
const css = readAllStyles()
|
|
expect(css).toMatch(/\.workspace-tabs > \.n-tabs-nav\s*\{[^}]*align-items:\s*stretch;/)
|
|
expect(css).toMatch(/\.workspace-tabs \.n-tabs-nav__suffix\s*\{[^}]*align-items:\s*center;/)
|
|
expect(css).toMatch(/\.tabs-toolbar-actions\s*\{[^}]*align-items:\s*center;[^}]*min-height:\s*40px;/)
|
|
expect(css).toMatch(
|
|
/\.tabs-toolbar-actions \.n-button\.icon-button\s*\{[^}]*width:\s*32px;[^}]*min-width:\s*32px;[^}]*height:\s*32px;[^}]*padding:\s*0/
|
|
)
|
|
expect(css).toContain('@container tabs-toolbar (max-width: 600px)')
|
|
expect(css).not.toContain('.result-toolbar > .n-button')
|
|
})
|
|
|
|
it('滚动边界样式包含 document 锁定和工作区收缩约束', () => {
|
|
// happy-dom 不计算视口几何;这里只保护 CSS 契约,真实滚动仍需浏览器验收。
|
|
const adminCss = readAllStyles()
|
|
expect(adminCss).toMatch(/html,\s*body,\s*#app,\s*\.app-provider\s*\{[^}]*overflow:\s*hidden/)
|
|
expect(adminCss).toMatch(/\.workspace-page\s*\{[^}]*min-height:\s*0;[^}]*overflow:\s*hidden/)
|
|
})
|
|
it('项目整体滚动仅用于手机阅读,弹窗素材选择保留有界滚动', () => {
|
|
const css = readAllStyles()
|
|
const mobileReading = /\.project-view:has\(\.mobile-reading-workspace\)\s*\{[^}]*\}/
|
|
expect(css.match(mobileReading)?.[0]).toContain('overflow-y: auto;')
|
|
/** 素材列表是弹窗内的局部滚动容器,不改变项目工作区滚动边界。 */
|
|
const assetPicker = /\.style-asset-picker\s*\{[^}]*\}/
|
|
expect(css.match(assetPicker)?.[0]).toContain('max-height: 280px;')
|
|
expect(css.match(assetPicker)?.[0]).toContain('overflow-y: auto;')
|
|
expect(css.replace(mobileReading, '').replace(assetPicker, '')).not.toMatch(
|
|
/overflow(?:-[xy])?\s*:\s*(?:auto|scroll)\b/
|
|
)
|
|
})
|
|
it('历史缩略图尺寸在非分层样式中覆盖 Naive 按钮,原图不能撑大预览或横向条目', () => {
|
|
// happy-dom 不计算几何;专门保护此前失效的层叠和固定尺寸约束。
|
|
const css = readFileSync('src/styles/admin.css', 'utf8')
|
|
expect(css).not.toContain('@layer')
|
|
const all = readAllStyles()
|
|
expect(all).toMatch(
|
|
/\.n-button\.image-history-item\s*\{[^}]*width:\s*128px;[^}]*min-width:\s*128px;[^}]*max-width:\s*128px;[^}]*flex:\s*0 0 128px;[^}]*padding:\s*6px/
|
|
)
|
|
expect(all).toMatch(/\.image-history-item \.asset-image\s*\{[^}]*height:\s*88px;[^}]*min-height:\s*0/)
|
|
expect(all).toMatch(
|
|
/\.asset-image\.asset-image-preview\s*\{[^}]*height:\s*min\(42dvh,\s*420px\);[^}]*aspect-ratio:\s*auto/
|
|
)
|
|
expect(all).toMatch(/\.image-history\.n-scrollbar\s*\{[^}]*max-width:\s*100%;[^}]*min-width:\s*0/)
|
|
expect(all).toMatch(/\.image-history-content\s*\{[^}]*display:\s*flex;[^}]*width:\s*max-content/)
|
|
})
|
|
it('选角卡片按可用宽度排列并覆盖按钮默认高度', () => {
|
|
// 保护间距与换行契约,真实宽高和暗色效果仍需浏览器验收。
|
|
const css = readAllStyles()
|
|
expect(css).toMatch(
|
|
/\.casting-list\s*\{[^}]*repeat\(auto-fit, minmax\(min\(100%, 260px\), 1fr\)\);[^}]*gap:\s*12px;[^}]*margin-top:\s*24px/
|
|
)
|
|
expect(css).toMatch(
|
|
/\.n-button\.casting-item\s*\{[^}]*height:\s*auto;[^}]*min-height:\s*76px;[^}]*padding:\s*12px 14px/
|
|
)
|
|
expect(css).toMatch(/\.casting-item-name\s*\{[^}]*overflow-wrap:\s*anywhere/)
|
|
expect(css).toMatch(/\.casting-item-status\s*\{[^}]*flex-shrink:\s*0/)
|
|
expect(css).toMatch(/\.n-button\.casting-item\.selected\s*\{[^}]*var\(--app-selected\)[^}]*var\(--app-accent\)/)
|
|
})
|
|
it('拆解结果独占剩余高度,手机正文交给项目内容区滚动', () => {
|
|
// 执行记录移除后,桌面保留有界滚动,手机结果容器随正文自然伸展。
|
|
const css = readAllStyles()
|
|
expect(css).toMatch(/\.breakdown-results-section\s*\{[^}]*flex:\s*1;[^}]*min-height:\s*0/)
|
|
expect(css).toMatch(/\.breakdown-results-section > \.result-toolbar\s*\{[^}]*flex-shrink:\s*0/)
|
|
expect(css).toMatch(
|
|
/\.breakdown-results-section > \.breakdown-content\s*\{[^}]*flex:\s*1;[^}]*height:\s*auto;[^}]*min-height:\s*0;[^}]*grid-template-columns:\s*minmax\(0, 1fr\);[^}]*grid-template-rows:\s*minmax\(0, 1fr\)/
|
|
)
|
|
expect(css).toMatch(
|
|
/@media \(max-width: 760px\)[\s\S]*?\.breakdown-workspace-page \.breakdown-content,[^{]*\{[^}]*height:\s*auto;[^}]*max-height:\s*none;[^}]*overflow:\s*visible/
|
|
)
|
|
expect(css).toMatch(/\.panel-scroll\.n-scrollbar\s*\{[^}]*height:\s*100%;[^}]*min-height:\s*0/)
|
|
})
|
|
it('标题与内容使用各自滚动容器,不随正文一起滚动', () => {
|
|
wrapper = mount(WorkspacePage, {
|
|
slots: { header: '<h2>固定操作区</h2>', default: '<p>正文</p>' }
|
|
})
|
|
expect(wrapper.get('.workspace-heading').text()).toBe('固定操作区')
|
|
const content = wrapper.get('.workspace-scroll')
|
|
expect(content.classes()).toContain('n-scrollbar')
|
|
expect(content.text()).toBe('正文')
|
|
expect(content.find('h2').exists()).toBe(false)
|
|
expect(wrapper.get('.workspace-heading-scroll .n-scrollbar-content').text()).toBe('固定操作区')
|
|
})
|
|
|
|
it('分栏工作区不再包一层整页滚动', () => {
|
|
wrapper = mount(WorkspacePage, {
|
|
props: { split: true },
|
|
slots: { default: '<aside>目录</aside><article>正文</article>' }
|
|
})
|
|
expect(wrapper.findComponent(NScrollbar).exists()).toBe(false)
|
|
expect(wrapper.get('.workspace-split').findAll(':scope > *')).toHaveLength(2)
|
|
})
|
|
|
|
it('图标主题菜单保留三种模式,设置入口位于侧栏底部并支持折叠', async () => {
|
|
const router = createRouter({
|
|
history: createMemoryHistory(),
|
|
routes: [
|
|
{ path: '/assets', component: { render: () => h('p', '资产库') } },
|
|
{ path: '/projects', component: { render: () => h('p', '项目列表') } },
|
|
{
|
|
path: '/projects/:projectId/:workspace',
|
|
component: { render: () => h(WorkspacePage, {}, () => '镜头详情') }
|
|
}
|
|
]
|
|
})
|
|
await router.push('/projects/test/production')
|
|
wrapper = mount(App, { attachTo: document.body, global: { plugins: [router] } })
|
|
await flushPromises()
|
|
expect(wrapper.findAll('.n-menu .n-menu-item')).toHaveLength(9)
|
|
expect(wrapper.get('#main-content .workspace-page').text()).toBe('镜头详情')
|
|
expect(wrapper.get('.theme-toggle').text()).toBe('')
|
|
expect(wrapper.get('.theme-toggle').attributes('aria-haspopup')).toBe('menu')
|
|
expect(wrapper.getComponent(ThemeToggle).findComponent(NTooltip).exists()).toBe(false)
|
|
expect(wrapper.get('.theme-toggle').attributes('title')).toBeUndefined()
|
|
expect(wrapper.get('.theme-toggle svg').classes()).toContain('lucide-monitor')
|
|
expect(wrapper.get('.admin-topbar [aria-controls="main-navigation"] svg').classes()).toContain(
|
|
'lucide-panel-left-close'
|
|
)
|
|
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
|
|
for (const [key, label, icon] of [
|
|
['dark', '暗黑模式', 'moon'],
|
|
['light', '浅色模式', 'sun'],
|
|
['system', '跟随系统', 'monitor']
|
|
] as const) {
|
|
await wrapper.get('.theme-toggle').trigger('click')
|
|
await flushPromises()
|
|
const option = [...document.querySelectorAll<HTMLElement>('.n-dropdown-option-body')].find(
|
|
item => item.textContent?.trim() === label
|
|
)
|
|
expect(option).toBeDefined()
|
|
option!.click()
|
|
await flushPromises()
|
|
expect(localStorage.getItem('drama-studio-theme')).toBe(key)
|
|
expect(wrapper.get('.theme-toggle svg').classes()).toContain(`lucide-${icon}`)
|
|
expect(wrapper.get('.theme-toggle').attributes('aria-label')).toBe(`主题模式:${label}`)
|
|
const expectedTheme = key === 'system' ? systemTheme : key
|
|
expect(document.documentElement.dataset.theme).toBe(expectedTheme)
|
|
expect(wrapper.getComponent(NConfigProvider).props('theme')?.name ?? 'light').toBe(expectedTheme)
|
|
}
|
|
expect(wrapper.find('.admin-topbar [aria-label="连接设置"]').exists()).toBe(false)
|
|
expect(wrapper.find('.admin-nav-scroll [aria-label="连接设置"]').exists()).toBe(false)
|
|
expect(wrapper.get('.admin-sider-footer [aria-label="连接设置"]').text()).toBe('连接设置')
|
|
expect(wrapper.getComponent(NMenu).props()).toMatchObject({
|
|
collapsed: false,
|
|
collapsedWidth: 64,
|
|
iconSize: 20,
|
|
collapsedIconSize: 20,
|
|
indent: 22,
|
|
rootIndent: 22
|
|
})
|
|
const firstMenuIcon = () => {
|
|
const [option] = wrapper!.getComponent(NMenu).props('options') as Array<{
|
|
icon: () => ReturnType<typeof h>
|
|
}>
|
|
return option!.icon()
|
|
}
|
|
expect(firstMenuIcon().type).not.toBe(NPopover)
|
|
|
|
expect(wrapper.get('.admin-sider-footer').findComponent(NPopover).exists()).toBe(false)
|
|
expect(wrapper.get('[aria-label="折叠侧栏"] svg').classes()).toContain('lucide-panel-left-close')
|
|
expect(wrapper.findAll('.studio-logo svg')).toHaveLength(2)
|
|
expect(wrapper.find('.studio-logo .lucide-film').exists()).toBe(true)
|
|
expect(wrapper.find('.studio-logo .lucide-sparkles').exists()).toBe(true)
|
|
await wrapper.get('[aria-label="折叠侧栏"]').trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.find('[aria-label="展开侧栏"]').exists()).toBe(true)
|
|
expect(wrapper.get('[aria-label="展开侧栏"] svg').classes()).toContain('lucide-panel-left-open')
|
|
expect(wrapper.getComponent(NMenu).props('collapsed')).toBe(false)
|
|
expect(firstMenuIcon().type).not.toBe(NPopover)
|
|
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 64px')
|
|
expect(wrapper.get('.admin-sider-footer').findComponent(NPopover).exists()).toBe(false)
|
|
// 悬停只展示整列名称,不能重新创建菜单或改变正文占用宽度。
|
|
const menuElement = wrapper.get('.n-menu').element
|
|
await wrapper.get('.admin-sider').trigger('mouseenter')
|
|
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 64px')
|
|
expect(wrapper.get('.n-menu').element).toBe(menuElement)
|
|
await wrapper.get('.admin-sider').trigger('mouseleave')
|
|
const labels = wrapper.findAll('.n-menu-item-content-header').map(item => item.text())
|
|
expect(labels).toEqual([
|
|
'我的剧本',
|
|
'资产库',
|
|
'剧本创作',
|
|
'剧本拆解',
|
|
'视觉风格',
|
|
'主体身份',
|
|
'形态图片',
|
|
'分镜设计',
|
|
'镜头生产'
|
|
])
|
|
// 切换布局时保留分镜工作区的 DOM,刷新后从已保存的偏好恢复。
|
|
const workspace = wrapper.get('#main-content .workspace-page').element
|
|
const layoutToggle = wrapper.get('.workspace-layout-toggle')
|
|
await layoutToggle.trigger('click')
|
|
await flushPromises()
|
|
const layoutOptions = [...document.querySelectorAll<HTMLElement>('.n-dropdown-option-body')]
|
|
.filter(option => option.closest('.n-dropdown-menu'))
|
|
.filter(option => ['居左', '居右', '居中'].includes(option.textContent?.trim() ?? ''))
|
|
expect(layoutOptions.map(option => option.textContent?.trim())).toEqual(['居左', '居右'])
|
|
layoutOptions[1]!.click()
|
|
await flushPromises()
|
|
expect(wrapper.get('.admin-layout').classes()).toContain('is-nav-right')
|
|
expect(wrapper.get('#main-content .workspace-page').element).toBe(workspace)
|
|
expect(layoutToggle.attributes('aria-label')).toBe('工作台布局:居右')
|
|
expect(wrapper.get('[aria-label="展开侧栏"] svg').classes()).toContain('lucide-panel-right-open')
|
|
wrapper.unmount()
|
|
wrapper = mount(App, { attachTo: document.body, global: { plugins: [router] } })
|
|
await flushPromises()
|
|
expect(wrapper.get('.admin-layout').classes()).toContain('is-nav-right')
|
|
|
|
const settings = wrapper.get('.admin-sider-footer [aria-label="连接设置"]')
|
|
expect(settings.text()).toBe('连接设置')
|
|
await settings.trigger('click')
|
|
await flushPromises()
|
|
expect(document.querySelector('[role="dialog"][aria-label="连接设置"]')).not.toBeNull()
|
|
expect(wrapper.findAll('.admin-nav-scroll .n-menu .n-menu-item')).toHaveLength(9)
|
|
})
|
|
|
|
it('侧栏菜单独立滚动,窄屏改为不占正文宽度的全屏固定层', () => {
|
|
const css = readAllStyles()
|
|
expect(css).toMatch(/\.admin-sider\s*\{[^}]*display:\s*flex;[^}]*flex-direction:\s*column;[^}]*height:\s*100%/)
|
|
expect(css).toMatch(
|
|
/\.admin-nav-scroll\.n-scrollbar\s*\{[^}]*flex:\s*1;[^}]*min-height:\s*0;[^}]*min-width:\s*var\(--admin-sider-expanded\)/
|
|
)
|
|
expect(css).toMatch(/\.admin-sider\.is-collapsed \.n-menu-item-content-header\s*\{[^}]*opacity:\s*0/)
|
|
expect(css).toMatch(/\.admin-sider\.is-collapsed \.n-menu-item-content__icon\s*\{[^}]*pointer-events:\s*none/)
|
|
expect(css).toMatch(/\.admin-sider-footer\s*\{[^}]*flex-shrink:\s*0/)
|
|
expect(css).toMatch(/\.admin-sider\.is-collapsed \.admin-settings-label\s*\{[^}]*opacity:\s*0/)
|
|
expect(css).toMatch(/\.admin-sider\.is-collapsed \.admin-brand-copy\s*\{[^}]*opacity:\s*0/)
|
|
expect(css).toMatch(/@media \(max-width: 800px\)[\s\S]*?\.admin-brand\s*\{[^}]*height:\s*48px/)
|
|
expect(css).toContain('@media (max-width: 800px)')
|
|
expect(css).toMatch(/\.admin-sider\s*\{[^}]*transition:\s*width\s+0\.32s/)
|
|
expect(css).toMatch(/\.workspace-tools-body\s*\{[^}]*padding-inline:\s*0;[^}]*padding-bottom:\s*20px/)
|
|
expect(css).toMatch(/\.app-dialog\s*\{[^}]*max-width:\s*calc\(100vw\s*-\s*32px\)/)
|
|
expect(css).toMatch(
|
|
/@media \(max-width: 800px\)[\s\S]*?\.admin-sider\s*\{[^}]*position:\s*fixed;[^}]*inset:\s*0;[^}]*width:\s*100%\s*!important;[^}]*transform:\s*translateX\(0\)/
|
|
)
|
|
expect(css).toMatch(
|
|
/\.admin-sider\.is-collapsed\s*\{[^}]*transform:\s*translateX\(-100%\);[^}]*visibility:\s*hidden;[^}]*pointer-events:\s*none/
|
|
)
|
|
expect(css).toMatch(/\.admin-layout > \.admin-main\s*\{[^}]*width:\s*100%;[^}]*min-width:\s*0/)
|
|
expect(css).toMatch(/\.mobile-sider-close\s*\{[^}]*display:\s*flex;[^}]*margin-right:\s*8px/)
|
|
expect(css).toContain('@media (prefers-reduced-motion: reduce)')
|
|
expect(css).toContain('.admin-sider.is-collapsed:is(:hover, :has(:focus-visible)) .n-menu-item-content-header')
|
|
expect(css).toContain('clip-path: inset(0);')
|
|
expect(css).toContain('transform: translateX(var(--admin-nav-reveal-offset));')
|
|
expect(css).toContain('--admin-nav-reveal-offset: -6px;')
|
|
expect(css).toContain('--admin-nav-reveal-offset: 6px;')
|
|
expect(css).not.toContain('.admin-sider-mask')
|
|
expect(css).not.toContain('.admin-sider.is-overlay')
|
|
for (const path of ['storyboard/StoryboardPage.vue', 'production/ProductionPage.vue']) {
|
|
const source = readFileSync(`src/features/${path}`, 'utf8')
|
|
expect(source).not.toContain('<span>剧集</span')
|
|
expect(source).toMatch(/aria-label="选择(?:分镜|生产)剧集"/)
|
|
}
|
|
})
|
|
|
|
it('窄屏导航关闭时移出视口,打开后全屏显示并可从内部关闭', async () => {
|
|
const realMatchMedia = window.matchMedia.bind(window)
|
|
vi.stubGlobal('matchMedia', (query: string) => {
|
|
if (query.includes('max-width: 800px')) {
|
|
return {
|
|
matches: true,
|
|
media: query,
|
|
addEventListener() {},
|
|
removeEventListener() {},
|
|
addListener() {},
|
|
removeListener() {},
|
|
dispatchEvent() {
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
return realMatchMedia(query)
|
|
})
|
|
const router = createRouter({
|
|
history: createMemoryHistory(),
|
|
routes: [
|
|
{ path: '/assets', component: { render: () => h('p', '资产库') } },
|
|
{ path: '/projects', component: { render: () => h('p', '项目列表') } },
|
|
{
|
|
path: '/projects/:projectId/:workspace',
|
|
component: { render: () => h(WorkspacePage, {}, () => '镜头详情') }
|
|
}
|
|
]
|
|
})
|
|
await router.push('/projects/test/production')
|
|
wrapper = mount(App, { attachTo: document.body, global: { plugins: [router] } })
|
|
await flushPromises()
|
|
expect(wrapper.findAll('.admin-sider')).toHaveLength(1)
|
|
expect(wrapper.get('.admin-sider').classes()).toContain('is-collapsed')
|
|
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 100%')
|
|
expect(wrapper.get('.admin-sider').attributes('aria-hidden')).toBe('true')
|
|
expect(wrapper.find('.admin-sider-mask').exists()).toBe(false)
|
|
expect(wrapper.find('.admin-nav-drawer').exists()).toBe(false)
|
|
expect(wrapper.getComponent(NMenu).props()).toMatchObject({
|
|
collapsedWidth: 64,
|
|
indent: 20,
|
|
rootIndent: 20
|
|
})
|
|
const [mobileOption] = wrapper.getComponent(NMenu).props('options') as Array<{
|
|
icon: () => ReturnType<typeof h>
|
|
}>
|
|
expect(mobileOption!.icon().type).not.toBe(NPopover)
|
|
expect(wrapper.get('.admin-sider-footer').findComponent(NPopover).exists()).toBe(false)
|
|
const collapsedBrand = wrapper.get('.admin-brand')
|
|
expect(collapsedBrand.classes()).toContain('is-collapsed')
|
|
expect(collapsedBrand.text()).toContain('短剧工作台')
|
|
const collapsedSettings = wrapper.get('.admin-sider-footer [aria-label="连接设置"]')
|
|
expect(collapsedSettings.text()).toBe('连接设置')
|
|
expect(collapsedSettings.classes()).toContain('is-collapsed')
|
|
expect(wrapper.get('.admin-topbar [aria-label="打开主菜单"] svg').classes()).toContain('lucide-panel-left-open')
|
|
await wrapper.get('.admin-topbar [aria-label="打开主菜单"]').trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.findAll('.admin-sider')).toHaveLength(1)
|
|
expect(wrapper.get('.admin-sider').classes()).not.toContain('is-collapsed')
|
|
expect(wrapper.get('.admin-sider').classes()).not.toContain('is-overlay')
|
|
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 100%')
|
|
expect(wrapper.get('.admin-sider').attributes('aria-hidden')).toBeUndefined()
|
|
expect(wrapper.find('.admin-sider-mask').exists()).toBe(false)
|
|
expect(wrapper.get('.admin-sider').findAll('.n-menu .n-menu-item')).toHaveLength(9)
|
|
expect(wrapper.get('.admin-topbar [aria-label="关闭主菜单"]').attributes('aria-expanded')).toBe('true')
|
|
expect(wrapper.get('.admin-topbar [aria-label="关闭主菜单"] svg').classes()).toContain(
|
|
'lucide-panel-left-close'
|
|
)
|
|
const expandedBrand = wrapper.get('.admin-brand')
|
|
expect(expandedBrand.classes()).not.toContain('is-collapsed')
|
|
expect(expandedBrand.text()).toContain('短剧工作台')
|
|
const expandedSettings = wrapper.get('.admin-sider-footer [aria-label="连接设置"]')
|
|
expect(expandedSettings.text()).toBe('连接设置')
|
|
expect(expandedSettings.classes()).not.toContain('is-collapsed')
|
|
expect(wrapper.get('.mobile-sider-close').attributes('aria-label')).toBe('关闭主菜单')
|
|
await wrapper.get('.mobile-sider-close').trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.get('.admin-sider').classes()).toContain('is-collapsed')
|
|
expect(wrapper.get('.admin-sider').attributes('style')).toContain('width: 100%')
|
|
expect(wrapper.get('.admin-sider').attributes('aria-hidden')).toBe('true')
|
|
expect(wrapper.get('.admin-brand').text()).toContain('短剧工作台')
|
|
expect(wrapper.get('.admin-sider-footer [aria-label="连接设置"]').text()).toBe('连接设置')
|
|
})
|
|
|
|
it.each([
|
|
['弹窗', AppDialog, '.app-dialog .n-card__footer'],
|
|
['全屏抽屉', AppDrawer, '.app-drawer .n-drawer-footer']
|
|
] as const)('%s 默认底栏可关闭,提交期间继续锁定所有关闭入口', async (kind, component, selector) => {
|
|
wrapper = mount(component, {
|
|
attachTo: document.body,
|
|
props: { open: true, title: '确认生图', description: '费用确认', busy: true },
|
|
slots: { default: '<p>内容</p>' }
|
|
})
|
|
await flushPromises()
|
|
const frame = kind === '弹窗' ? wrapper.getComponent(NModal) : wrapper.getComponent(NDrawer)
|
|
expect(frame.props()).toMatchObject({
|
|
maskClosable: false,
|
|
closeOnEsc: false
|
|
})
|
|
expect(
|
|
document.querySelector(
|
|
kind === '弹窗' ? '.app-dialog .n-card-header__close' : '.app-drawer .n-drawer-header__close'
|
|
)
|
|
).toBeNull()
|
|
const footer = document.querySelector<HTMLElement>(selector)
|
|
expect(footer).not.toBeNull()
|
|
const close = new DOMWrapper(footer!).get<HTMLButtonElement>('button')
|
|
expect(close.text()).toBe('关闭')
|
|
expect(close.element.disabled).toBe(true)
|
|
await close.trigger('click')
|
|
expect(wrapper.emitted('update:open')).toBeUndefined()
|
|
await wrapper.setProps({ busy: false })
|
|
await close.trigger('click')
|
|
expect(wrapper.emitted('update:open')?.at(-1)).toEqual([false])
|
|
})
|
|
|
|
it('操作弹窗挂载 body 并限制视口尺寸,开关保留列表与配置草稿', async () => {
|
|
/** 配置由工作区拥有,弹窗开关不会清空用户填写的数据。 */
|
|
const draft = ref('')
|
|
wrapper = mount(WorkspacePage, {
|
|
attachTo: document.body,
|
|
props: { split: true, compact: true },
|
|
slots: {
|
|
header: () =>
|
|
h(WorkspaceTools, { title: '测试操作' }, () =>
|
|
h('input', {
|
|
'aria-label': '配置草稿',
|
|
value: draft.value,
|
|
/** 输入后的草稿保存在工作区,关闭弹窗后仍可恢复。 */
|
|
onInput: (event: Event) => {
|
|
draft.value = (event.target as HTMLInputElement).value
|
|
}
|
|
})
|
|
),
|
|
default: '<article class="test-list">主体列表</article>'
|
|
}
|
|
})
|
|
const list = wrapper.get('.test-list').element
|
|
expect(wrapper.find('.workspace-tools-drawer').exists()).toBe(false)
|
|
expect(wrapper.get('.workspace-heading').find('[data-workspace-tools]').exists()).toBe(true)
|
|
await wrapper.get('[data-workspace-tools]').trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.getComponent(AppDialog).props('wide')).toBe(true)
|
|
expect(wrapper.getComponent(NModal).props()).toMatchObject({
|
|
preset: 'card',
|
|
blockScroll: true,
|
|
trapFocus: true,
|
|
maskClosable: true,
|
|
closeOnEsc: true
|
|
})
|
|
expect(wrapper.find('.app-dialog').exists()).toBe(false)
|
|
const container = drawerPanel().element.closest('.n-modal-container')!
|
|
expect(container.parentElement).toBe(document.body)
|
|
expect(container.closest('main, .admin-content, .workspace-page')).toBeNull()
|
|
expect(container.querySelector('.n-modal-mask')).not.toBeNull()
|
|
expect(drawerPanel().find('.dialog-body-scroll .n-scrollbar-container').exists()).toBe(true)
|
|
await drawerPanel().get('input[aria-label="配置草稿"]').setValue('保留配置')
|
|
await drawerPanel().get('.n-card-header__close').trigger('click')
|
|
await flushPromises()
|
|
expect(wrapper.getComponent(NModal).props('show')).toBe(false)
|
|
expect(wrapper.get('.test-list').element).toBe(list)
|
|
await wrapper.get('[data-workspace-tools]').trigger('click')
|
|
await flushPromises()
|
|
expect(drawerPanel().get<HTMLInputElement>('input[aria-label="配置草稿"]').element.value).toBe('保留配置')
|
|
const reopenedContainer = drawerPanel().element.closest('.n-modal-container')!
|
|
// Naive 的 clickoutside 由完整按下/抬起事件触发,单独 click 不代表遮罩交互。
|
|
const mask = reopenedContainer.querySelector<HTMLElement>('.n-modal-mask')!
|
|
mask.dispatchEvent(new MouseEvent('mousedown', { bubbles: true }))
|
|
mask.dispatchEvent(new MouseEvent('mouseup', { bubbles: true }))
|
|
await flushPromises()
|
|
expect(wrapper.getComponent(NModal).props('show')).toBe(false)
|
|
expect(wrapper.get('.test-list').element).toBe(list)
|
|
wrapper.unmount()
|
|
wrapper = undefined
|
|
expect(document.querySelector('.n-modal-container')).toBeNull()
|
|
})
|
|
|
|
it('服务端制作阶段就绪后解锁全部左侧链接,标题保留制作前检查与项目配置入口', async () => {
|
|
const detail = vi.spyOn(projectsApi, 'detail').mockResolvedValue({
|
|
id: 'navigation-test',
|
|
durationMode: 'auto',
|
|
episodeCount: 1,
|
|
targetDurationSeconds: null,
|
|
episodeMinSeconds: null,
|
|
episodeMaxSeconds: null,
|
|
title: '导航测试项目',
|
|
topic: '测试主题',
|
|
style: null,
|
|
status: 'completed',
|
|
createdAt: '',
|
|
updatedAt: '',
|
|
episodes: [],
|
|
characters: [],
|
|
world: null
|
|
})
|
|
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
|
|
vi.spyOn(projectsApi, 'stageReadiness').mockResolvedValue({
|
|
projectId: 'navigation-test',
|
|
script: { ready: true, reason: null },
|
|
breakdown: { ready: true, reason: null },
|
|
preparation: { ready: true, reason: null },
|
|
visualStyle: { ready: true, reason: null },
|
|
identity: { ready: true, reason: null },
|
|
subjectAssets: { ready: true, reason: null },
|
|
storyboard: { ready: true, reason: null }
|
|
})
|
|
const paths = [
|
|
'create-drama',
|
|
'breakdown',
|
|
'visual-style',
|
|
'subject-identity',
|
|
'subject-images',
|
|
'storyboard',
|
|
'production'
|
|
]
|
|
const router = createRouter({
|
|
history: createMemoryHistory(),
|
|
routes: [
|
|
{ path: '/assets', component: { render: () => h('p', '资产库') } },
|
|
{ path: '/projects', component: { render: () => h('p', '项目列表') } },
|
|
{
|
|
path: '/projects/:projectId',
|
|
component: ProjectLayout,
|
|
children: paths.map(path => ({
|
|
path,
|
|
component: { render: () => h(WorkspacePage, {}, () => path) }
|
|
}))
|
|
}
|
|
]
|
|
})
|
|
await router.push('/projects/navigation-test/create-drama')
|
|
wrapper = mount(App, { attachTo: document.body, global: { plugins: [router] } })
|
|
await flushPromises()
|
|
expect(wrapper.find('[aria-label="项目工作流"]').exists()).toBe(false)
|
|
expect(wrapper.get('.project-title').text()).toBe('导航测试项目')
|
|
for (const path of paths) {
|
|
await wrapper.get(`.n-menu a[href="/projects/navigation-test/${path}"]`).trigger('click')
|
|
await flushPromises()
|
|
expect(router.currentRoute.value.path).toBe('/projects/navigation-test/' + path)
|
|
expect(wrapper.get('.project-view .workspace-page').text()).toBe(path)
|
|
}
|
|
expect(detail).toHaveBeenCalledOnce()
|
|
expect(wrapper.findAll('.project-header .n-button').map(button => button.text())).toEqual([
|
|
'制作前检查',
|
|
'项目配置'
|
|
])
|
|
expect(wrapper.find('.project-header [aria-label="刷新项目"]').exists()).toBe(false)
|
|
expect(wrapper.find('.project-header .n-tag').exists()).toBe(false)
|
|
})
|
|
|
|
it('公共弹窗状态仅在标题旁提示,默认不显示图标,切换状态不影响正文', async () => {
|
|
wrapper = mount(AppDialog, {
|
|
attachTo: document.body,
|
|
props: { open: true, title: '操作结果' },
|
|
slots: { default: '<p>请核对当前内容。</p>' }
|
|
})
|
|
await flushPromises()
|
|
expect(document.querySelector('.n-card-header [role="img"]')).toBeNull()
|
|
await wrapper.setProps({ status: 'warning' })
|
|
expect(document.querySelector('.n-card-header [aria-label="警告"]')).not.toBeNull()
|
|
await wrapper.setProps({ status: 'success' })
|
|
expect(document.querySelector('.n-card-header [aria-label="警告"]')).toBeNull()
|
|
expect(document.querySelector('.n-card-header [aria-label="成功"]')).not.toBeNull()
|
|
await wrapper.setProps({ status: 'error' })
|
|
expect(document.querySelector('.n-card-header [aria-label="成功"]')).toBeNull()
|
|
expect(document.querySelector('.n-card-header [aria-label="错误"]')).not.toBeNull()
|
|
expect(document.querySelector('.dialog-body-scroll')?.textContent).toContain('请核对当前内容。')
|
|
})
|
|
|
|
it('确认按钮有稳定根元素,操作说明始终位于正文,标题说明可省略', async () => {
|
|
wrapper = mount(ConfirmAction, {
|
|
props: { label: '测试操作', description: '仅展示,不提交请求' },
|
|
attrs: { class: 'mt-4' }
|
|
})
|
|
expect(wrapper.element.tagName).toBe('SPAN')
|
|
expect(wrapper.classes()).toContain('confirm-action')
|
|
expect(wrapper.classes()).toContain('mt-4')
|
|
expect(wrapper.get('button').text()).toBe('测试操作')
|
|
await wrapper.get('button').trigger('click')
|
|
await flushPromises()
|
|
const dialog = document.querySelector('.app-dialog')!
|
|
expect(dialog.querySelector('.n-card-header [aria-label="警告"]')).not.toBeNull()
|
|
expect(dialog.querySelector('.n-card-header')?.textContent).not.toContain('仅展示,不提交请求')
|
|
expect(dialog.querySelector('.dialog-body-scroll')?.textContent).toContain('仅展示,不提交请求')
|
|
expect(readAllStyles()).toMatch(/\.production-pipeline-card\s*\{[^}]*display:\s*grid;[^}]*gap:\s*16px;/)
|
|
})
|
|
})
|