Files
jiapuapp/tests/shared-interaction-accessibility-contract.ps1
T
2026-07-21 20:59:10 +08:00

47 lines
2.2 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
function Read-Utf8([string]$path) { Get-Content -LiteralPath (Join-Path $root $path) -Raw -Encoding UTF8 }
$button = Read-Utf8 'components/AppButton.vue'
foreach ($token in @('<button', ':disabled="disabled"', ':aria-label="label"', '@click="handleClick"')) {
if (-not $button.Contains($token)) { throw "AppButton accessibility contract missing: $token" }
}
if ($button -match '<view\s+[^>]*class="app-button"') { throw 'AppButton must use a native button root' }
$header = Read-Utf8 'components/PageHeader.vue'
foreach ($pattern in @(
'(?s)<button[^>]+class="header-back"[^>]+aria-label=',
'(?s)<button[^>]+class="header-icon-button header-notice"[^>]+aria-label=',
'(?s)<button[^>]+class="header-icon-button"[^>]+aria-label='
)) {
if ($header -notmatch $pattern) { throw "PageHeader accessibility contract missing: $pattern" }
}
if (-not $header.Contains('fallbackUrl')) { throw 'PageHeader must expose a deep-link fallback route' }
foreach ($token in @(
'customBack: { type: Boolean, default: false }',
'const emit = defineEmits(["brand", "notice", "action", "back"]);',
'if (props.customBack) {',
'emit("back");',
'uni.navigateBack();',
'uni.reLaunch({ url: props.fallbackUrl });'
)) {
if (-not $header.Contains($token)) { throw "PageHeader back contract missing: $token" }
}
$dialog = Read-Utf8 'components/AppDialog.vue'
foreach ($token in @('role="dialog"', 'aria-modal="true"', 'tabindex="-1"', '@keydown.esc.stop="cancel"', 'max-height: calc(var(--app-viewport-height, 100vh) - 160rpx)', 'overflow-y: auto')) {
if (-not $dialog.Contains($token)) { throw "AppDialog accessibility contract missing: $token" }
}
$toast = Read-Utf8 'components/AppToast.vue'
foreach ($token in @('v-show="visible"', 'role="status"', 'aria-live="polite"', 'aria-atomic="true"')) {
if (-not $toast.Contains($token)) { throw "AppToast accessibility contract missing: $token" }
}
$loading = Read-Utf8 'components/AppLoading.vue'
foreach ($token in @('role="status"', 'aria-live="polite"', 'aria-busy="true"', 'animation: none')) {
if (-not $loading.Contains($token)) { throw "AppLoading accessibility contract missing: $token" }
}
Write-Output 'SHARED-INTERACTION-ACCESSIBILITY-CONTRACT PASS'