Files
docs/悦/PDA(海外)/tests/pallet-scan-list.test.ps1
2026-09-08 14:05:30 +08:00

89 lines
6.0 KiB
PowerShell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
$ErrorActionPreference = 'Stop'
$html = Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot '..\assets\app.js')
$required = @(
'id="pallet-top-scan"',
'function handlePalletTopScan()',
"state.page='pallet'",
"t('palletLabel')",
"t('destination')",
"t('cartonCount')",
"t('palletStatus')",
"unknownPalletScan"
)
$missing = $required | Where-Object { -not $html.Contains($_) }
if ($missing) { throw "Missing pallet scan/list contract: $($missing -join ', ')" }
$requiredTypeContracts = @(
"palletOrderType:'fba'",
'fbaPalletLabels:[]',
"dropshipPalletLabel:''",
'function setPalletOrderType(type)',
'class="pallet-order-tabs"',
"setPalletOrderType('fba')",
"setPalletOrderType('overseas')",
"setPalletOrderType('dropship')"
)
$missingTypeContracts = $requiredTypeContracts | Where-Object { -not $html.Contains($_) }
if ($missingTypeContracts) { throw "Missing pallet order tabs: $($missingTypeContracts -join ', ')" }
$plansView = [regex]::Match($html, '(?s)function plansPalletView\(\).*?(?=function receivePhotoView)').Value
if (-not $plansView.Contains('pallet-top-scan')) { throw 'Pallet list does not expose a top scan field' }
if ($plansView.Contains("t('orderList')")) { throw 'Pallet list still presents the order-list label' }
if (-not $plansView.Contains("t('palletBoxSummary')")) { throw 'Pallet list summary label is missing' }
if (-not $plansView.Contains('const totalBoxes=pallets.length*5')) { throw 'Pallet list total carton count is missing' }
if (-not $plansView.Contains('${t(''palletBoxSummary'')}:${pallets.length}/${totalBoxes}')) { throw 'Pallet summary is missing the colon separator' }
if (-not $plansView.Contains("t('scanBoxSku')")) { throw 'Top scan does not use carton mark/SKU copy' }
if (-not $html.Contains('function handlePalletTopScan()')) { throw 'Top scan handler is missing' }
if (-not $html.Contains("c.boxNo===value||c.sku===value")) { throw 'Top scan does not resolve carton mark/SKU' }
$scanHandler = [regex]::Match($html, '(?s)function handlePalletTopScan\(\).*?(?=function receivePhotoView)').Value
if (-not $scanHandler.Contains("if(!value){state.palletTopMessage=null;state.palletMode='palletize';startPallet();return}")) { throw 'Empty scan-button click does not enter palletizing' }
if (-not $plansView.Contains('<table class="table pallet-list-table">')) { throw 'Pallet list is not rendered as a table' }
if ($plansView.Contains("t('viewPalletDetails')") -or $plansView.Contains("t('palletizeAction')")) { throw 'Pallet list still exposes a detail/action button' }
if ($plansView.Contains('${esc(pallet.plan.id)}') -or $plansView.Contains('${esc(pallet.container)}')) { throw 'Pallet list still exposes order/container information' }
$css = Get-Content -Raw -LiteralPath (Join-Path $PSScriptRoot '..\assets\app.css')
if (-not $css.Contains('.pallet-list-table{min-width:0')) { throw 'Pallet table still requires horizontal scrolling' }
if (-not $css.Contains('.pallet-list-table th,.pallet-list-table td{padding:8px 6px')) { throw 'Pallet table spacing is not compact' }
if (-not $css.Contains('.pallet-list-table tbody td:nth-child(-n+3){font-size:14px}')) { throw 'Primary pallet columns are not enlarged' }
if (-not $css.Contains('.pallet-list-table th:nth-child(1),.pallet-list-table td:nth-child(1){width:35%}')) { throw 'Pallet label column width is incorrect' }
if (-not $css.Contains('.pallet-list-table th:nth-child(2),.pallet-list-table td:nth-child(2){width:25%}')) { throw 'Destination column width is incorrect' }
if (-not $css.Contains('.pallet-list-table th:nth-child(3),.pallet-list-table td:nth-child(3){width:15%;text-align:left}')) { throw 'Carton count column width is incorrect' }
if (-not $css.Contains('.pallet-list-table th:nth-child(4),.pallet-list-table td:nth-child(4){width:25%}')) { throw 'Status column width is incorrect' }
if ($html.Contains("if(state.page==='plans'||state.page==='relabel')")) { throw 'Pallet page still injects an order count' }
$palletView = [regex]::Match($html, '(?s)function palletView\(\).*?(?=function startPallet\()').Value
$tabsAt = $palletView.IndexOf('${palletOrderTabs()}')
$scanAt = $palletView.IndexOf('${scanCard}')
$progressAt = $palletView.IndexOf('pallet-progress-card')
$cargoAt = $palletView.IndexOf('${cargoInfo}')
if ($tabsAt -lt 0 -or $scanAt -lt $tabsAt -or $progressAt -lt $scanAt -or $cargoAt -lt $progressAt) { throw 'Pallet detail module order is incorrect' }
if (-not $palletView.Contains("const showDetails=state.palletOrderType==='overseas'")) { throw 'Detail visibility is not type-driven' }
if (-not $palletView.Contains("const scanHint=state.palletOrderType==='dropship'?t('scanPalletLabel'):t('scanBoxSku')")) { throw 'Scan hint is not type-driven' }
if (-not $palletView.Contains("t('cargoInfo')")) { throw 'Pallet detail title is not cargo information' }
if (-not $palletView.Contains("t('inboundCode')")) { throw 'Pallet detail does not show inbound code' }
if (-not $palletView.Contains("t('cartonCount')")) { throw 'Pallet detail does not show carton count' }
if ($palletView.Contains("t('palletNo')")) { throw 'Pallet detail still shows pallet number' }
if ($palletView.Contains("t('destinationAddress')")) { throw 'Pallet detail still shows destination address' }
if ($palletView.Contains("t('pieces')")) { throw 'Pallet detail still shows pieces' }
$fbaContracts = @(
'function fbaPalletLabelSelector(plan)',
'function toggleFbaPalletLabel(palletId)',
'state.fbaPalletLabels.includes(palletId)',
"state.palletOrderType==='fba'&&!state.fbaPalletLabels.length"
)
$missingFba = $fbaContracts | Where-Object { -not $html.Contains($_) }
if ($missingFba) { throw "Missing FBA multi-select behavior: $($missingFba -join ', ')" }
$dropshipContracts = @(
"state.palletOrderType==='dropship'",
'state.dropshipPalletLabel=pallet.id',
"state.palletOrderType==='dropship'&&!state.dropshipPalletLabel",
"state.palletOrderType==='overseas'"
)
$missingDropship = $dropshipContracts | Where-Object { -not $html.Contains($_) }
if ($missingDropship) { throw "Missing dropship scan behavior: $($missingDropship -join ', ')" }
Write-Output 'PASS: pallet scan/list source contract'