Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e752a3b7ed | ||
|
|
9389235a6c | ||
|
|
a293591dba |
No files matched your search
@@ -91,6 +91,16 @@ Admin 浏览器回归新增 `apps/taro/test/browser/brand-creation-and-page-sche
|
||||
- 页面方案切换和升级提交正确版本、校验和与冲突保留参数。
|
||||
- 操作成功后刷新工作区、页面方案选项和升级预览查询。
|
||||
|
||||
`apps/taro/test/browser/publication-release.spec.ts` 覆盖内容与发布流程:
|
||||
|
||||
- 发布按钮按 readiness 启用;空备注发布提交空 body,不写入 `note`。
|
||||
- 备注提交前去除首尾空格。
|
||||
- 发布失败时保留备注与确认弹窗,并显示服务端错误。
|
||||
- 撤回当前版本、恢复历史版本分别提交正确路径与版本号。
|
||||
- 小程序配置页从服务端回填设置,只提交用户新输入的私钥。
|
||||
|
||||
该回归同时发现并修复了 `MiniAppSettingsTab` 的 `Form` 实例归属问题:表单实例原本在父组件创建、子组件懒挂载,触发 antd `useForm` 未连接警告;现已下沉到配置页自身。
|
||||
|
||||
## Ant Design 6 弃用项
|
||||
|
||||
- `Alert` 统一使用 `title`,`Space` 统一使用 `orientation`。
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect } from "react";
|
||||
import { Alert, Button, Form, Input, Space } from "antd";
|
||||
import type { FormInstance } from "antd";
|
||||
import type { MiniAppReleaseSettings } from "@personal-brand/api-client";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { MutationError } from "../../components/QueryState.js";
|
||||
@@ -12,20 +12,24 @@ export type MiniAppSettingsValues = {
|
||||
};
|
||||
|
||||
interface MiniAppSettingsTabProps {
|
||||
form: FormInstance<MiniAppSettingsValues>;
|
||||
settings: MiniAppReleaseSettings | undefined;
|
||||
saving: boolean;
|
||||
error?: unknown;
|
||||
onSave: (values: MiniAppSettingsValues) => void;
|
||||
}
|
||||
|
||||
export function MiniAppSettingsTab({
|
||||
form,
|
||||
settings,
|
||||
saving,
|
||||
error,
|
||||
onSave,
|
||||
}: MiniAppSettingsTabProps) {
|
||||
export function MiniAppSettingsTab({ settings, saving, error, onSave }: MiniAppSettingsTabProps) {
|
||||
const [form] = Form.useForm<MiniAppSettingsValues>();
|
||||
|
||||
useEffect(() => {
|
||||
if (!settings) return;
|
||||
form.setFieldsValue({
|
||||
appId: settings.appId,
|
||||
apiBaseUrl: settings.apiBaseUrl,
|
||||
privateKey: "",
|
||||
});
|
||||
}, [form, settings]);
|
||||
|
||||
return (
|
||||
<div className="admin-stack admin-stack-lg">
|
||||
<AdminSection
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { Alert, Button, Divider, Form, Input, Modal, Space, Tabs, Typography } from "antd";
|
||||
import { Alert, Button, Divider, Input, Modal, Space, Tabs, Typography } from "antd";
|
||||
import { AdminPageHeader } from "../../components/AdminPageHeader.js";
|
||||
import { AdminSection } from "../../components/AdminSection.js";
|
||||
import { EmptyState } from "../../components/EmptyState.js";
|
||||
import { MutationError, QueryState } from "../../components/QueryState.js";
|
||||
import { StatusTag, statusLabel } from "../../components/StatusTag.js";
|
||||
import { MiniAppReleaseCard } from "./MiniAppReleaseCard.js";
|
||||
import { MiniAppSettingsTab, type MiniAppSettingsValues } from "./MiniAppSettingsTab.js";
|
||||
import { MiniAppSettingsTab } from "./MiniAppSettingsTab.js";
|
||||
import { usePublicationQueries } from "./use-publication-queries.js";
|
||||
import { usePublicationMutations } from "./use-publication-mutations.js";
|
||||
|
||||
@@ -29,8 +29,7 @@ export function PublicationPage() {
|
||||
const [rollbackVersion, setRollbackVersion] = useState<number | null>(null);
|
||||
const [note, setNote] = useState("");
|
||||
const [activeTab, setActiveTab] = useState("content");
|
||||
const [miniAppSettingsForm] = Form.useForm<MiniAppSettingsValues>();
|
||||
const queries = usePublicationQueries(miniAppSettingsForm);
|
||||
const queries = usePublicationQueries();
|
||||
const {
|
||||
workspace,
|
||||
readiness,
|
||||
@@ -255,7 +254,6 @@ export function PublicationPage() {
|
||||
label: "小程序配置",
|
||||
children: (
|
||||
<MiniAppSettingsTab
|
||||
form={miniAppSettingsForm}
|
||||
settings={miniAppSettings.data}
|
||||
saving={saveMiniAppSettings.isPending}
|
||||
error={saveMiniAppSettings.error}
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
import { useEffect } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type { FormInstance } from "antd";
|
||||
import { createApiClient } from "../../lib/api.js";
|
||||
|
||||
const client = createApiClient();
|
||||
|
||||
export function usePublicationQueries(
|
||||
miniAppSettingsForm: FormInstance<{
|
||||
appId: string;
|
||||
apiBaseUrl: string;
|
||||
privateKey?: string;
|
||||
}>,
|
||||
) {
|
||||
export function usePublicationQueries() {
|
||||
const brand = useQuery<Awaited<ReturnType<typeof client.getAdminBrand>>>({
|
||||
queryKey: ["publication-brand"],
|
||||
queryFn: () => client.getAdminBrand(),
|
||||
@@ -37,15 +30,6 @@ export function usePublicationQueries(
|
||||
queryFn: () => client.getAdminMiniAppSettings(),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!miniAppSettings.data) return;
|
||||
miniAppSettingsForm.setFieldsValue({
|
||||
appId: miniAppSettings.data.appId,
|
||||
apiBaseUrl: miniAppSettings.data.apiBaseUrl,
|
||||
privateKey: "",
|
||||
});
|
||||
}, [miniAppSettings.data, miniAppSettingsForm]);
|
||||
|
||||
useEffect(() => {
|
||||
const building = miniAppReleases.data?.find(
|
||||
(task) =>
|
||||
|
||||
@@ -0,0 +1,310 @@
|
||||
import { test, expect, type Page, type Route } from "@playwright/test";
|
||||
|
||||
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
||||
|
||||
const pageErrors = new WeakMap<Page, string[]>();
|
||||
|
||||
test.beforeEach(({ page }) => {
|
||||
const errors: string[] = [];
|
||||
pageErrors.set(page, errors);
|
||||
page.on("pageerror", (error) => errors.push(error.message));
|
||||
});
|
||||
|
||||
test.afterEach(({ page }) => {
|
||||
expect(pageErrors.get(page) ?? []).toEqual([]);
|
||||
});
|
||||
|
||||
interface ReleaseRow {
|
||||
id: string;
|
||||
version: number;
|
||||
status: string;
|
||||
note: string | null;
|
||||
actorId: string;
|
||||
createdAt: string;
|
||||
revokedAt: string | null;
|
||||
}
|
||||
|
||||
interface MockOptions {
|
||||
ready?: boolean;
|
||||
onPublish?: (body: Record<string, unknown>) => void;
|
||||
onRollback?: (body: Record<string, unknown>, version: number) => void;
|
||||
onRevoke?: () => void;
|
||||
publishStatus?: number;
|
||||
}
|
||||
|
||||
async function mockPublicationApi(page: Page, options: MockOptions = {}) {
|
||||
const releases: ReleaseRow[] = [
|
||||
{
|
||||
id: "release-2",
|
||||
version: 2,
|
||||
status: "published",
|
||||
note: "第二版",
|
||||
actorId: "actor-1",
|
||||
createdAt: "2026-10-20T02:00:00.000Z",
|
||||
revokedAt: null,
|
||||
},
|
||||
{
|
||||
id: "release-1",
|
||||
version: 1,
|
||||
status: "superseded",
|
||||
note: null,
|
||||
actorId: "actor-1",
|
||||
createdAt: "2026-10-19T02:00:00.000Z",
|
||||
revokedAt: null,
|
||||
},
|
||||
];
|
||||
|
||||
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: {
|
||||
id: "brand-current",
|
||||
name: "独立工坊",
|
||||
slug: "atelier-studio",
|
||||
templateKey: "personal",
|
||||
},
|
||||
});
|
||||
}
|
||||
if (path === "/admin/brands" && method === "GET") {
|
||||
return route.fulfill({
|
||||
json: [
|
||||
{
|
||||
id: "membership-current",
|
||||
role: "owner",
|
||||
brand: {
|
||||
id: "brand-current",
|
||||
name: "独立工坊",
|
||||
slug: "atelier-studio",
|
||||
templateKey: "personal",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (path === "/admin/workspace") {
|
||||
return route.fulfill({
|
||||
json: {
|
||||
brand: { id: "brand-current", name: "独立工坊" },
|
||||
installations: [],
|
||||
templateContent: { displayName: "独立创作者画册" },
|
||||
offerings: [],
|
||||
forms: [],
|
||||
},
|
||||
});
|
||||
}
|
||||
if (path === "/admin/releases/readiness") {
|
||||
return route.fulfill({
|
||||
json: {
|
||||
ready: options.ready ?? true,
|
||||
checks: [
|
||||
{ key: "brand", label: "品牌资料", passed: true },
|
||||
{
|
||||
key: "offerings",
|
||||
label: "业务提供项",
|
||||
passed: options.ready ?? true,
|
||||
help: "至少添加一个业务提供项",
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
if (path === "/admin/releases" && method === "GET") {
|
||||
return route.fulfill({ json: releases });
|
||||
}
|
||||
if (path === "/admin/releases/publish" && method === "POST") {
|
||||
const body = JSON.parse(request.postData() ?? "{}") as Record<string, unknown>;
|
||||
options.onPublish?.(body);
|
||||
if (options.publishStatus && options.publishStatus !== 200) {
|
||||
return route.fulfill({
|
||||
status: options.publishStatus,
|
||||
json: {
|
||||
error: { code: "RELEASE_FAILED", message: "发布检查未通过" },
|
||||
requestId: "browser-release-error",
|
||||
},
|
||||
});
|
||||
}
|
||||
for (const item of releases) item.status = "superseded";
|
||||
const created: ReleaseRow = {
|
||||
id: "release-3",
|
||||
version: 3,
|
||||
status: "published",
|
||||
note: typeof body.note === "string" ? body.note : null,
|
||||
actorId: "actor-1",
|
||||
createdAt: "2026-10-21T02:00:00.000Z",
|
||||
revokedAt: null,
|
||||
};
|
||||
releases.unshift(created);
|
||||
return route.fulfill({ json: created });
|
||||
}
|
||||
if (path === "/admin/releases/revoke" && method === "POST") {
|
||||
options.onRevoke?.();
|
||||
return route.fulfill({ json: { revoked: true } });
|
||||
}
|
||||
const rollback = path.match(/^\/admin\/releases\/(\d+)\/rollback$/);
|
||||
if (rollback && method === "POST") {
|
||||
const body = JSON.parse(request.postData() ?? "{}") as Record<string, unknown>;
|
||||
options.onRollback?.(body, Number(rollback[1]));
|
||||
for (const item of releases) item.status = "superseded";
|
||||
const created: ReleaseRow = {
|
||||
id: "release-rollback",
|
||||
version: 4,
|
||||
status: "published",
|
||||
note: null,
|
||||
actorId: "actor-1",
|
||||
createdAt: "2026-10-21T03:00:00.000Z",
|
||||
revokedAt: null,
|
||||
};
|
||||
releases.unshift(created);
|
||||
return route.fulfill({ json: created });
|
||||
}
|
||||
if (path === "/admin/miniapp-releases") return route.fulfill({ json: [] });
|
||||
if (path === "/admin/miniapp-releases/settings") {
|
||||
return route.fulfill({
|
||||
json: {
|
||||
appId: "wx0000000000000000",
|
||||
apiBaseUrl: "https://wechat.app.que01.top/api",
|
||||
hasStoredCredentials: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
return route.fulfill({ json: {} });
|
||||
});
|
||||
}
|
||||
|
||||
test("发布按钮按就绪状态启用,空备注发布不写入 note", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
const bodies: Record<string, unknown>[] = [];
|
||||
await mockPublicationApi(page, { onPublish: (body) => bodies.push(body) });
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/publication`);
|
||||
await expect(page.getByRole("heading", { name: "内容与发布" })).toBeVisible();
|
||||
await page.getByRole("button", { name: "发布当前草稿" }).click();
|
||||
await page.getByRole("button", { name: "确认发布" }).click();
|
||||
|
||||
await expect.poll(() => bodies).toEqual([{}]);
|
||||
await expect(page.getByText("品牌已发布")).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "确认发布" })).toBeHidden();
|
||||
await expect(page.getByText("v3")).toBeVisible();
|
||||
});
|
||||
|
||||
test("发布备注会去除首尾空格并随请求提交", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
const bodies: Record<string, unknown>[] = [];
|
||||
await mockPublicationApi(page, { onPublish: (body) => bodies.push(body) });
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/publication`);
|
||||
await page.getByRole("button", { name: "发布当前草稿" }).click();
|
||||
await page.getByPlaceholder("发布备注(可选)").fill(" 国庆版本 ");
|
||||
await page.getByRole("button", { name: "确认发布" }).click();
|
||||
|
||||
await expect.poll(() => bodies).toEqual([{ note: "国庆版本" }]);
|
||||
await expect(page.getByText("国庆版本")).toBeVisible();
|
||||
});
|
||||
|
||||
test("发布失败时保留备注与确认弹窗", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await mockPublicationApi(page, { publishStatus: 409 });
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/publication`);
|
||||
await page.getByRole("button", { name: "发布当前草稿" }).click();
|
||||
await page.getByPlaceholder("发布备注(可选)").fill("待重试的版本");
|
||||
await page.getByRole("button", { name: "确认发布" }).click();
|
||||
|
||||
await expect(page.getByText("发布检查未通过")).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "确认发布" })).toBeVisible();
|
||||
await expect(page.getByPlaceholder("发布备注(可选)")).toHaveValue("待重试的版本");
|
||||
});
|
||||
|
||||
test("未通过发布检查时禁用发布按钮", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
await mockPublicationApi(page, { ready: false });
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/publication`);
|
||||
await expect(page.getByRole("button", { name: "发布当前草稿" })).toBeDisabled();
|
||||
await expect(page.getByText("至少添加一个业务提供项")).toBeVisible();
|
||||
});
|
||||
|
||||
test("撤回当前版本并刷新发布记录", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
let revoked = 0;
|
||||
await mockPublicationApi(page, { onRevoke: () => (revoked += 1) });
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/publication`);
|
||||
await page.getByRole("button", { name: "撤回当前版本" }).click();
|
||||
await page.getByRole("button", { name: "确认撤回" }).click();
|
||||
|
||||
await expect.poll(() => revoked).toBe(1);
|
||||
await expect(page.getByText("品牌已撤回,小程序将显示未发布状态")).toBeVisible();
|
||||
});
|
||||
|
||||
test("恢复历史版本会提交版本号并刷新发布记录", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
const requests: Array<{ body: Record<string, unknown>; version: number }> = [];
|
||||
await mockPublicationApi(page, {
|
||||
onRollback: (body, version) => requests.push({ body, version }),
|
||||
});
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/publication`);
|
||||
await page.getByRole("button", { name: "恢复此版本" }).click();
|
||||
await page.getByRole("button", { name: "确 定" }).click();
|
||||
|
||||
await expect.poll(() => requests).toEqual([{ body: {}, version: 1 }]);
|
||||
await expect(page.getByText("历史版本已重新发布")).toBeVisible();
|
||||
});
|
||||
|
||||
test("小程序配置页回填服务端设置并仅提交新私钥", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
||||
const bodies: Record<string, unknown>[] = [];
|
||||
await mockPublicationApi(page, {});
|
||||
await page.route("**/api/admin/miniapp-releases/settings", async (route) => {
|
||||
if (route.request().method() === "PATCH") {
|
||||
const body = JSON.parse(route.request().postData() ?? "{}") as Record<string, unknown>;
|
||||
bodies.push(body);
|
||||
return route.fulfill({
|
||||
json: {
|
||||
appId: body.appId,
|
||||
apiBaseUrl: body.apiBaseUrl,
|
||||
hasStoredCredentials: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
return route.fallback();
|
||||
});
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/publication`);
|
||||
await page.getByRole("tab", { name: "小程序配置" }).click();
|
||||
await expect(page.getByLabel("微信 AppID")).toHaveValue("wx0000000000000000");
|
||||
await expect(page.getByLabel("小程序请求地址")).toHaveValue("https://wechat.app.que01.top/api");
|
||||
|
||||
await page
|
||||
.getByLabel("上传私钥")
|
||||
.fill("-----BEGIN PRIVATE KEY-----\nKEY\n-----END PRIVATE KEY-----");
|
||||
await page.getByRole("button", { name: "保存上传配置" }).click();
|
||||
|
||||
await expect
|
||||
.poll(() => bodies)
|
||||
.toEqual([
|
||||
{
|
||||
appId: "wx0000000000000000",
|
||||
apiBaseUrl: "https://wechat.app.que01.top/api",
|
||||
privateKey: "-----BEGIN PRIVATE KEY-----\nKEY\n-----END PRIVATE KEY-----",
|
||||
},
|
||||
]);
|
||||
await expect(page.getByText("小程序上传配置已保存")).toBeVisible();
|
||||
});
|
||||
Reference in new issue
Block a user