|
| 1 | +import { resolve } from "node:path"; |
| 2 | +import { outputDir } from "./fixture.mjs"; |
| 3 | +import { openWorkspacePage } from "./scenario-context.mjs"; |
| 4 | + |
| 5 | +export const blockedNoticeSettingsScenario = { |
| 6 | + id: "blocked-notice-settings", |
| 7 | + async run({ browser, collectCoverage, url }) { |
| 8 | + const notificationProjection = { |
| 9 | + schema_version: "loopx_goal_channel_notification_projection_v0", |
| 10 | + goals: [{ |
| 11 | + goal_id: "product-release", configured: true, enabled: true, |
| 12 | + human_gate_auto_notify_enabled: false, blocked_notice_auto_notify_enabled: false, |
| 13 | + receipt_count: 1, |
| 14 | + blocked_notice_delivery: { delivered_count: 1, unverified_count: 0, resolved_count: 0 }, |
| 15 | + }], |
| 16 | + }; |
| 17 | + const requests = []; |
| 18 | + const context = await openWorkspacePage(browser, url, { |
| 19 | + collectCoverage, |
| 20 | + apiOptions: { notificationProjection }, |
| 21 | + beforeGoto: async (_api, page) => { |
| 22 | + await page.route("**/api/chat/goal-channel/configure", async (route) => { |
| 23 | + const body = route.request().postDataJSON(); |
| 24 | + requests.push(body); |
| 25 | + notificationProjection.goals[0].blocked_notice_auto_notify_enabled = body.auto_notify_blocked_notices === true; |
| 26 | + await route.fulfill({ contentType: "application/json", json: { |
| 27 | + ok: true, status: "configured", public_summary: "updated", readback_verified: true, |
| 28 | + }, status: 200 }); |
| 29 | + }); |
| 30 | + }, |
| 31 | + }); |
| 32 | + const { page } = context; |
| 33 | + try { |
| 34 | + await page.getByRole("button", { name: "设置", exact: true }).click(); |
| 35 | + await page.getByRole("button", { name: "能力中心", exact: true }).click(); |
| 36 | + await page.getByRole("radio", { name: "单个 Goal", exact: true }).check(); |
| 37 | + await page.getByRole("combobox", { name: "目标 Goal", exact: true }).selectOption("product-release"); |
| 38 | + await page.getByRole("navigation", { name: "Goal 能力目录" }) |
| 39 | + .getByRole("button", { name: /飞书事件收件箱/ }).click(); |
| 40 | + const toggle = page.getByLabel("任务受阻时推送到此目标群"); |
| 41 | + await toggle.waitFor(); |
| 42 | + await page.getByText("受阻通知:已核验 1 条,未核验 0 条,已解除 0 条").waitFor(); |
| 43 | + await page.screenshot({ path: resolve(outputDir, "blocked-notice-settings.png"), animations: "disabled" }); |
| 44 | + await toggle.click(); |
| 45 | + if (requests.length !== 1 || requests[0].goal_id !== "product-release" |
| 46 | + || requests[0].auto_notify_blocked_notices !== true |
| 47 | + || "auto_notify_human_gates" in requests[0]) { |
| 48 | + throw new Error(`Blocked notice toggle sent the wrong request: ${JSON.stringify(requests)}`); |
| 49 | + } |
| 50 | + await page.waitForFunction(() => { |
| 51 | + const input = [...document.querySelectorAll("input[type=checkbox]")] |
| 52 | + .find((item) => item.closest("label")?.textContent?.includes("任务受阻时推送到此目标群")); |
| 53 | + return input?.checked === true; |
| 54 | + }); |
| 55 | + await page.setViewportSize({ width: 390, height: 844 }); |
| 56 | + await page.screenshot({ path: resolve(outputDir, "blocked-notice-settings-mobile.png"), animations: "disabled" }); |
| 57 | + if (await page.evaluate(() => document.documentElement.scrollWidth > innerWidth + 1)) { |
| 58 | + throw new Error("Blocked notice settings overflow the narrow viewport"); |
| 59 | + } |
| 60 | + if (context.errors.length) throw new Error(context.errors.join(" | ")); |
| 61 | + return { coverageEntries: await context.close(), note: "Goal Channel blocked notice opt-in, readback, and mobile layout verified." }; |
| 62 | + } catch (error) { await context.close(); throw error; } |
| 63 | + }, |
| 64 | +}; |
0 commit comments