feat: 新增 Taro 模板双端运行与独立 Web 预览
This commit is contained in:
1 parent
f4061a24bd
commit
7e8fc01fba
48 files changed
+11576
-12
No files matched your search
@@ -0,0 +1,81 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
test("真实 API 驱动首页、出摊和主理人视觉槽位", async ({ page }) => {
|
||||
const errors: string[] = [];
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
await page.goto("/");
|
||||
await expect(page.locator(".food-home .name")).toContainText("阿成");
|
||||
const widths = await page.locator(".scene").evaluate((element) => ({
|
||||
image: element.getBoundingClientRect().width,
|
||||
parent: element.parentElement!.getBoundingClientRect().width,
|
||||
}));
|
||||
expect(Math.abs(widths.image - widths.parent)).toBeLessThan(2);
|
||||
await page.getByText("出摊服务", { exact: true }).click();
|
||||
await expect(page.locator(".schedule")).toHaveCount(2);
|
||||
await expect(page.locator(".delivery-item")).toHaveCount(2);
|
||||
await expect(page.locator(".step")).toHaveCount(4);
|
||||
await page.screenshot({
|
||||
path: "../../.codex-tasks/taro-migration/raw/food-service.png",
|
||||
fullPage: true,
|
||||
});
|
||||
await page.getByText("主理人", { exact: true }).click();
|
||||
await expect(page.locator(".standard")).toHaveCount(3);
|
||||
await expect(page.locator(".case-row")).toHaveCount(3);
|
||||
await expect(page.locator(".commitment")).toHaveCount(2);
|
||||
await page.screenshot({
|
||||
path: "../../.codex-tasks/taro-migration/raw/food-profile.png",
|
||||
fullPage: true,
|
||||
});
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
test("餐品搜索、详情和咨询目标传递", async ({ page }) => {
|
||||
await page.goto("/#/pages/offerings/index");
|
||||
await expect(page.locator(".offering-card").first()).toBeVisible();
|
||||
await page.locator("input").fill("不存在的餐品名称");
|
||||
await expect(page.getByText("没有找到相关餐品,换个词试试")).toBeVisible();
|
||||
await page.locator("input").fill("");
|
||||
const name = await page.locator(".dish-name").first().textContent();
|
||||
await page.locator(".offering-card").first().click();
|
||||
await expect(page.locator(".hero-copy")).toContainText(name!);
|
||||
await page.locator(".bar taro-button-core").click();
|
||||
await expect(page.locator(".inquiry-form")).toBeVisible();
|
||||
await expect(page.locator(".half-field")).toHaveCount(4);
|
||||
});
|
||||
test("失败和未登录不清空表单,不伪造提交成功", async ({ page }) => {
|
||||
await page.goto("/#/pages/inquiry/index");
|
||||
await expect(page.locator(".inquiry-form")).toBeVisible();
|
||||
await page.locator(".submit-button").click();
|
||||
await expect(page.locator(".form-error")).toContainText("请填写");
|
||||
const input = page.locator("input:not([type=hidden])").last();
|
||||
await input.fill("13800138000");
|
||||
await page.locator(".submit-button").click();
|
||||
await expect(input).toHaveValue("13800138000");
|
||||
await expect(page).not.toHaveURL(/success/);
|
||||
});
|
||||
test("加载失败提供重试", async ({ page }) => {
|
||||
await page.route("**/public/workspace**", (route) =>
|
||||
route.fulfill({
|
||||
status: 503,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ error: { message: "测试服务暂不可用" } }),
|
||||
}),
|
||||
);
|
||||
await page.goto("/");
|
||||
await expect(page.getByText("测试服务暂不可用")).toBeVisible();
|
||||
await expect(page.getByText("重试")).toBeVisible();
|
||||
});
|
||||
|
||||
test("林境模板使用真实品牌数据与独立路由", async ({ page }) => {
|
||||
const errors: string[] = [];
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
await page.goto("http://localhost:3003/");
|
||||
await expect(page.locator(".founder-name")).toContainText("林");
|
||||
await expect(page.locator(".stat-value")).toHaveCount(4);
|
||||
await page.getByText("主理人与我", { exact: true }).click();
|
||||
await expect(page.locator(".editorial-profile .founder")).toBeVisible();
|
||||
await expect(page.locator(".trust-card").first()).toBeVisible();
|
||||
await page.screenshot({
|
||||
path: "../../.codex-tasks/taro-migration/raw/linjing-profile.png",
|
||||
fullPage: true,
|
||||
});
|
||||
expect(errors).toEqual([]);
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
const root = path.resolve(import.meta.dirname, "../../..");
|
||||
for (const key of ["acheng-campus-food", "linjing-editorial"])
|
||||
test(`${key} 两端产物有真实入口及模板导航`, () => {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(root, `packages/template-${key}/template.json`)),
|
||||
);
|
||||
const base = path.join(root, `apps/taro/dist/${key}`);
|
||||
const config = JSON.parse(fs.readFileSync(path.join(base, "weapp/app.json")));
|
||||
assert.equal(config.pages.length, 8);
|
||||
assert.deepEqual(
|
||||
config.tabBar.list.map((item) => item.text),
|
||||
manifest.navigation.map((item) => item.label),
|
||||
);
|
||||
for (const page of config.pages)
|
||||
for (const ext of ["js", "wxml", "json"])
|
||||
assert.ok(fs.existsSync(path.join(base, "weapp", `${page}.${ext}`)), `${page}.${ext}`);
|
||||
assert.ok(fs.readFileSync(path.join(base, "h5/index.html"), "utf8").includes('type="module"'));
|
||||
assert.ok(fs.existsSync(path.join(base, "weapp/project.config.json")));
|
||||
assert.ok(fs.readFileSync(path.join(base, "weapp/common.wxss"), "utf8").length > 1000);
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { missingField, visibleFields, slot, offering } from "../src/runtime/content.ts";
|
||||
test("条件字段与空数组校验使用实际显示字段", () => {
|
||||
const fields = [
|
||||
{ key: "type", type: "select", label: "类型", required: true },
|
||||
{
|
||||
key: "choices",
|
||||
type: "checkbox",
|
||||
label: "选项",
|
||||
required: true,
|
||||
visibleWhen: [{ field: "type", operator: "equals", value: "group" }],
|
||||
},
|
||||
];
|
||||
assert.equal(visibleFields(fields, { type: "daily" }).length, 1);
|
||||
assert.equal(missingField(fields, { type: "group", choices: [] }).key, "choices");
|
||||
assert.equal(missingField(fields, { type: "group", choices: ["a"] }), undefined);
|
||||
});
|
||||
test("结构化来源优先,详情使用公开投影", () => {
|
||||
const item = slot(
|
||||
{
|
||||
trustItems: [
|
||||
{ type: "credential", config: {}, content: "old" },
|
||||
{ type: "credential", config: { standards: [] }, content: "edited" },
|
||||
],
|
||||
},
|
||||
"credential",
|
||||
);
|
||||
assert.equal(item.content, "edited");
|
||||
const data = offering({
|
||||
id: "a",
|
||||
summary: "摘要",
|
||||
coverUrl: "cover",
|
||||
priceText: "报价",
|
||||
presentation: {
|
||||
categoryLabel: "套餐",
|
||||
heroImage: "hero",
|
||||
keywords: [],
|
||||
details: { background: "实际餐品说明" },
|
||||
},
|
||||
});
|
||||
assert.equal(data.image, "hero");
|
||||
assert.equal(data.details.background, "实际餐品说明");
|
||||
});
|
||||
Reference in new issue
Block a user