fix(billing): refine mobile dates and balance card
parent
9ea9625576
commit
96f06d3438
@ -1,2 +1,2 @@
|
||||
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
|
||||
{assign var=venix_asset_version value='2026110121' scope='global'}
|
||||
{assign var=venix_asset_version value='2026110122' scope='global'}
|
||||
|
||||
@ -0,0 +1,118 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFile } from 'node:child_process';
|
||||
import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { promisify } from 'node:util';
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const root = new URL('../', import.meta.url);
|
||||
const css = await readFile(new URL('public/cloud/client.css', root), 'utf8');
|
||||
const template = await readFile(
|
||||
new URL('resources/views/venix/cloud/pages/invoices.tpl', root),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
assert.match(template, /class="invoice-balance-summary"/,
|
||||
'The balance label and amount must share a stable summary container.');
|
||||
assert.match(template, /class="invoice-balance-hint"/,
|
||||
'The balance card must explain what the wallet balance can be used for.');
|
||||
assert.match(css, /\.invoice-balance-summary\s*\{/,
|
||||
'The balance summary has no dedicated visual hierarchy.');
|
||||
assert.match(css, /@media \(max-width: 520px\)[\s\S]*?\.invoice-filter-date\s*\{[^}]*grid-column:\s*1\s*\/\s*-1/,
|
||||
'Mobile date controls must each occupy a full row to avoid native-input overflow.');
|
||||
assert.match(css, /\.invoice-filter-field input\[type="date"\][^{]*\{[^}]*max-width:\s*100%/,
|
||||
'Native date controls must be explicitly constrained to their grid cell.');
|
||||
assert.match(css, /@media \(max-width: 360px\)[\s\S]*?\.invoice-balance-card\s*\{[^}]*grid-template-columns:\s*1fr/,
|
||||
'Very narrow screens must stack the balance action below the amount.');
|
||||
|
||||
const chromeCandidates = [
|
||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
||||
'/usr/bin/google-chrome',
|
||||
'/usr/bin/chromium',
|
||||
'/usr/bin/chromium-browser',
|
||||
];
|
||||
let chrome = '';
|
||||
for (const candidate of chromeCandidates) {
|
||||
try {
|
||||
await execFileAsync(candidate, ['--version']);
|
||||
chrome = candidate;
|
||||
break;
|
||||
} catch { /* Try the next local browser. */ }
|
||||
}
|
||||
|
||||
if (chrome) {
|
||||
const directory = await mkdtemp(join(tmpdir(), 'invoice-mobile-layout-'));
|
||||
const fixture = join(directory, 'fixture.html');
|
||||
const safeCss = css.replaceAll('</style', '<\\/style');
|
||||
const html = `<!doctype html><html><head><meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<style>${safeCss}</style></head><body>
|
||||
<main style="width:auto;box-sizing:border-box;padding:20px;">
|
||||
<div class="invoice-balance-card">
|
||||
<div class="invoice-balance-summary">
|
||||
<span class="invoice-balance-label">当前账户余额</span>
|
||||
<strong id="invoices-balance">$10,551.00</strong>
|
||||
<small class="invoice-balance-hint">可用于支付未结清账单</small>
|
||||
</div>
|
||||
<button class="button button-outline small" type="button">余额充值</button>
|
||||
</div>
|
||||
<form class="invoice-filter-bar">
|
||||
<label class="invoice-filter-field"><span>账单类型</span><select><option>全部账单</option></select></label>
|
||||
<label class="invoice-filter-field"><span>账单状态</span><select><option>全部状态</option></select></label>
|
||||
<label class="invoice-filter-field invoice-filter-keyword"><span>账单或实例</span><input type="search"></label>
|
||||
<label class="invoice-filter-field invoice-filter-date" id="from-field"><span>开始日期</span><input id="from-date" type="date"></label>
|
||||
<label class="invoice-filter-field invoice-filter-date" id="to-field"><span>结束日期</span><input id="to-date" type="date"></label>
|
||||
<div class="invoice-filter-actions"><button class="button button-primary small">筛选</button><button class="button button-ghost small">清除</button></div>
|
||||
</form>
|
||||
</main><script>
|
||||
const rect = target => { const value = target.getBoundingClientRect(); return { left:value.left, right:value.right, top:value.top, bottom:value.bottom, width:value.width }; };
|
||||
const card = document.querySelector('.invoice-balance-card');
|
||||
document.body.dataset.metrics = encodeURIComponent(JSON.stringify({
|
||||
viewport: document.documentElement.clientWidth,
|
||||
scrollWidth: document.documentElement.scrollWidth,
|
||||
from: rect(document.getElementById('from-field')),
|
||||
to: rect(document.getElementById('to-field')),
|
||||
fromInput: rect(document.getElementById('from-date')),
|
||||
toInput: rect(document.getElementById('to-date')),
|
||||
card: rect(card),
|
||||
summary: rect(card.querySelector('.invoice-balance-summary')),
|
||||
recharge: rect(card.querySelector('button')),
|
||||
}));
|
||||
</script></body></html>`;
|
||||
await writeFile(fixture, html);
|
||||
const measure = async width => {
|
||||
const profile = join(directory, `profile-${width}`);
|
||||
const { stdout } = await execFileAsync(chrome, [
|
||||
'--headless=new', '--disable-gpu', '--no-sandbox', '--hide-scrollbars',
|
||||
`--window-size=${width},844`, `--user-data-dir=${profile}`,
|
||||
'--dump-dom', `file://${fixture}`,
|
||||
], { maxBuffer: 8 * 1024 * 1024 });
|
||||
const encoded = stdout.match(/data-metrics="([^"]+)"/)?.[1];
|
||||
assert.ok(encoded, 'Headless browser did not return invoice layout metrics.');
|
||||
return JSON.parse(decodeURIComponent(encoded));
|
||||
};
|
||||
try {
|
||||
// Desktop Chrome enforces a 500 CSS-pixel minimum headless window. That
|
||||
// still drives the real max-width:520px mobile rules; the narrower
|
||||
// max-width:360px fallback is locked by the static contract above.
|
||||
const regular = await measure(500);
|
||||
assert.ok(regular.scrollWidth <= regular.viewport,
|
||||
`Invoice page overflows horizontally (${regular.scrollWidth} > ${regular.viewport}).`);
|
||||
assert.ok(Math.abs(regular.from.left - regular.to.left) < 1
|
||||
&& regular.to.top >= regular.from.bottom,
|
||||
'Mobile date controls are not stacked into stable full-width rows.');
|
||||
assert.ok(regular.fromInput.right <= regular.viewport
|
||||
&& regular.toInput.right <= regular.viewport,
|
||||
'A native date input extends beyond the mobile viewport.');
|
||||
assert.ok(regular.recharge.left >= regular.summary.right - 1
|
||||
&& regular.recharge.right <= regular.card.right,
|
||||
'The balance action is not aligned with the summary on a normal phone.');
|
||||
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Cloud invoice mobile date and balance layout checks passed${chrome ? ' with headless browser.' : ' (browser unavailable; static contract only).'}`);
|
||||
Loading…
Reference in New Issue