34 lines
1.6 KiB
JavaScript
34 lines
1.6 KiB
JavaScript
|
|
import fs from 'node:fs'
|
||
|
|
import path from 'node:path'
|
||
|
|
import { fileURLToPath } from 'node:url'
|
||
|
|
|
||
|
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
||
|
|
const toolbarFile = path.resolve(currentDir, '../components/SteadyTrendToolbar.vue')
|
||
|
|
const payloadFile = path.resolve(currentDir, '../utils/trendPayload.ts')
|
||
|
|
|
||
|
|
const toolbarSource = fs.readFileSync(toolbarFile, 'utf8')
|
||
|
|
const payloadSource = fs.readFileSync(payloadFile, 'utf8')
|
||
|
|
|
||
|
|
const checks = [
|
||
|
|
['toolbar labels the filter as data quality', /toolbar-field__label">数据质量:<\/span>/],
|
||
|
|
['toolbar renders quality flag with switch', /<el-switch[\s\S]*:model-value="modelValue\.qualityFlag \?\? 0"/],
|
||
|
|
['quality switch maps valid data to zero', /active-text="有效"[\s\S]*:active-value="0"/],
|
||
|
|
['quality switch maps invalid data to one', /inactive-text="无效"[\s\S]*:inactive-value="1"/],
|
||
|
|
['quality switch updates qualityFlag', /@update:model-value="handleQualityFlagChange"/],
|
||
|
|
['quality switch reserves enough prompt width', /\.quality-switch\s*\{[\s\S]*min-width:\s*72px/],
|
||
|
|
['utilities default to valid quality flag zero', /qualityFlag:\s*0/],
|
||
|
|
['utilities send quality flag in trend query payload', /qualityFlag:\s*formState\.qualityFlag/]
|
||
|
|
]
|
||
|
|
|
||
|
|
const failed = checks
|
||
|
|
.filter(([, pattern], index) => !pattern.test(index < 6 ? toolbarSource : payloadSource))
|
||
|
|
.map(([message]) => message)
|
||
|
|
|
||
|
|
if (failed.length) {
|
||
|
|
console.error('steadyTrend quality switch contract failed:')
|
||
|
|
failed.forEach(message => console.error(`- ${message}`))
|
||
|
|
process.exit(1)
|
||
|
|
}
|
||
|
|
|
||
|
|
console.log('steadyTrend quality switch contract passed')
|