dsh-sansheng-liubu/sansheng/test/nav.test.js

49 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 左侧入口的静态契约:必须走宿主正式槽位 sidebar.panellist,且不再挂在「新会话」行。
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const root = dirname(dirname(fileURLToPath(import.meta.url)))
test('左侧入口使用 sidebar.panellist,位置在记忆系统与更多之间(order 32)', async () => {
const source = await readFile(join(root, 'src/client/index.js'), 'utf8')
assert.match(source, /name: 'sidebar\.panellist'/)
assert.match(source, /order: NAV_ORDER/)
assert.match(source, /const NAV_ORDER = 32/)
assert.ok(!source.includes('sidebar.session.action'), '不得再占用新会话右侧槽位')
assert.ok(!source.includes('SanshengSessionAction'), '旧的新会话入口应已删除')
})
test('右侧工作台依赖宿主 sidebarRight,并在会话切换后重新固定', async () => {
const source = await readFile(join(root, 'src/client/index.js'), 'utf8')
assert.match(source, /export const inject = \[[^\]]*'workspaces'[^\]]*'sidebarRightTabs', 'sidebarRight'/)
assert.match(source, /right\.mounted\.subscribe/)
assert.match(source, /right\.openTabs\.getSnapshot/)
assert.match(source, /right\.focus\(row\.tabId\)/)
})
test('右侧栏有可发现的 guide 入口,并把标签会话传给工作台', async () => {
const source = await readFile(join(root, 'src/client/index.js'), 'utf8')
assert.match(source, /guide: \[\{/)
assert.match(source, /const sessionId = props && props\.sessionId/)
assert.match(source, /workspaceForSessionId\(sessionId\)/)
})
test('右栏展开失败会继续重试,guide 打开也会记为固定', async () => {
const source = await readFile(join(root, 'src/client/index.js'), 'utf8')
assert.match(source, /if \(revealRightTab\(sessionId\)\) \{ attempt = 0; return \}/)
assert.match(source, /right\.openTabs\.subscribe\(discoverPinnedTab\)/)
assert.match(source, /if \(existing\) return revealRightTab\(targetSessionId\)/)
assert.match(source, /if \(activeNow !== row\.tabId\) return false/)
})
test('右栏可见性按会话判断,布局列收起时主动展开', async () => {
const source = await readFile(join(root, 'src/client/index.js'), 'utf8')
assert.match(source, /'data-session-id': sessionId/)
assert.match(source, /function workbenchVisible\(sessionId\)/)
assert.match(source, /workbenchVisible\(sessionId\)/)
assert.match(source, /layout\.openRightbar\(true, false\)/)
})