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, /HIDECK \/ AUTOMATION/) assert.match(view, / { 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\('\/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, /\.task-toggle :deep\(\.el-switch\) \{ min-width: 44px; min-height: 44px;/) assert.match(taskDetail, /\.task-detail > header :deep\(\.el-button\) \{ width: 44px; height: 44px; flex: 0 0 44px; \}/) assert.match(taskEditor, /\.task-form :deep\(\.el-switch\) \{ min-width: 44px; min-height: 44px;/) assert.match(taskEditor, /\.task-form :deep\(\.el-input-number__decrease\),[\s\S]*\.el-input-number__increase\) \{ width: 44px; height: 44px;/) assert.match(taskEditor, /\.el-input-number \.el-input__wrapper\) \{ padding-inline: 44px; \}/) assert.match(taskRuns, /:pager-count="5"/) assert.match(taskRuns, /\.runs-pagination :deep\(\.el-pager li\) \{ min-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, / { assert.match(taskEditor, /const configLoading = ref\(false\)/) assert.match(taskEditor, /const configError = ref\(''\)/) assert.match(taskEditor, /if \(!config\.ok\) \{[\s\S]*configError\.value = config\.error\.message/) assert.match(taskEditor, /设备配置未返回后端类型/) assert.match(taskEditor, /requestID !== configRequest/) assert.match(taskEditor, /class="config-state config-error" role="alert"/) assert.match(taskEditor, /正在读取设备能力/) assert.match(taskEditor, /重新读取/) assert.match(taskEditor, /:disabled="saving \|\| deviceConfigUnavailable"/) }) test('automatic task runs use the real paginated polling contract in a timeline tray', () => { assert.match(taskRuns, / 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 \{ display: grid; grid-template-columns: minmax\(0, 1fr\); \}/) 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]*\.task-detail \{[^}]*display: grid;[^}]*grid-template-columns: 1fr 1fr;/) 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/) }) test('automatic task backgrounds follow the device management canvas and surface hierarchy', () => { assert.doesNotMatch(view, /class="ui-panel automation-shell"/) assert.match(view, /class="automation-shell ui-card ui-workspace-glow"/) assert.match(view, /\.automation-shell \{[^}]*overflow: hidden;[^}]*display: grid;/) assert.match(taskList, /class="task-list-region"/) assert.doesNotMatch(taskList, /class="task-list-region ui-card"/) assert.match(taskList, /\.task-state \{[^}]*var\(--ui-primary\)[^}]*var\(--ui-surface\);/) assert.match(taskDetail, /class="task-detail"/) assert.doesNotMatch(taskDetail, /class="task-detail ui-card"/) assert.match(taskEditor, /\.automatic-task-editor\) \{[^}]*background: var\(--ui-surface\);/) assert.match(taskRuns, /\.automatic-task-runs\) \{[^}]*background: var\(--ui-surface\);/) })