fix: 修正品牌创建与页面方案交互
This commit is contained in:
1 parent
6df4e1d72b
commit
ab17f80607
3 files changed
+321
-1
No files matched your search
@@ -28,6 +28,7 @@ export function CreateBrandPage() {
|
||||
const navigate = useNavigate();
|
||||
const [form] = Form.useForm<CreateBrandInput>();
|
||||
const businessType = Form.useWatch("businessType", form);
|
||||
const selectedSchemeId = Form.useWatch("templatePackageVersionId", form);
|
||||
const options = useQuery({
|
||||
queryKey: ["admin-brand-creation-options"],
|
||||
queryFn: () => client.getAdminBrandCreationOptions(),
|
||||
@@ -190,7 +191,10 @@ export function CreateBrandPage() {
|
||||
htmlType="submit"
|
||||
size="large"
|
||||
loading={create.isPending}
|
||||
disabled={!businessType || schemes.length === 0}
|
||||
disabled={
|
||||
!businessType ||
|
||||
!schemes.some((scheme) => scheme.templatePackageVersionId === selectedSchemeId)
|
||||
}
|
||||
>
|
||||
创建并进入品牌
|
||||
</Button>
|
||||
|
||||
@@ -43,6 +43,7 @@ export function PageSchemePage() {
|
||||
const refresh = () => {
|
||||
for (const queryKey of [
|
||||
"page-scheme-workspace",
|
||||
"admin-page-scheme-options",
|
||||
"page-scheme-upgrade-preview",
|
||||
"admin-workspace",
|
||||
"admin-preview-workspace",
|
||||
|
||||
@@ -0,0 +1,315 @@
|
||||
import { test, expect, type Page, type Route } from "@playwright/test";
|
||||
|
||||
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
||||
|
||||
const businesses = [
|
||||
{ key: "personal", name: "个人品牌", description: "适合独立创作者与个人工作室" },
|
||||
{ key: "doors", name: "门作品牌", description: "适合门作、木作与建筑空间业务" },
|
||||
{ key: "food", name: "餐饮品牌", description: "适合餐饮与本地生活业务" },
|
||||
];
|
||||
|
||||
const pageSchemes = [
|
||||
{
|
||||
templatePackageVersionId: "atelier-v132",
|
||||
name: "独立创作者画册",
|
||||
description: "个人品牌页面方案",
|
||||
version: "1.3.2",
|
||||
supportedBusinessTypes: ["personal"],
|
||||
isLatestForPackage: true,
|
||||
},
|
||||
{
|
||||
templatePackageVersionId: "linjing-v107",
|
||||
name: "林境建筑画册",
|
||||
description: "门作品牌页面方案",
|
||||
version: "1.0.7",
|
||||
supportedBusinessTypes: ["doors"],
|
||||
isLatestForPackage: false,
|
||||
},
|
||||
{
|
||||
templatePackageVersionId: "linjing-v108",
|
||||
name: "林境建筑画册",
|
||||
description: "门作品牌页面方案",
|
||||
version: "1.0.8",
|
||||
supportedBusinessTypes: ["doors"],
|
||||
isLatestForPackage: true,
|
||||
},
|
||||
{
|
||||
templatePackageVersionId: "food-v103",
|
||||
name: "阿成校园餐饮",
|
||||
description: "餐饮品牌页面方案",
|
||||
version: "1.0.3",
|
||||
supportedBusinessTypes: ["food"],
|
||||
isLatestForPackage: true,
|
||||
},
|
||||
];
|
||||
|
||||
const currentBrand = {
|
||||
id: "brand-current",
|
||||
name: "独立工坊",
|
||||
slug: "atelier-studio",
|
||||
templateKey: "personal",
|
||||
};
|
||||
|
||||
const memberships = [{ id: "membership-current", role: "owner", brand: currentBrand }];
|
||||
|
||||
interface ApiMockOptions {
|
||||
createStatus?: number;
|
||||
onCreate?: (body: Record<string, unknown>) => void;
|
||||
onSelectVersion?: (body: Record<string, unknown>) => void;
|
||||
onUpgrade?: (body: Record<string, unknown>) => void;
|
||||
}
|
||||
|
||||
async function mockAdminApi(page: Page, options: ApiMockOptions = {}) {
|
||||
let createStatus = options.createStatus ?? 200;
|
||||
let currentVersion = "1.0.7";
|
||||
let currentPackageVersionId = "linjing-v107";
|
||||
await page.route("**/api/**", async (route: Route) => {
|
||||
const request = route.request();
|
||||
const url = new URL(request.url());
|
||||
const path = url.pathname.replace(/^\/api/, "");
|
||||
const method = request.method();
|
||||
|
||||
if (path === "/admin/session/current") {
|
||||
return route.fulfill({
|
||||
json: {
|
||||
authenticated: true,
|
||||
displayName: "品牌负责人",
|
||||
role: "owner",
|
||||
mustChangePassword: false,
|
||||
platformTemplateRole: "none",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (path === "/admin/config/brand") return route.fulfill({ json: currentBrand });
|
||||
if (path === "/admin/brands" && method === "GET") return route.fulfill({ json: memberships });
|
||||
if (path === "/admin/brands/creation-options") {
|
||||
return route.fulfill({ json: { businesses, pageSchemes } });
|
||||
}
|
||||
if (path === "/admin/brands" && method === "POST") {
|
||||
const body = JSON.parse(request.postData() ?? "{}") as Record<string, unknown>;
|
||||
options.onCreate?.(body);
|
||||
if (createStatus !== 200) {
|
||||
return route.fulfill({
|
||||
status: createStatus,
|
||||
json: {
|
||||
error: { code: "BRAND_SLUG_TAKEN", message: "小程序地址标识已被使用" },
|
||||
requestId: "browser-create-error",
|
||||
},
|
||||
});
|
||||
}
|
||||
return route.fulfill({
|
||||
json: {
|
||||
role: "owner",
|
||||
brand: {
|
||||
id: "brand-created",
|
||||
name: body.name,
|
||||
slug: body.slug,
|
||||
templateKey: body.businessType,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
if (path === "/admin/workspace/template/options") {
|
||||
return route.fulfill({
|
||||
json: {
|
||||
business: businesses[1],
|
||||
pageSchemes: pageSchemes.filter((scheme) =>
|
||||
scheme.supportedBusinessTypes.includes("doors"),
|
||||
),
|
||||
},
|
||||
});
|
||||
}
|
||||
if (path === "/admin/workspace/template/preview") {
|
||||
return route.fulfill({
|
||||
json: {
|
||||
templateKey: "doors",
|
||||
currentVersion: "1.0.7",
|
||||
latestVersion: "1.0.8",
|
||||
canUpgrade: true,
|
||||
canRollback: false,
|
||||
currentPackageVersionId: "linjing-v107",
|
||||
currentContentChecksum: "current-checksum",
|
||||
targetPackageVersionId: "linjing-v108",
|
||||
targetContentChecksum: "target-checksum",
|
||||
changes: {
|
||||
brandFields: { available: false, reason: "不适用" },
|
||||
templateBindings: { added: [], changed: [], removed: [] },
|
||||
pages: { added: [], changed: [], removed: [] },
|
||||
modules: {
|
||||
available: true,
|
||||
source: "platform_visual_manifest",
|
||||
packageUpgradeChangesRenderer: false,
|
||||
pages: [],
|
||||
},
|
||||
assets: {
|
||||
slots: { added: [], changed: [], removed: [] },
|
||||
files: { available: false, reason: "不适用" },
|
||||
},
|
||||
capabilities: { added: [], removed: [] },
|
||||
renderer: {
|
||||
available: true,
|
||||
source: "platform_visual_manifest",
|
||||
packageUpgradeChangesRenderer: false,
|
||||
pages: [],
|
||||
},
|
||||
package: {
|
||||
currentContentChecksum: "current-checksum",
|
||||
targetContentChecksum: "target-checksum",
|
||||
runtimeContract: { current: null, target: null },
|
||||
},
|
||||
},
|
||||
conflicts: [{ key: "hero.title", binding: "brand.name", reason: "自定义标题" }],
|
||||
},
|
||||
});
|
||||
}
|
||||
if (path === "/admin/workspace/template/select-version" && method === "POST") {
|
||||
options.onSelectVersion?.(JSON.parse(request.postData() ?? "{}") as Record<string, unknown>);
|
||||
currentVersion = "1.0.8";
|
||||
currentPackageVersionId = "linjing-v108";
|
||||
return route.fulfill({ json: { selected: true } });
|
||||
}
|
||||
if (path === "/admin/workspace/template/upgrade" && method === "POST") {
|
||||
options.onUpgrade?.(JSON.parse(request.postData() ?? "{}") as Record<string, unknown>);
|
||||
currentVersion = "1.0.8";
|
||||
currentPackageVersionId = "linjing-v108";
|
||||
return route.fulfill({ json: { upgraded: true } });
|
||||
}
|
||||
if (path === "/admin/workspace") {
|
||||
return route.fulfill({
|
||||
json: {
|
||||
brand: currentBrand,
|
||||
installations: [
|
||||
{
|
||||
templateVersion: currentVersion,
|
||||
templatePackageVersionId: currentPackageVersionId,
|
||||
templateKey: "doors",
|
||||
},
|
||||
],
|
||||
templateContent: { displayName: "林境建筑画册" },
|
||||
offerings: [],
|
||||
forms: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
if (path === "/admin/releases/readiness") {
|
||||
return route.fulfill({ json: { ready: true, checks: [] } });
|
||||
}
|
||||
if (
|
||||
path === "/admin/config/trust-content" ||
|
||||
path === "/admin/workspace/offerings" ||
|
||||
path === "/admin/workspace/submissions"
|
||||
) {
|
||||
return route.fulfill({ json: [] });
|
||||
}
|
||||
return route.fulfill({ json: {} });
|
||||
});
|
||||
return {
|
||||
failCreate: () => {
|
||||
createStatus = 400;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
test("创建品牌成功后进入新品牌工作区", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
let createdBody: Record<string, unknown> | undefined;
|
||||
await mockAdminApi(page, { onCreate: (body) => (createdBody = body) });
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/brands/new`);
|
||||
await page.getByText("个人品牌", { exact: true }).click();
|
||||
await page.getByText(/最新版 1\.3\.2/).click();
|
||||
await page.getByLabel("品牌名称").fill("新的独立品牌");
|
||||
await page.getByLabel("小程序地址标识").fill("new-atelier");
|
||||
await page.getByRole("button", { name: "创建并进入品牌" }).click();
|
||||
|
||||
await expect
|
||||
.poll(() => createdBody)
|
||||
.toEqual({
|
||||
name: "新的独立品牌",
|
||||
slug: "new-atelier",
|
||||
businessType: "personal",
|
||||
templatePackageVersionId: "atelier-v132",
|
||||
});
|
||||
await page.waitForURL("**/admin/overview");
|
||||
await expect(page.getByRole("heading", { name: "品牌概览" })).toBeVisible();
|
||||
});
|
||||
|
||||
test("创建品牌按业务类型过滤页面方案,失败后保留输入", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
let createdBody: Record<string, unknown> | undefined;
|
||||
const api = await mockAdminApi(page, { onCreate: (body) => (createdBody = body) });
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/brands/new`);
|
||||
await expect(page.getByRole("heading", { name: "创建品牌" })).toBeVisible();
|
||||
await expect(page.getByText("先选择业务类型")).toBeVisible();
|
||||
|
||||
await page.getByText("个人品牌", { exact: true }).click();
|
||||
await expect(page.getByText("独立创作者画册")).toBeVisible();
|
||||
await expect(page.getByText("林境建筑画册")).toBeHidden();
|
||||
|
||||
await page.getByText("门作品牌", { exact: true }).click();
|
||||
await expect(page.getByText("林境建筑画册").first()).toBeVisible();
|
||||
await expect(page.getByText("独立创作者画册")).toBeHidden();
|
||||
await page.getByText(/最新版 1\.0\.8/).click();
|
||||
|
||||
await page.getByText("个人品牌", { exact: true }).click();
|
||||
await expect(page.getByRole("button", { name: "创建并进入品牌" })).toBeDisabled();
|
||||
await page.getByText(/最新版 1\.3\.2/).click();
|
||||
|
||||
await page.getByLabel("品牌名称").fill("测试独立品牌");
|
||||
await page.getByLabel("小程序地址标识").fill("test-atelier");
|
||||
|
||||
api.failCreate();
|
||||
await page.getByRole("button", { name: "创建并进入品牌" }).click();
|
||||
await expect(page.locator(".admin-error-note")).toContainText("小程序地址标识已被使用");
|
||||
await expect(page.getByLabel("品牌名称")).toHaveValue("测试独立品牌");
|
||||
await expect(page.getByLabel("小程序地址标识")).toHaveValue("test-atelier");
|
||||
expect(createdBody).toEqual({
|
||||
name: "测试独立品牌",
|
||||
slug: "test-atelier",
|
||||
businessType: "personal",
|
||||
templatePackageVersionId: "atelier-v132",
|
||||
});
|
||||
});
|
||||
|
||||
test("页面方案切换和升级提交正确契约,并刷新查询缓存", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
let selectBody: Record<string, unknown> | undefined;
|
||||
let upgradeBody: Record<string, unknown> | undefined;
|
||||
await mockAdminApi(page, {
|
||||
onSelectVersion: (body) => (selectBody = body),
|
||||
onUpgrade: (body) => (upgradeBody = body),
|
||||
});
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/page-scheme`);
|
||||
await expect(page.getByRole("heading", { name: "页面方案" })).toBeVisible();
|
||||
await expect(page.getByText("门作品牌", { exact: true })).toBeVisible();
|
||||
await expect(page.getByText("正在使用版本 1.0.7")).toBeVisible();
|
||||
await expect(page.getByText("独立创作者画册")).toBeHidden();
|
||||
await expect(page.getByRole("button", { name: "恢复上一版配置" })).toBeDisabled();
|
||||
|
||||
await page.getByRole("button", { name: "切换到此版本" }).click();
|
||||
await page.getByRole("button", { name: "确认切换" }).click();
|
||||
await expect.poll(() => selectBody).toBeTruthy();
|
||||
expect(selectBody).toEqual({
|
||||
templatePackageVersionId: "linjing-v108",
|
||||
expectedCurrentPackageVersionId: "linjing-v107",
|
||||
confirm: true,
|
||||
});
|
||||
await expect(page.getByText("页面方案版本已切换")).toBeVisible();
|
||||
await expect(page.getByText("正在使用版本 1.0.8")).toBeVisible();
|
||||
|
||||
await page.getByRole("button", { name: "升级到 1.0.8" }).click();
|
||||
await expect(page.getByText("将升级到版本 1.0.8,并全部保留 1 项现有内容。")).toBeVisible();
|
||||
await page.getByRole("button", { name: "确认升级" }).click();
|
||||
await expect.poll(() => upgradeBody).toBeTruthy();
|
||||
expect(upgradeBody).toMatchObject({
|
||||
templatePackageVersionId: "linjing-v108",
|
||||
expectedContentChecksum: "target-checksum",
|
||||
expectedCurrentVersion: "1.0.7",
|
||||
expectedCurrentPackageVersionId: "linjing-v107",
|
||||
confirm: true,
|
||||
preservedBindings: [{ key: "hero.title", binding: "brand.name", action: "preserve" }],
|
||||
});
|
||||
await expect(page.getByText("页面方案已升级,现有内容已全部保留")).toBeVisible();
|
||||
});
|
||||
Reference in new issue
Block a user