refactor: 收口公共AppBar组件

This commit is contained in:
czz
2026-05-09 15:55:05 +08:00
parent f3eb25b035
commit b7fa2fce9d
25 changed files with 497 additions and 242 deletions

View File

@@ -0,0 +1,40 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const appBarSource = fs.readFileSync(
path.join(__dirname, "../../src/components/app-bar/index.tsx"),
"utf8"
);
const appBarStyles = fs.readFileSync(
path.join(__dirname, "../../src/components/app-bar/index.scss"),
"utf8"
);
function run(name, fn) {
try {
fn();
console.log(`PASS ${name}`);
} catch (error) {
console.error(`FAIL ${name}`);
throw error;
}
}
run("AppBar back action uses the shared back.svg asset", () => {
assert.match(appBarSource, /back\.svg/);
assert.match(appBarSource, /<Image[\s\S]*className="app-bar__back-icon"/);
});
run("AppBar back action no longer renders a text arrow", () => {
assert.doesNotMatch(appBarSource, /&lt;|>\s*<\s*</);
});
run("AppBar back icon uses a fixed mini-program sized constraint", () => {
assert.match(appBarStyles, /\.app-bar__back-icon\s*\{[\s\S]*width:\s*32rpx;/);
assert.match(appBarStyles, /\.app-bar__back-icon\s*\{[\s\S]*height:\s*32rpx;/);
});
run("AppBar props stay focused on title and back navigation only", () => {
assert.doesNotMatch(appBarSource, /subtitle\?:|eyebrow\?:|align\?:|rightText\?:|onRightAction\?:|leftSlot\?:|rightSlot\?:|bottomSlot\?:/);
});

View File

@@ -0,0 +1,45 @@
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
const messagePageStyles = fs.readFileSync(
path.join(__dirname, "../../src/pages/message/index.scss"),
"utf8"
);
const messagePageSource = fs.readFileSync(
path.join(__dirname, "../../src/pages/message/index.tsx"),
"utf8"
);
function run(name, fn) {
try {
fn();
console.log(`PASS ${name}`);
} catch (error) {
console.error(`FAIL ${name}`);
throw error;
}
}
run("message tabs container spans full width without manual gap spacing", () => {
assert.match(messagePageStyles, /\.message-tabs\s*\{[\s\S]*width:\s*100%;/);
assert.doesNotMatch(messagePageStyles, /\.message-tabs\s*\{[\s\S]*gap:\s*110rpx;/);
});
run("each message tab item takes half of the row", () => {
assert.match(messagePageStyles, /\.message-tabs__item\s*\{[\s\S]*flex:\s*1;/);
assert.match(messagePageStyles, /\.message-tabs__item\s*\{[\s\S]*min-width:\s*0;/);
});
run("message tab label and unread dot are grouped in a centered content wrapper", () => {
assert.match(messagePageSource, /className="message-tabs__content"/);
assert.match(messagePageStyles, /\.message-tabs__content\s*\{[\s\S]*display:\s*inline-flex;/);
});
run("message tabs are rendered below AppBar instead of inside bottomSlot", () => {
assert.doesNotMatch(messagePageSource, /bottomSlot=\{/);
assert.match(
messagePageSource,
/<AppBar[\s\S]*\/>\s*<View className="message-tabs">/
);
});