Files
X-Financial/web/tests/receipt-folder-view.test.mjs

144 lines
6.7 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
const root = process.cwd()
function readProjectFile(path) {
return readFileSync(join(root, path), 'utf8')
}
function testReceiptFolderViewSurface() {
const view = readProjectFile('web/src/views/ReceiptFolderView.vue')
assert.match(view, /未关联票据/)
assert.match(view, /已关联票据/)
assert.match(view, /label: '全部'/)
assert.match(view, /一键关联票据/)
assert.match(view, /票据关键字段/)
assert.match(view, /原始文件/)
assert.match(view, /keyReceiptFields/)
assert.match(view, /editableOtherFields/)
assert.match(view, /class="receipt-key-grid"/)
assert.match(view, /class="receipt-other-collapse"/)
assert.match(view, /class="receipt-other-scroll"/)
assert.match(view, /其他信息/)
assert.match(view, /ElCollapse/)
assert.doesNotMatch(view, /新增字段/)
assert.match(view, /const isTrainTicket = computed/)
assert.doesNotMatch(view, /打开源文件/)
assert.doesNotMatch(view, /openSourceFile/)
assert.match(view, /返回票据夹/)
assert.doesNotMatch(view, /返回列表/)
assert.match(view, /删除票据/)
assert.match(view, /ElCheckboxGroup/)
assert.match(view, /fetchReceiptFolderItems\('all'\)/)
assert.match(view, /buildReceiptFile\(item\)/)
assert.match(view, /source: selectedDraft \? 'detail' : 'receipt-folder'/)
assert.match(view, /emit\('open-assistant'/)
}
function testReceiptFolderServiceContract() {
const service = readProjectFile('web/src/services/receiptFolder.js')
const ocrService = readProjectFile('web/src/services/ocr.js')
const reimbursementService = readProjectFile('web/src/services/reimbursements.js')
assert.match(service, /\/receipt-folder\$\{buildStatusQuery\(status\)\}/)
assert.match(service, /\/receipt-folder\/\$\{encodeURIComponent/)
assert.match(service, /responseType: 'blob'/)
assert.match(service, /new File\(\[blob\], fileName/)
assert.match(service, /receiptId/)
assert.match(ocrService, /formData\.append\('receipt_ids'/)
assert.match(reimbursementService, /formData\.append\('receipt_id'/)
}
function testAppShellWiresReceiptFolder() {
const shell = readProjectFile('web/src/views/AppShellRouteView.vue')
const topBar = readProjectFile('web/src/components/layout/TopBar.vue')
assert.match(shell, /activeView === 'receiptFolder'/)
assert.match(shell, /ReceiptFolderView/)
assert.match(shell, /@open-assistant="openSmartEntry"/)
assert.match(shell, /@detail-open-change="receiptFolderDetailOpen = \$event"/)
assert.match(shell, /@detail-topbar-change="detailTopBarPayload = \$event"/)
assert.match(shell, /receipt-folder-workarea/)
assert.match(topBar, /receiptFolder/)
assert.match(topBar, /eyebrowLabel/)
}
function testSharedDocumentListStyleReuse() {
const receiptView = readProjectFile('web/src/views/ReceiptFolderView.vue')
const documentView = readProjectFile('web/src/views/DocumentsCenterView.vue')
const receiptStyles = readProjectFile('web/src/assets/styles/views/receipt-folder-view.css')
const sharedStyles = readProjectFile('web/src/assets/styles/components/document-list-shared.css')
assert.match(receiptView, /document-list-shared\.css/)
assert.match(documentView, /document-list-shared\.css/)
assert.match(sharedStyles, /\.table-wrap\b/)
assert.match(sharedStyles, /\.doc-kind-tag\b/)
assert.match(sharedStyles, /\.list-foot\b/)
assert.doesNotMatch(receiptStyles, /\.table-wrap\b/)
assert.doesNotMatch(receiptStyles, /\.doc-kind-tag\b/)
assert.doesNotMatch(receiptStyles, /\.list-foot\b/)
}
function testReceiptFolderDetailLayoutAdjustments() {
const receiptView = readProjectFile('web/src/views/ReceiptFolderView.vue')
const receiptStyles = readProjectFile('web/src/assets/styles/views/receipt-folder-view.css')
const fieldModel = readProjectFile('web/src/views/scripts/receiptFolderDetailFields.js')
assert.match(receiptView, /showStatusColumn/)
assert.match(receiptView, /<col v-if="showStatusColumn" class="col-status">/)
assert.match(receiptView, /<th v-if="showStatusColumn">/)
assert.match(receiptView, /<th>票据日期<\/th>/)
assert.match(receiptView, /<td>{{ row\.document_date \|\| '待补充' }}<\/td>/)
assert.match(receiptView, /<td>\s*<strong class="doc-id">/)
assert.match(receiptView, /<td v-if="showStatusColumn">\s*<span class="status-tag"/)
assert.match(receiptView, /const activeStatus = ref\('all'\)/)
assert.match(receiptView, /import EnterpriseDetailCard/)
assert.match(receiptView, /import EnterpriseDetailPage/)
assert.match(receiptView, /<EnterpriseDetailPage/)
assert.match(receiptView, /variant="receipt-folder-detail"/)
assert.match(receiptView, /<EnterpriseDetailCard class="receipt-basic-panel"/)
assert.match(receiptView, /<EnterpriseDetailCard class="receipt-preview-panel"/)
assert.match(receiptView, /createReceiptDetailFieldModel/)
assert.match(receiptView, /buildDetailPayload\(\)/)
assert.match(receiptView, /receiptDetailSubtitle/)
assert.match(receiptView, /receiptDetailTopBarPayload/)
assert.match(receiptView, /eyebrow: '票据详情'/)
assert.match(receiptView, /detail-topbar-change/)
assert.doesNotMatch(receiptView, /<article v-else class="receipt-folder-detail/)
assert.doesNotMatch(receiptView, /class="back-btn"/)
assert.doesNotMatch(receiptView, /receipt-detail-head/)
assert.doesNotMatch(receiptView, /detail-actions receipt-detail-foot/)
assert.match(receiptStyles, /\.receipt-folder-list th:first-child/)
assert.match(receiptStyles, /\.receipt-folder-detail :deep\(\.detail-grid\)/)
assert.match(receiptStyles, /\.receipt-folder-detail :deep\(\.detail-actions\)/)
assert.match(receiptStyles, /\.receipt-folder-detail :deep\(\.enterprise-detail-card \.card-head\)/)
assert.match(receiptStyles, /\.receipt-key-grid/)
assert.match(receiptStyles, /\.receipt-other-collapse/)
assert.match(receiptStyles, /\.receipt-other-scroll/)
assert.doesNotMatch(receiptStyles, /\.receipt-detail-head\b/)
assert.doesNotMatch(receiptStyles, /\.receipt-detail-layout\b/)
assert.doesNotMatch(receiptStyles, /\.detail-loading\b/)
assert.doesNotMatch(receiptStyles, /\.back-btn\b/)
assert.doesNotMatch(receiptStyles, /\.danger-btn\b/)
assert.match(fieldModel, /TRAIN_KEY_FIELD_DEFINITIONS/)
assert.match(fieldModel, /label: '发票号码'/)
assert.match(fieldModel, /label: '开票日期'/)
assert.match(fieldModel, /label: '票价'/)
assert.match(fieldModel, /label: '姓名'/)
assert.match(fieldModel, /syncEditableFieldsToTopLevel/)
}
function run() {
testReceiptFolderViewSurface()
testReceiptFolderServiceContract()
testAppShellWiresReceiptFolder()
testSharedDocumentListStyleReuse()
testReceiptFolderDetailLayoutAdjustments()
console.log('receipt folder view tests passed')
}
run()