import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' const source = readFileSync(new URL('./FirstLegOrdersView.vue', import.meta.url), 'utf8') const routerSource = readFileSync(new URL('../routes.ts', import.meta.url), 'utf8') const editorShellSource = readFileSync(new URL('../components/FirstLegOrderEditorShell.vue', import.meta.url), 'utf8') test('routes the confirmed first-leg path to the implemented order view', () => { assert.match(routerSource, /path: 'orders\/first-leg'[\s\S]*?component: \(\) => import\('\.\/views\/FirstLegOrdersView\.vue'\)[\s\S]*?release: 'active'/) }) test('opens order creation as a dedicated protected page while keeping draft editing in a drawer', () => { assert.match(routerSource, /path: 'orders\/first-leg\/create'[\s\S]*?name: 'first-leg-order-create'[\s\S]*?release: 'active'[\s\S]*?permission: 'order:first-leg:create'/) assert.match(source, /router\.push\(\{ name: 'first-leg-order-create' \}\)/) assert.match(source, /const isCreatePage = computed\(\(\) => route\.name === 'first-leg-order-create'\)/) assert.match(source, /]*:page="isCreatePage"/) assert.match(editorShellSource, /
/) assert.match(editorShellSource, / { assert.match(source, /function openCreate\(\)/) assert.match(source, /async function saveDraft\(\)/) assert.match(source, /function submitOrder\(\)/) assert.match(source, /async function openDetail\(order: FirstLegOrder\)/) assert.match(source, /Promise\.allSettled\(\[/) assert.match(source, /Promise\.allSettled\(\[\s*store\.load\(\),\s*companyRequest/) assert.match(source, /tenantStore\.loadCompanyContext\(\)/) assert.match(source, /await store\.loadDetail\(order\.id\)/) assert.doesNotMatch(source, /cancelOrder|取消订单/) }) test('blocks order submission before company approval while preserving draft actions', () => { assert.match(source, /companySubmissionBlocked/) assert.match(source, /companyAuditLoaded\.value = true/) assert.match(source, /企业资料待审核,当前仅可保存订单草稿/) assert.match(source, /暂时无法提交订单/) assert.match(source, /router\.push\('\/company\/profile'\)/) assert.match(source, /auth\.hasPermission\('order:first-leg:submit'\)/) }) test('defers approval checks to the server when the member cannot read the company profile', () => { assert.match(source, /const canViewCompanyProfile = computed/) assert.match(source, /const companySubmissionBlocked = computed\(\(\) => companyAuditLoaded\.value/) assert.match(source, /const knownCompanyAuditStatus = companyAuditLoaded\.value \? tenantStore\.company\.auditStatus : undefined/) assert.match(source, /store\.submit\([^\n]*knownCompanyAuditStatus\)/) }) test('renders dynamic cargo lines and responsive drawers', () => { assert.match(source, /v-for="\(item, index\) in form\.items"/) assert.match(source, /function addCargoItem\(\)/) assert.match(source, /function removeCargoItem\(index: number\)/) assert.match(source, /:global\(\.first-leg-editor\).*width: 100% !important/) assert.match(source, /class="mobile-order-list"/) assert.match(source, /\.desktop-order-table \{ display: none; \}/) }) test('keeps primary mobile order actions touch sized', () => { assert.match(source, /\.editor-actions :deep\(\.el-button\) \{ min-height: 44px;/) }) test('uses the shared query toolbar and data table without metric cards', () => { assert.match(source, /import QueryToolbar, \{ type QueryField, type QueryModel \}/) assert.match(source, /import DataTable, \{ type DataTableColumn \}/) assert.match(source, /const filters = ref/) assert.match(source, //) assert.match(source, /async function searchOrders\(model: QueryModel\)/) assert.match(source, /await store\.load\(\)/) assert.match(source, / { assert.match(source, /class="order-table-toolbar"/) assert.match(source, /订单列表<\/strong>共 \{\{ filteredOrders\.length \}\} 条<\/span>/) assert.match(source, /class="order-table-toolbar"[\s\S]*order:first-leg:create[\s\S]*创建订单[\s\S]*class="order-eligibility is-pending"/) assert.doesNotMatch(source, //) assert.match(source, /client-main:has\(> \.first-leg-page:not\(\.is-create-route\)\) > \.client-page-heading > div\) \{ position: absolute; width: 1px; height: 1px;/) }) test('keeps desktop query actions on the first row and only shows the qualification notice before approval', () => { assert.match(source, /\.first-leg-query-toolbar \{ flex-wrap: nowrap; \}/) assert.match(source, /query-toolbar__filters\) \{ display: grid; min-width: 0; flex: 1 1 auto;/) assert.match(source, /query-toolbar__actions\) \{ align-self: flex-start; flex-wrap: nowrap; margin-left: auto;/) assert.match(source, /v-if="companySubmissionBlocked && !supportingDataErrors\.some/) assert.doesNotMatch(source, /企业资料已审核,可正常提交订单/) assert.doesNotMatch(source, /order-eligibility\.is-approved/) }) test('does not expose arbitrary status mutation controls to customers', () => { assert.doesNotMatch(source, /setStatusForPreview/) assert.doesNotMatch(source, /状态更新|更新状态/) }) test('requires an enabled platform receiving warehouse in the order form', () => { assert.match(source, /store\.warehouses\.filter\(\(warehouse\) => warehouse\.warehouseType === 'DOMESTIC'\)/) assert.match(source, /availableWarehouses\.value\.length === 0/) assert.match(source, /label="国内收货仓"[^>]*required/) assert.match(source, /v-model="form\.receivingWarehouseId"/) assert.match(source, /selectedWarehouse\.businessHours/) assert.match(source, /class="selected-warehouse" aria-label="所选收货仓详情"/) assert.doesNotMatch(source, /class="selected-warehouse"[^>]*>[\s\S]*?\{\{ selectedWarehouse\.name \}\}<\/strong>/) assert.match(source, /first-leg-editor \.el-drawer__header\) \{[^}]*margin-bottom: 0;[^}]*border-bottom: 1px solid var\(--border\)/) assert.match(source, /first-leg-editor \.el-drawer__body\) \{[^}]*min-height: 0;[^}]*padding: 18px 22px 32px;[^}]*overscroll-behavior: contain/) assert.match(source, /first-leg-editor \.el-drawer__footer\) \{[^}]*border-top: 1px solid var\(--border\);[^}]*background: #fff/) assert.match(source, /detailOrder\.receivingWarehouseSnapshot\?\.name/) assert.match(source, /detailOrder\.receivingWarehouseSnapshot\.code/) assert.match(source, /loadSelectedWarehouse\(detailedOrder\.receivingWarehouseId\)/) }) test('selects platform destinations by type and caches private addresses per user', () => { assert.match(source, /warehouse\.warehouseType === form\.destinationType/) assert.match(source, /v-model="form\.destinationWarehouseId"/) assert.match(source, /form\.amazonWarehouseCode = form\.destinationType === 'FBA' \? warehouse\.code : ''/) assert.match(source, /cc:first-leg:private-addresses:\$\{auth\.user\?\.id/) assert.match(source, /localStorage\.setItem\(privateAddressStorageKey\(\)/) assert.match(source, /私人地址不能引用平台公共仓库|form\.destinationWarehouseId = ''/) }) test('auto-fills trusted warehouse and company data instead of asking customers to repeat it', () => { assert.match(source, /async function selectDestinationWarehouse\(id: string\)/) assert.match(source, /await store\.loadWarehouseDetail\(warehouse\.id\)/) assert.match(source, /availableWarehouses\.value\.length === 1/) assert.match(source, /availableDestinationWarehouses\.value\.length === 1/) assert.match(source, /function createPickupPartySnapshot\(\)/) assert.match(source, /contactName: tenantStore\.company\.contactName/) assert.match(source, /selectedDestinationWarehouse\.address/) }) test('collects the backend-required first-leg fields', () => { for (const model of ['destinationCountryCode', 'destinationWarehouseName', 'channelCode', 'pickupMethod', 'taxMode', 'destinationType', 'packageType', 'upc']) { assert.match(source, new RegExp(`v-model="(?:form|item)\\.${model}"`)) } assert.match(source, /form\.channelName = channel\?\.name/) }) test('distills order creation into the confirmed prototype sections without fake pricing', () => { assert.match(source, /

目的地信息<\/h3>/) assert.match(source, /

发货信息<\/h3>/) assert.match(source, /

货物明细<\/h3>/) assert.ok(source.indexOf('

发货信息

') < source.indexOf('

目的地信息

')) assert.ok(source.indexOf('

目的地信息

') < source.indexOf('

货物明细

')) assert.match(source, /class="segmented-options"/) assert.match(source, /class="prototype-form-row prototype-form-row--tabs"/) assert.match(source, /class="cargo-primary-grid"/) assert.match(source, /title="更多申报信息"/) assert.doesNotMatch(source, /费用预估|查看最新报价|cost-estimate/) assert.doesNotMatch(source, /v-model="form\.(?:businessType|origin|destination|priority|tradeTerm)"/) }) test('shows field-level validation and concise guidance for required order inputs', () => { assert.match(source, /ref="orderFormRef"[^>]*:model="form" :rules="orderFormRules"/) assert.match(source, /prop="shipperPartySnapshot\.contactName" required/) assert.match(source, /prop="consigneePartySnapshot\.address" required/) assert.match(source, /:prop="`items\.\$\{index\}\.cargoNameCn`" required/) assert.match(source, /:prop="`items\.\$\{index\}\.grossWeightKg`" required/) assert.match(source, /label="UPC".*required.*v-model="item\.upc"/) assert.match(source, /placeholder="例如:蓝牙音箱"/) assert.match(source, /\.order-form :deep\(\.el-form-item__error\).*position: static/) }) test('collects snapshots only for pickup and private destinations', () => { assert.doesNotMatch(source, /firstLegPartySource|v-model="form\.(?:shipper|consignee)PartyId"/) assert.match(source, /form\.pickupMethod === 'PICKUP'/) assert.match(source, /form\.destinationType === 'PRIVATE'/) assert.match(source, /form\.shipperPartySnapshot\.contactName/) assert.match(source, /form\.consigneePartySnapshot\.address/) assert.match(source, /syncPrivateDestinationName/) assert.match(source, /changePickupMethod/) }) test('shows fulfillment courier information as read-only client detail', () => { assert.match(source, /履约快递信息/) assert.match(source, /detailOrder\.expressCompanyName/) assert.match(source, /detailOrder\.trackingNumber/) assert.match(source, /客户端仅只读展示/) assert.doesNotMatch(source, /v-model="form\.expressCompanyName"/) assert.doesNotMatch(source, /v-model="form\.trackingNumber"/) }) test('protects unsaved drafts and exposes recoverable load failures', () => { assert.match(source, /onBeforeRouteLeave/) assert.match(source, /beforeunload/) assert.match(source, /confirmDiscardChanges/) assert.match(source, /:before-close="requestCloseEditor"/) assert.match(source, /store\.loadError/) assert.match(source, /订单数据加载失败/) assert.match(source, /订单详情加载失败/) assert.match(source, /部分订单配套数据加载失败/) assert.doesNotMatch(source, /往来单位加载失败/) assert.match(source, /企业资料加载失败/) assert.match(source, /@click="loadPageData"/) assert.match(source, /@click="retryDetail"/) }) test('copies reactive order drafts into plain request data', () => { assert.match(source, /function cloneDraft\(draft: FirstLegOrderDraft\)/) assert.match(source, /items: draft\.items\.map\(\(item\) => \(\{ \.\.\.item \}\)\)/) assert.match(source, /store\.saveDraft\(cloneDraft\(form\)/) assert.match(source, /store\.submit\(cloneDraft\(form\)/) assert.doesNotMatch(source, /structuredClone\((?:form|order\.)/) }) test('loads complete order detail before editing and rejects an unavailable historical warehouse', () => { assert.match(source, /async function openEdit\(order: FirstLegOrder\)/) assert.match(source, /const detailedOrder = await store\.loadDetail\(order\.id\)/) assert.match(source, /draftFromOrder\(detailedOrder\)/) assert.match(source, /draft\.receivingWarehouseId = ''/) assert.match(source, /原平台收货仓当前不可用,请重新选择可用收货仓/) assert.match(source, /原目的仓当前不可用,请重新选择平台维护的目的仓/) })