mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-05 16:02:17 +00:00
122 lines
7.0 KiB
TypeScript
122 lines
7.0 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import { readFile } from 'node:fs/promises'
|
|
import test from 'node:test'
|
|
|
|
const view = await readFile(new URL('../src/views/AutomaticTasks.vue', import.meta.url), 'utf8')
|
|
const taskList = await readFile(new URL('../src/components/automation/AutomaticTaskList.vue', import.meta.url), 'utf8')
|
|
const taskDetail = await readFile(new URL('../src/components/automation/AutomaticTaskDetail.vue', import.meta.url), 'utf8')
|
|
const taskEditor = await readFile(new URL('../src/components/AutomaticTaskDialog.vue', import.meta.url), 'utf8')
|
|
const taskRuns = await readFile(new URL('../src/components/AutomaticTaskRunsDialog.vue', import.meta.url), 'utf8')
|
|
const service = await readFile(new URL('../src/services/automation.ts', import.meta.url), 'utf8')
|
|
|
|
test('automatic tasks use the Studio workspace with real task selection and summary', () => {
|
|
assert.match(view, /VOHIVE \/ AUTOMATION/)
|
|
assert.match(view, /<AutomaticTaskList/)
|
|
assert.match(view, /<AutomaticTaskDetail/)
|
|
assert.match(view, /const selectedTask = computed/)
|
|
assert.match(view, /function syncSelection/)
|
|
assert.match(view, /detailDismissed/)
|
|
assert.doesNotMatch(view, /<el-table/)
|
|
assert.match(taskList, /automaticTaskSummary\(props\.tasks\)/)
|
|
assert.match(taskList, /role="table"/)
|
|
assert.match(taskList, /aria-selected=/)
|
|
assert.match(taskList, /emit\('select', task\)/)
|
|
})
|
|
|
|
test('automatic task rows preserve every production action without optimistic toggle mutation', () => {
|
|
assert.match(taskList, /emit\('toggle', task, Boolean\(\$event\)\)/)
|
|
assert.doesNotMatch(taskList, /v-model="task\.enabled"/)
|
|
assert.match(taskList, /emit\('run', task\)/)
|
|
assert.match(taskList, /emit\('history', task\)/)
|
|
assert.match(taskList, /emit\('edit', task\)/)
|
|
assert.match(taskList, /emit\('delete', task\)/)
|
|
assert.match(view, /automationService\.update\(task\.id, taskToInput\(task, \{ enabled \}\)\)/)
|
|
assert.match(view, /automationService\.runNow\(task\.id\)/)
|
|
assert.match(view, /automationService\.remove\(task\.id\)/)
|
|
assert.match(view, /rowBusy\(task\.id\)/)
|
|
})
|
|
|
|
test('automatic task loading and failures remain explicit while polling real APIs', () => {
|
|
assert.match(view, /TASK_REFRESH_INTERVAL_MS = 10_000/)
|
|
assert.match(view, /window\.setInterval\(\(\) => void loadTasks\(true\)/)
|
|
assert.match(view, /tasksError\.value = result\.error\.message/)
|
|
assert.match(taskList, /class="task-state task-error" role="alert"/)
|
|
assert.match(taskList, /正在读取自动任务/)
|
|
assert.match(taskList, /暂无自动任务/)
|
|
assert.match(service, /api\.get<TaskListResponse>\('\/automatic-tasks'\)/)
|
|
assert.doesNotMatch(view + taskList + taskDetail, /RUN_HISTORY|automationTasks:\s*\[/)
|
|
})
|
|
|
|
test('task detail consumes selected API facts and keeps history and editing reachable', () => {
|
|
assert.match(taskDetail, /automaticTaskTypeLabel\(task\)/)
|
|
assert.match(taskDetail, /automaticTaskEnvironmentLabel\(task\)/)
|
|
assert.match(taskDetail, /automaticTaskPayloadSummary\(task\)/)
|
|
assert.match(taskDetail, /task\.profile_iccid \|\| '未绑定'/)
|
|
assert.match(taskDetail, /emit\('history', task\)/)
|
|
assert.match(taskDetail, /emit\('edit', task\)/)
|
|
assert.match(taskDetail, /aria-label="关闭任务详情"/)
|
|
})
|
|
|
|
test('automatic task workspace uses touch-safe cards and reduced motion', () => {
|
|
assert.match(taskList, /@media \(max-width: 640px\)[\s\S]*\.task-item \{[\s\S]*grid-template-columns: minmax\(0, 1fr\) auto/)
|
|
assert.match(taskList, /\.task-actions :deep\(\.el-button\) \{ width: 44px; height: 44px; \}/)
|
|
assert.match(taskList, /@media \(prefers-reduced-motion: reduce\)/)
|
|
assert.match(view, /task-detail-enter-active[\s\S]*opacity 220ms[\s\S]*transform 220ms/)
|
|
assert.match(view, /task-detail-leave-active[\s\S]*opacity 120ms[\s\S]*transform 120ms/)
|
|
assert.match(view, /@media \(prefers-reduced-motion: reduce\)[\s\S]*transform: none/)
|
|
})
|
|
|
|
test('automatic task editor is a guarded right-side management tray', () => {
|
|
assert.match(taskEditor, /<el-drawer/)
|
|
assert.match(taskEditor, /direction="rtl"/)
|
|
assert.match(taskEditor, /size="min\(720px, 100vw\)"/)
|
|
assert.match(taskEditor, /append-to-body/)
|
|
assert.match(taskEditor, /:close-on-click-modal="!saving"/)
|
|
assert.match(taskEditor, /:close-on-press-escape="!saving"/)
|
|
assert.match(taskEditor, /if \(!open && props\.saving\) return/)
|
|
assert.match(taskEditor, /@opened="focusNameInput"/)
|
|
assert.match(taskEditor, /nameInput\.value\?\.focus\(\)/)
|
|
assert.doesNotMatch(taskEditor, /<el-dialog|<select/)
|
|
assert.match(taskEditor, /form\.device_id/)
|
|
assert.match(taskEditor, /selectedProfile/)
|
|
assert.match(taskEditor, /form\.task_type/)
|
|
assert.match(taskEditor, /form\.environment/)
|
|
assert.match(taskEditor, /form\.interval_days/)
|
|
assert.match(taskEditor, /form\.timezone/)
|
|
assert.match(taskEditor, /form\.retry_count/)
|
|
assert.match(taskEditor, /form\.notify/)
|
|
assert.match(taskEditor, /role="alert"/)
|
|
assert.match(taskEditor, /min-height: 44px/)
|
|
})
|
|
|
|
test('automatic task runs use the real paginated polling contract in a timeline tray', () => {
|
|
assert.match(taskRuns, /<el-drawer/)
|
|
assert.match(taskRuns, /direction="rtl"/)
|
|
assert.match(taskRuns, /size="min\(620px, 100vw\)"/)
|
|
assert.doesNotMatch(taskRuns, /<el-dialog|<el-table/)
|
|
assert.match(taskRuns, /RUN_REFRESH_INTERVAL_MS = 3_000/)
|
|
assert.match(taskRuns, /window\.setInterval\(\(\) => void loadRuns\(true\)/)
|
|
assert.match(taskRuns, /automationService\.runs\(\{[\s\S]*taskId: taskID,[\s\S]*limit: PAGE_SIZE,[\s\S]*offset: \(page\.value - 1\) \* PAGE_SIZE/)
|
|
assert.match(taskRuns, /requestID !== requestGeneration \|\| props\.task\?\.id !== taskID/)
|
|
assert.match(taskRuns, /@current-change="loadRuns\(false\)"/)
|
|
assert.match(taskRuns, /automaticTaskStatus\(run\.status\)/)
|
|
assert.match(taskRuns, /automaticTaskRunResult\(run\)/)
|
|
assert.match(taskRuns, /class="runs-error" role="alert"/)
|
|
assert.match(taskRuns, /暂无运行记录/)
|
|
assert.match(taskRuns, /white-space: pre-wrap; overflow-wrap: anywhere/)
|
|
})
|
|
|
|
test('automatic task workspace keeps the responsive theme and safe-area contract', () => {
|
|
assert.match(view, /@media \(max-width: 1180px\)[\s\S]*\.automation-shell\.detail-open \{ min-height: 0; display: block; \}/)
|
|
assert.match(view, /@media \(max-width: 820px\)[\s\S]*env\(safe-area-inset-bottom\)/)
|
|
assert.match(view, /@media \(max-width: 640px\)[\s\S]*\.page-heading \{[\s\S]*flex-direction: column/)
|
|
assert.match(taskList, /@media \(max-width: 640px\)[\s\S]*\.task-table \{ min-width: 0/)
|
|
assert.match(taskList, /\.task-cell b, \.task-cell small \{ white-space: normal; overflow-wrap: anywhere; \}/)
|
|
assert.match(taskDetail, /@media \(max-width: 1180px\)[\s\S]*border-left: 0/)
|
|
assert.match(taskDetail, /@media \(max-width: 640px\)[\s\S]*grid-template-columns: 1fr/)
|
|
assert.match(taskEditor, /@media \(max-width: 640px\)[\s\S]*safe-area-inset-bottom/)
|
|
assert.match(taskRuns, /@media \(max-width: 640px\)[\s\S]*safe-area-inset-bottom/)
|
|
assert.match(view + taskList + taskDetail + taskEditor + taskRuns, /var\(--ui-text\)/)
|
|
assert.match(view + taskList + taskDetail + taskEditor + taskRuns, /prefers-reduced-motion: reduce/)
|
|
})
|