Files
knowledge-governance/web/src/QARegions.test.tsx
T
姚章浩 154b0b62ad
build / build (push) Successful in 1m20s
feat(qaops): 完成区域统计与部门绑定六项联动
新增北京时间自然周校验与缓存隔离,默认展开到业务二级部门。
选中部门在统计页就地绑定;区域名称列表原位增删改,双版本锁、自动预览、独立读回及删除确认。
筛选和两张区域看板使用同一已保存目录,删除失效筛选回全部。

验证:完整 make verify、全 mirror 隔离 PostgreSQL race、自然周边界与缓存键负例通过;真实恢复库327部门逐行对拍及六项浏览器验收通过。
schema57无迁移,不改真实公司区域绑定或原始问答,不连接DobotAI生产源库;PNG导出本轮不冒充已验证。
2026-10-19 23:41:01 +08:00

130 lines
5.1 KiB
TypeScript

import { renderToStaticMarkup } from 'react-dom/server'
// @ts-expect-error The test runner provides Node; the browser bundle intentionally omits @types/node.
import { readFileSync } from 'node:fs'
import { describe, expect, it, vi } from 'vitest'
import { RegionCatalogView } from './QARegions'
import { parseOrganization } from './qaOrg'
const state = parseOrganization({
state: 'ready',
directory_id: 'd',
directory_source: 'weekly_report_snapshot',
directory_synced_at: '2026-09-27T14:03:44Z',
revision_id: 'r',
updated_by: 'fixture-admin',
updated_at: null,
rules: [{ department_id: 'a', region: 'APAC' }],
view: {
departments: [
{
id: 'a',
parent_id: '',
name: '<script>test</script>',
path: '示例公司/<script>test</script>',
region: 'APAC',
explicit: true,
inherited_from: '',
},
],
regions: { 国内工业: 0, APAC: 1, EMEA: 0, America: 0 },
total_people: 2,
unassigned_people: 0,
conflicting_people: 1,
missing_departments: [],
},
})
const props = {
state,
preview: null,
rules: state.rules,
busy: false,
error: '',
notice: '',
dirty: false,
onPreview: vi.fn(),
onSave: vi.fn(),
onReload: vi.fn(),
onRemoveMissing: vi.fn(),
}
describe('region catalog settings', () => {
it('uses a region-name list without a second department mapping page', () => {
const html = renderToStaticMarkup(<RegionCatalogView {...props} />)
expect(html).toContain('区域名称列表')
expect(html).toContain('保存区域设置')
expect(html).not.toContain('qa-region-table')
expect(html).not.toContain('批量归属')
expect(html).not.toContain('全选当前列表')
})
it('shows direct binding counts and enters local confirmation before removing a bound region', () => {
const regions = [
{ id: 'APAC', name: 'Assigned' },
{ id: 'spare', name: 'Spare' },
]
const html = renderToStaticMarkup(<RegionCatalogView {...props} regions={regions} />)
expect(html).toContain('删除区域 Spare')
expect(html).toContain('直接绑定 1 个部门')
expect(html).not.toMatch(/aria-label="删除区域 Assigned"[^>]*disabled=""/)
expect(html).not.toContain('确认删除')
})
it('shows editable saved region names but keeps department binding out of the settings list', () => {
const custom = {
...state,
regions: [{ id: 'APAC', name: '国外工业Amercia' }],
view: { ...state.view, regions: { APAC: 1 } },
}
const html = renderToStaticMarkup(<RegionCatalogView {...props} state={custom} />)
for (const label of ['区域设置', '添加区域', '区域名称列表', '保存区域设置', '国外工业Amercia'])
expect(html).toContain(label)
for (const removed of ['一级部门', '二级部门', '批量归属', '全选当前列表', 'qa-region-table'])
expect(html).not.toContain(removed)
expect(html).not.toContain('将 示例公司/')
})
it('shows real synchronization stages without inventing progress and protects dirty drafts', () => {
const syncStatus = {
configured: true,
worker_ready: true,
job: {
id: 'j',
state: 'running' as const,
attempt: 1,
max_attempts: 3,
updated_at: '2026-10-17T08:00:00Z',
error_code: '',
result: null,
},
}
const html = renderToStaticMarkup(<RegionCatalogView {...props} syncStatus={syncStatus} />)
expect(html).toContain('正在读取并校验通讯录')
expect(html).not.toMatch(/\d+%/)
expect(html).toMatch(/disabled=""[^>]*>同步通讯录/)
const dirty = renderToStaticMarkup(
<RegionCatalogView {...props} dirty syncStatus={{ configured: true, worker_ready: true, job: null }} />
)
expect(dirty).toContain('未保存的区域修改')
expect(dirty).toMatch(/disabled=""[^>]*>同步通讯录/)
})
it('uses a responsive catalog list with wrapping warnings and no obsolete mapping-table styles', () => {
const css = readFileSync(new URL('./qaRegions.css', import.meta.url), 'utf8')
expect(css).toMatch(/\.qa-region-catalog-list/)
expect(css).toMatch(/minmax\(0,\s*1fr\)/)
expect(css).toMatch(/\.qa-region-row-actions/)
expect(css).toMatch(/overflow-wrap:\s*anywhere/)
expect(css).not.toContain('.qa-region-table')
})
it('shows a dated historical roster, conflicts and no invented performance verdict', () => {
const html = renderToStaticMarkup(<RegionCatalogView {...props} />)
expect(html).toContain('历史快照')
expect(html).toContain('跨区域待核对:1')
expect(html).not.toContain('配置区域归属不等于纳入绩效考核')
expect(html).not.toContain('<script>test</script>')
expect(html).not.toContain('达标率')
expect(html).toMatch(/disabled=""[^>]*>保存区域设置/)
})
it('keeps optional preview visible and lets save invoke the same preview automatically', () => {
const html = renderToStaticMarkup(<RegionCatalogView {...props} dirty preview={state} />)
expect(html).toContain('预览结果(未保存)')
expect(html).not.toMatch(/disabled=""[^>]*>保存区域设置/)
})
})