cmvr-wms/ruoyi-ui-vue3/tests/unit/business-assistant-launcher.test.mjs
lixiaolong a82258561b feat(auth): 添加认证cookie名称配置并优化表单布局
- 在 .env.production 中新增 VITE_AUTH_COOKIE_NAME 配置项用于设置认证cookie名称
- 将 AcceptanceException.vue 中的表单标签宽度从固定90px改为自动适配
- 在 ActionDialog.vue 中将多个表单项标记为必填项并调整标签宽度为自动适配
- 重构 ActionHistory.vue 中的按钮布局结构并添加表格列样式类名
- 更新 api-contract-audit.cjs 添加生产任务和BOM相关接口的契约测试
- 修改 auth.js 使用动态认证cookie键名替换硬编码的Admin-Token
- 调整系统角色授权用户页面的表单布局和表格样式类名
- 优化 ReceiptDialog Batch 组件的对话框尺寸、表单验证和分页功能
2026-10-16 15:30:10 +08:00

47 lines
3.1 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { assistantLauncherPreferences, assistantLauncherRect, assistantSnapLauncher, readAssistantLauncherPreferences, saveAssistantLauncherPreferences } from '../../src/utils/assistant-launcher.js'
test('entry starts expanded and fully visible near the lower right', () => {
assert.deepEqual(assistantLauncherPreferences(), { side: 'right', y: 1, collapsed: false })
assert.deepEqual(assistantLauncherRect(null, { width: 1280, height: 800 }), { left: 1216, top: 736, width: 52, height: 52 })
})
test('release snaps to either edge while retaining vertical placement', () => {
const viewport = { width: 1280, height: 800 }
const left = assistantSnapLauncher({ left: 240, top: 300 }, viewport, {})
const right = assistantSnapLauncher({ left: 800, top: 300 }, viewport, {})
assert.equal(left.side, 'left'); assert.equal(right.side, 'right')
assert.equal(assistantLauncherRect(left, viewport).top, 300)
assert.equal(assistantLauncherRect(right, viewport).top, 300)
})
test('collapsing always leaves a visible, recoverable edge tab', () => {
const viewport = { width: 1280, height: 800 }
assert.deepEqual(assistantLauncherRect({ side: 'right', y: 1, collapsed: true }, viewport), { left: 1252, top: 724, width: 28, height: 64 })
assert.equal(assistantLauncherRect({ side: 'left', collapsed: true }, viewport).left, 0)
})
test('extreme dragging and smaller screens cannot lose the entry off-screen', () => {
for (const viewport of [{ width: 1280, height: 800 }, { width: 320, height: 240 }, { width: 20, height: 30 }]) {
for (const collapsed of [true, false]) {
const rect = assistantLauncherRect({ collapsed, y: 999 }, viewport, { left: -999, top: 9999 })
assert.ok(rect.left >= 0 && rect.top >= 0)
assert.ok(rect.left + rect.width <= viewport.width && rect.top + rect.height <= viewport.height)
}
}
})
test('entry preferences are isolated per account and recover safely from bad or blocked storage', () => {
const map = new Map(), storage = { getItem: key => map.get(key), setItem: (key, value) => map.set(key, value) }
saveAssistantLauncherPreferences(1, { side: 'left', y: .4, collapsed: true }, storage)
assert.deepEqual(readAssistantLauncherPreferences(1, storage), { side: 'left', y: .4, collapsed: true })
assert.deepEqual(readAssistantLauncherPreferences(2, storage), assistantLauncherPreferences())
map.set('business-assistant:launcher:1', 'bad-json')
assert.deepEqual(readAssistantLauncherPreferences(1, storage), assistantLauncherPreferences())
const blocked = { getItem() { throw Error('blocked') }, setItem() { throw Error('blocked') } }
assert.doesNotThrow(() => saveAssistantLauncherPreferences(1, {}, blocked))
assert.deepEqual(readAssistantLauncherPreferences(1, blocked), assistantLauncherPreferences())
})
test('homepage no longer duplicates the global assistant entry', () => {
const home = readFileSync(new URL('../../src/views/businessHome/index.vue', import.meta.url), 'utf8')
assert.doesNotMatch(home, /home-assistant-entry|canAssistant|openAssistant|useBusinessAssistantStore/)
})