* 新增自适应数值与窗口分析工具,提升交互体验 * 优化回收站模块逻辑,增加展示与选择功能 * 引入 Macaron 主题配置文件并更新 Tailwind 配置 * 精简基础组件代码,移除冗余样式与设置项 * 完善测试用例,覆盖 UI 系统与回收站工作流 * 更新多语言配置,支持功能变更后的文案需求
46 lines
2.7 KiB
JavaScript
46 lines
2.7 KiB
JavaScript
import { test, before, after } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { createServer } from 'vite'
|
|
import { createSSRApp, h } from 'vue'
|
|
import { renderToString } from 'vue/server-renderer'
|
|
import { createI18n } from 'vue-i18n'
|
|
let server, Button, Pagination, DateSelect, zh
|
|
before(async()=>{
|
|
server=await createServer({server:{middlewareMode:true,watch:null},appType:'custom'})
|
|
Button=(await server.ssrLoadModule('/src/components/common/BaseButton.vue')).default
|
|
Pagination=(await server.ssrLoadModule('/src/components/common/DataPagination.vue')).default
|
|
DateSelect=(await server.ssrLoadModule('/src/components/common/NativeDateSelect.vue')).default
|
|
zh=(await server.ssrLoadModule('/src/i18n/locales/zh-CN.ts')).default
|
|
})
|
|
after(async()=>await server?.close())
|
|
async function render(component,props,slots={}) {
|
|
const app=createSSRApp({render:()=>h(component,props,slots)})
|
|
app.use(createI18n({legacy:false,locale:'zh-CN',messages:{'zh-CN':zh}}))
|
|
return renderToString(app)
|
|
}
|
|
test('button variants retain their semantic role and disabled/loading behavior',async()=>{
|
|
for(const variant of ['primary','secondary','danger','success','outline']) {
|
|
const html=await render(Button,{variant},{default:()=> '刷新'})
|
|
assert.ok(html.includes(`fcb-button-${variant}`) && html.includes('fcb-action') && html.includes('刷新'))
|
|
}
|
|
const loading=await render(Button,{loading:true},{icon:()=>h('span','CUSTOM ICON'),default:()=> '刷新'})
|
|
assert.match(loading, /disabled/);assert.ok(!loading.includes('CUSTOM ICON'))
|
|
assert.match(await render(Button,{disabled:true}),/disabled/)
|
|
})
|
|
test('pagination retains accessible labels and correct edge controls',async()=>{
|
|
const first=await render(Pagination,{currentPage:1,pageSize:20,total:85})
|
|
assert.ok(first.includes('每页显示数量') && first.includes('20/页') && first.includes('1 / 5'))
|
|
assert.match(first,/<button[^>]*disabled[^>]*>[\s\S]*?上一页/)
|
|
const last=await render(Pagination,{currentPage:5,pageSize:20,total:85})
|
|
assert.ok(last.includes('第 81 到 85 条') && last.includes('5 / 5'))
|
|
assert.ok(!last.includes('col-span-3'))
|
|
})
|
|
test('date field keeps real selects, readable labels, leap days and optional time',async()=>{
|
|
const leap=await render(DateSelect,{modelValue:'2024-02-29',ariaLabel:'开始日期'})
|
|
assert.ok(leap.includes('开始日期年')&&leap.includes('开始日期月')&&leap.includes('开始日期日'))
|
|
assert.match(leap,/<option[^>]*value="29"/)
|
|
const ordinary=await render(DateSelect,{modelValue:'2025-02-28T14:30',ariaLabel:'过期时间',includeTime:true})
|
|
assert.ok(ordinary.includes('过期时间时')&&ordinary.includes('过期时间分'))
|
|
assert.ok(ordinary.includes('native-date-label'))
|
|
})
|