68 lines
3.1 KiB
JavaScript
68 lines
3.1 KiB
JavaScript
const assert = require('node:assert/strict')
|
|
const fs = require('node:fs')
|
|
const path = require('node:path')
|
|
const vm = require('node:vm')
|
|
const ts = require('typescript')
|
|
const { parse, compileScript, compileTemplate, compileStyleAsync } = require('@vue/compiler-sfc')
|
|
|
|
const root = path.resolve(__dirname, '..')
|
|
const read = (relative) => fs.readFileSync(path.join(root, 'src', relative), 'utf8')
|
|
const utils = ts.transpileModule(read('utils/appointment-type.ts'), {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS }
|
|
}).outputText
|
|
const exportsObject = {}
|
|
vm.runInNewContext(utils, { exports: exportsObject })
|
|
for (const [value, expected] of [
|
|
['video', '视频问诊'], ['text', '图文问诊'], [undefined, '视频问诊'],
|
|
[null, '视频问诊'], ['', '视频问诊'], [' ', '视频问诊'],
|
|
['phone', '电话问诊'], ['other', '未知']
|
|
]) {
|
|
assert.equal(exportsObject.appointmentTypeDescription(value), expected)
|
|
}
|
|
|
|
const callers = [
|
|
'views/tcm/appointment/list.vue',
|
|
'views/tcm/appointment/list_h5.vue',
|
|
'views/patient/reception/index.vue'
|
|
]
|
|
for (const caller of callers) {
|
|
assert.match(read(caller), /chatDialogRef\.value\?\.open\(\{[\s\S]*?appointmentType: row\.appointment_type,/)
|
|
assert.match(read(caller), /appointmentId: Number\(row\.id\)/)
|
|
}
|
|
const chat = read('components/chat-dialog/index.vue')
|
|
assert.match(chat, /appointmentType\.value = data\.appointmentType/)
|
|
assert.match(chat, /class="chat-appointment-type">\{\{ appointmentTypeLabel \}\}/)
|
|
const form = read('views/tcm/diagnosis/appointment.vue')
|
|
assert.match(form, /<el-radio value="text">图文问诊<\/el-radio>/)
|
|
assert.match(form, /appointmentType: 'video'/)
|
|
assert.match(form, /form\.appointmentType = 'video'/)
|
|
assert.match(form, /appointment_type: form\.appointmentType/)
|
|
|
|
async function main() {
|
|
const components = [
|
|
...callers, 'components/chat-dialog/index.vue',
|
|
'views/tcm/diagnosis/appointment.vue', 'views/consumer/prescription/guahao.vue',
|
|
'views/first_visit/my_patients/index.vue', 'views/tcm/diagnosis/index.vue', 'views/tcm/diagnosis/index_h5.vue'
|
|
]
|
|
for (const filename of components) {
|
|
const { descriptor, errors } = parse(read(filename), { filename })
|
|
assert.deepEqual(errors, [], `${filename} parses`)
|
|
const script = compileScript(descriptor, { id: filename })
|
|
const template = compileTemplate({
|
|
source: descriptor.template.content,
|
|
filename, id: filename,
|
|
compilerOptions: { bindingMetadata: script.bindings }
|
|
})
|
|
assert.deepEqual(template.errors, [], `${filename} template compiles`)
|
|
for (const style of descriptor.styles) {
|
|
const result = await compileStyleAsync({
|
|
source: style.content, filename: path.join(root, 'src', filename),
|
|
id: filename, scoped: style.scoped, preprocessLang: style.lang
|
|
})
|
|
assert.deepEqual(result.errors, [], `${filename} styles compile`)
|
|
}
|
|
}
|
|
console.log(`Appointment type defaults/labels, ${callers.length} chat entry contracts, ${components.length} Vue components: OK`)
|
|
}
|
|
main().catch((error) => { console.error(error); process.exitCode = 1 })
|