offPeakNewTaskEntry.test.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
  4. import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
  5. import { BUILTIN_MODEL_PROVIDER_IDS } from "@zcode/shared";
  6. const h = vi.hoisted(() => {
  7. const initialize = vi.fn(async () => {});
  8. const dismissNewTaskBanner = vi.fn();
  9. const setPendingCreateDraft = vi.fn();
  10. const refreshCodingPlanSupport = vi.fn(async () => {});
  11. const openCodingPlanUpgrade = vi.fn();
  12. const inventory = { status: "ready" as "ready" | "loading" | "error", retry: vi.fn() };
  13. const loggerDebug = vi.fn();
  14. const toast = vi.fn();
  15. const messages: { current: Record<string, string> } = { current: {} };
  16. const locale = { current: "en-US" };
  17. const offPeakTemplateIds = {
  18. current: ["standupGitSummary", "ciFlakyReport", "customize"] as string[],
  19. };
  20. const remoteTemplateCopy = {
  21. standupGitSummary: {
  22. en: {
  23. title: "Remote standup summary",
  24. description: "Remote Friday summary",
  25. prompt: "Summarize the remote standup.",
  26. },
  27. cn: { title: "远程站会摘要", description: "远程周五摘要", prompt: "汇总远程站会。" },
  28. },
  29. ciFlakyReport: {
  30. en: {
  31. title: "Remote CI report",
  32. description: "Remote CI failures",
  33. prompt: "Review the remote CI report.",
  34. },
  35. cn: { title: "远程 CI 报告", description: "远程 CI 失败", prompt: "检查远程 CI 报告。" },
  36. },
  37. documentationSyncCheck: {
  38. en: {
  39. title: "Remote docs check",
  40. description: "Remote documentation sync",
  41. prompt: "Review remote documentation.",
  42. },
  43. cn: { title: "远程文档检查", description: "远程文档同步", prompt: "检查远程文档。" },
  44. },
  45. };
  46. const providerSettingsState = {
  47. view: null as import("@zcode/services").ProviderSettingsView | null,
  48. };
  49. const state = {
  50. loading: false,
  51. grayConfig: {
  52. enabled: true,
  53. modelSelectionView: { revision: 1, providers: [] },
  54. },
  55. codingPlanSupport: {
  56. supported: false,
  57. reason: "connection_unselected",
  58. },
  59. newTaskBannerDismissed: false,
  60. initialize,
  61. refreshCodingPlanSupport,
  62. dismissNewTaskBanner,
  63. setPendingCreateDraft,
  64. };
  65. const settings = {
  66. providerFamilyDomain: undefined as "zai" | "bigmodel" | undefined,
  67. modelProviderFamilyModes: {} as Record<string, "oauth" | "apiKey">,
  68. modelProviderFamilySelectedKeys: {} as Record<string, string>,
  69. };
  70. // 真实 useServices 返回的是稳定的 Context 值;mock 若每次调用都新建对象,
  71. // 组件任何一次重渲染都会让 initialize 的依赖变化并重复拉取灰度配置。
  72. const services = {
  73. offPeakTaskService: {},
  74. codingPlanSubscriptionService: {},
  75. };
  76. return {
  77. initialize,
  78. loggerDebug,
  79. locale,
  80. messages,
  81. offPeakTemplateIds,
  82. providerSettingsState,
  83. openCodingPlanUpgrade,
  84. inventory,
  85. refreshCodingPlanSupport,
  86. services,
  87. setPendingCreateDraft,
  88. settings,
  89. state,
  90. toast,
  91. remoteTemplateCopy,
  92. };
  93. });
  94. vi.mock("@/components/ui/toast.js", () => ({ toast: h.toast }));
  95. vi.mock("@/hooks/useServices.js", () => ({
  96. useServices: () => h.services,
  97. }));
  98. vi.mock("@/hooks/useProviderSettingsView.js", () => ({
  99. useProviderSettingsView: () => ({
  100. state: h.providerSettingsState.view
  101. ? { status: "ready", view: h.providerSettingsState.view }
  102. : { status: "loading" },
  103. reload: vi.fn(),
  104. }),
  105. }));
  106. vi.mock("@/hooks/useSettingService.js", () => ({
  107. useSettings: () => ({ settings: h.settings }),
  108. }));
  109. vi.mock("@/i18n/IntlProvider.js", () => ({
  110. useZCodeIntl: () => ({
  111. locale: h.locale.current,
  112. intl: {
  113. formatMessage: ({ id }: { id: string }) => h.messages.current[id] ?? id,
  114. },
  115. }),
  116. }));
  117. vi.mock("@/settings/useAutomationTemplates.js", () => ({
  118. useAutomationTemplates: () => ({
  119. scheduled: [],
  120. rejectedScheduledTemplateIds: [],
  121. offPeak: h.offPeakTemplateIds.current.map((id) => {
  122. const customize = id === "customize" || id === "item-customize";
  123. const copy = customize
  124. ? null
  125. : h.remoteTemplateCopy[
  126. id as "standupGitSummary" | "ciFlakyReport" | "documentationSyncCheck"
  127. ];
  128. return {
  129. id,
  130. title: copy ? { en: copy.en.title, cn: copy.cn.title } : {},
  131. // Automations 仍展示 contents;首页必须显式读取 homepageDescription(descs 映射结果)。
  132. description: copy
  133. ? { en: `contents:${copy.en.description}`, cn: `contents:${copy.cn.description}` }
  134. : {},
  135. homepageDescription: copy ? { en: copy.en.description, cn: copy.cn.description } : {},
  136. prompt: copy ? { en: copy.en.prompt, cn: copy.cn.prompt } : { en: "", cn: "" },
  137. customize,
  138. icon: customize ? "customize" : id,
  139. ...(customize
  140. ? {}
  141. : {
  142. iconName:
  143. id === "standupGitSummary"
  144. ? "git-commit-horizontal"
  145. : id === "ciFlakyReport"
  146. ? "activity"
  147. : "file-text",
  148. }),
  149. };
  150. }),
  151. }),
  152. }));
  153. vi.mock("@/logger.js", () => ({
  154. logger: { debug: h.loggerDebug },
  155. }));
  156. vi.mock("@/settings/CodingPlanUpgradeDialogProvider.js", () => ({
  157. useOptionalCodingPlanUpgradeDialog: () => ({
  158. openCodingPlanUpgrade: h.openCodingPlanUpgrade,
  159. inventory: h.inventory,
  160. }),
  161. }));
  162. vi.mock("@/store/offPeakTaskStore.js", async (importOriginal) => {
  163. const actual = await importOriginal<typeof import("@/store/offPeakTaskStore.js")>();
  164. return {
  165. ...actual,
  166. useOffPeakTaskStore: (selector: (state: typeof h.state) => unknown) => selector(h.state),
  167. };
  168. });
  169. import { OffPeakNewTaskEntry } from "@/v4/OffPeakNewTaskEntry.js";
  170. import enUS from "@/i18n/locales/en-US.js";
  171. import zhCN from "@/i18n/locales/zh-CN.js";
  172. function renderEntry(props: { onOpenAutomations?: () => void } = {}) {
  173. return render(createElement(OffPeakNewTaskEntry, props));
  174. }
  175. function getEntryRoot(container: HTMLElement) {
  176. return container.querySelector<HTMLElement>("[data-off-peak-new-task-entry]");
  177. }
  178. function clickStandupTemplate(onOpenAutomations = vi.fn()) {
  179. renderEntry({ onOpenAutomations });
  180. fireEvent.click(
  181. screen.getByRole("button", {
  182. name: /Remote standup summary Remote Friday summary/,
  183. }),
  184. );
  185. return onOpenAutomations;
  186. }
  187. beforeEach(() => {
  188. vi.clearAllMocks();
  189. h.inventory.status = "ready";
  190. h.state.loading = false;
  191. h.state.grayConfig = {
  192. enabled: true,
  193. modelSelectionView: { revision: 1, providers: [] },
  194. };
  195. h.state.codingPlanSupport = {
  196. supported: false,
  197. reason: "connection_unselected",
  198. };
  199. h.providerSettingsState.view = {
  200. revision: 1,
  201. addableProviders: [],
  202. providerOrder: [],
  203. providers: [],
  204. };
  205. h.messages.current = {};
  206. h.locale.current = "en-US";
  207. h.offPeakTemplateIds.current = ["standupGitSummary", "ciFlakyReport", "customize"];
  208. h.settings.providerFamilyDomain = undefined;
  209. h.settings.modelProviderFamilyModes = {};
  210. h.settings.modelProviderFamilySelectedKeys = {};
  211. });
  212. afterEach(() => {
  213. cleanup();
  214. vi.restoreAllMocks();
  215. });
  216. describe("OffPeakNewTaskEntry", () => {
  217. it.each(["loading", "error"] as const)(
  218. "purchase inventory %s does not enter purchase from the blocked template",
  219. (status) => {
  220. h.inventory.status = status;
  221. const onOpenAutomations = clickStandupTemplate();
  222. const options = h.toast.mock.calls[0]?.[1];
  223. expect(h.setPendingCreateDraft).not.toHaveBeenCalled();
  224. expect(onOpenAutomations).not.toHaveBeenCalled();
  225. if (status === "loading") {
  226. expect(options?.actionLabel).toBeUndefined();
  227. } else {
  228. expect(options?.actionLabel).toBe("purchase.entry.retry");
  229. options?.onAction?.();
  230. expect(h.inventory.retry).toHaveBeenCalledOnce();
  231. }
  232. expect(h.openCodingPlanUpgrade).not.toHaveBeenCalled();
  233. },
  234. );
  235. it("远程目录为空时显示本地 Customize 入口", () => {
  236. h.offPeakTemplateIds.current = [];
  237. renderEntry();
  238. expect(screen.getByRole("button", { name: /Customize/i })).not.toBeNull();
  239. });
  240. it("首页只展示前两条普通远程模板,并把本地 Customize 固定放在最后", () => {
  241. h.offPeakTemplateIds.current = [
  242. "standupGitSummary",
  243. "item-customize",
  244. "ciFlakyReport",
  245. "documentationSyncCheck",
  246. ];
  247. const view = renderEntry();
  248. const cards = view.container.querySelectorAll<HTMLElement>(
  249. "[data-off-peak-template-grid] > button",
  250. );
  251. expect(cards).toHaveLength(3);
  252. expect(Array.from(cards, (card) => card.textContent)).toEqual([
  253. "Remote standup summaryRemote Friday summary",
  254. "Remote CI reportRemote CI failures",
  255. "offPeak.newTask.template.customize.titleoffPeak.newTask.template.customize.description",
  256. ]);
  257. expect(view.container.textContent).not.toContain("Remote docs check");
  258. });
  259. it("anchors the entry to the bottom of the draft page with a 38px inset", () => {
  260. const view = renderEntry();
  261. const entry = getEntryRoot(view.container);
  262. expect(entry?.classList.contains("pb-[38px]")).toBe(true);
  263. // 入口已从 composer 下方的 bottom dock 移出,不再靠 mt-6 与 composer 拉开间距,
  264. // 也不再依赖 @container/conversation 断点外扩(该容器只声明在 timeline 内部)。
  265. expect(entry?.classList.contains("mt-6")).toBe(false);
  266. expect(entry?.className).not.toContain("@min-[820px]/conversation:-mx-[54px]");
  267. });
  268. it("keeps the banner row and the template buttons 12px apart", () => {
  269. const view = renderEntry();
  270. const entry = getEntryRoot(view.container);
  271. expect(entry?.classList.contains("gap-3")).toBe(true);
  272. expect(entry?.classList.contains("gap-2")).toBe(false);
  273. });
  274. it("centers the banner and restores the 780px three-button row", () => {
  275. const view = renderEntry();
  276. const banner = view.container.querySelector<HTMLElement>("[data-off-peak-new-task-banner]");
  277. const templateGrid = view.container.querySelector<HTMLElement>("[data-off-peak-template-grid]");
  278. expect(banner?.classList.contains("justify-center")).toBe(true);
  279. expect(banner?.classList.contains("max-w-[580px]")).toBe(true);
  280. expect(templateGrid?.classList.contains("w-full")).toBe(true);
  281. expect(templateGrid?.classList.contains("max-w-[780px]")).toBe(true);
  282. });
  283. it("renders three equal template buttons horizontally with a narrow-screen fallback", async () => {
  284. const view = renderEntry();
  285. const templateGrid = view.container.querySelector<HTMLElement>("[data-off-peak-template-grid]");
  286. const cards = templateGrid?.querySelectorAll<HTMLElement>("button") ?? [];
  287. expect(templateGrid?.classList.contains("grid-cols-1")).toBe(true);
  288. expect(templateGrid?.classList.contains("sm:grid-cols-3")).toBe(true);
  289. expect(templateGrid?.classList.contains("gap-4")).toBe(true);
  290. expect(cards).toHaveLength(3);
  291. expect(view.container.querySelector('[data-slot="carousel"]')).toBeNull();
  292. expect(view.container.querySelector("[data-off-peak-carousel-dot]")).toBeNull();
  293. for (const card of cards) {
  294. expect(card.classList.contains("rounded-2xl")).toBe(true);
  295. expect(card.classList.contains("border-card-border")).toBe(true);
  296. }
  297. await waitFor(() => {
  298. expect(
  299. cards[0]?.querySelector('[data-client-scene-lucide-icon="git-commit-horizontal"]'),
  300. ).not.toBeNull();
  301. expect(cards[1]?.querySelector('[data-client-scene-lucide-icon="activity"]')).not.toBeNull();
  302. });
  303. expect(cards[2]?.querySelector('[data-off-peak-homepage-template-icon="moon"]')).not.toBeNull();
  304. });
  305. it("keeps the dismiss control implemented but hidden in this design round", () => {
  306. const view = renderEntry();
  307. const closeButton = view.container.querySelector<HTMLElement>(
  308. "[data-off-peak-new-task-dismiss]",
  309. );
  310. expect(closeButton).not.toBeNull();
  311. expect(closeButton?.classList.contains("hidden")).toBe(true);
  312. });
  313. it("limits localized template descriptions to two lines without a fixed height", () => {
  314. renderEntry();
  315. const description = screen.getByText("Remote Friday summary");
  316. const title = screen.getByText("Remote standup summary");
  317. expect(description.classList.contains("h-[54px]")).toBe(false);
  318. expect(description.classList.contains("line-clamp-2")).toBe(true);
  319. expect(description.classList.contains("line-clamp-3")).toBe(false);
  320. expect(description.classList.contains("text-wrap-phrase")).toBe(true);
  321. expect(description.classList.contains("text-ui-caption")).toBe(true);
  322. expect(description.classList.contains("text-ui-base")).toBe(false);
  323. expect(description.classList.contains("font-normal")).toBe(true);
  324. expect(title.classList.contains("text-ui-base")).toBe(true);
  325. expect(title.classList.contains("font-normal")).toBe(false);
  326. });
  327. it("uses matching Lucide glyphs for the announcement, close, and template actions", () => {
  328. const view = renderEntry();
  329. const closeButton = view.container.querySelector<HTMLElement>(
  330. "[data-off-peak-new-task-dismiss]",
  331. );
  332. const icons = view.container.querySelectorAll<SVGSVGElement>("svg");
  333. expect(icons.length).toBeGreaterThanOrEqual(5);
  334. for (const icon of icons) {
  335. expect(icon.getAttribute("viewBox")).toBe("0 0 24 24");
  336. expect(icon.getAttribute("stroke-width")).toBe("2");
  337. }
  338. expect(closeButton?.querySelector("svg")).not.toBeNull();
  339. });
  340. it("keeps the full banner copy visible and uses its entire area as the tooltip trigger", () => {
  341. renderEntry();
  342. const copy = screen.getByText("offPeak.newTask.bannerText");
  343. expect(copy.classList.contains("text-ui-caption")).toBe(true);
  344. expect(copy.classList.contains("text-ui-sm")).toBe(false);
  345. expect(copy.classList.contains("text-ui-base")).toBe(false);
  346. expect(copy.classList.contains("font-normal")).toBe(true);
  347. expect(copy.classList.contains("truncate")).toBe(false);
  348. expect(copy.getAttribute("data-slot")).toBe("tooltip-trigger");
  349. expect(copy.tabIndex).toBe(0);
  350. expect(copy.classList.contains("cursor-default")).toBe(true);
  351. expect(copy.classList.contains("cursor-help")).toBe(false);
  352. expect(copy.parentElement?.classList.contains("gap-1")).toBe(true);
  353. expect(copy.parentElement?.children).toHaveLength(2);
  354. expect(screen.queryByText("!")).toBeNull();
  355. });
  356. it("首次挂载交由共享机制初始化和登记 freshness,连接变化后刷新", () => {
  357. const view = renderEntry();
  358. expect(h.initialize).toHaveBeenCalledOnce();
  359. // 去重归 Store 所有;这里验证组件交付通知,不再要求它自行跳过首次通知。
  360. expect(h.refreshCodingPlanSupport).toHaveBeenCalledOnce();
  361. view.rerender(createElement(OffPeakNewTaskEntry));
  362. expect(h.refreshCodingPlanSupport).toHaveBeenCalledOnce();
  363. h.settings.providerFamilyDomain = "zai";
  364. h.settings.modelProviderFamilyModes = { zai: "oauth" };
  365. h.settings.modelProviderFamilySelectedKeys = { zai: "zai-coding-plan" };
  366. view.rerender(createElement(OffPeakNewTaskEntry));
  367. expect(h.refreshCodingPlanSupport).toHaveBeenCalledTimes(2);
  368. });
  369. it("非 Coding Plan 用户点击模板时直接弹升级 toast,并拦截草稿与导航", () => {
  370. vi.spyOn(globalThis.crypto, "randomUUID").mockReturnValue("idle-funnel-home");
  371. h.messages.current["settings.modelProvider.codingPlan.upgrade"] = "升级";
  372. const onOpenAutomations = clickStandupTemplate();
  373. expect(h.toast).toHaveBeenCalledWith("offPeak.create.codingPlanToast", {
  374. durationMs: 8000,
  375. position: "top-center",
  376. variant: "info",
  377. actionLabel: "升级",
  378. onAction: expect.any(Function),
  379. dismissible: true,
  380. dismissLabel: "common.close",
  381. });
  382. expect(h.setPendingCreateDraft).not.toHaveBeenCalled();
  383. expect(onOpenAutomations).not.toHaveBeenCalled();
  384. expect(h.loggerDebug).toHaveBeenCalledWith(
  385. "[off-peak] blocked home template without any Coding Plan",
  386. { templateId: "standupGitSummary" },
  387. );
  388. const toastOptions = h.toast.mock.calls[0]?.[1];
  389. toastOptions?.onAction?.();
  390. expect(h.openCodingPlanUpgrade).toHaveBeenCalledWith({
  391. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  392. initialAudience: "personal",
  393. funnelContext: {
  394. purchaseFunnelId: "idle-funnel-home",
  395. upgradeSource: "session_idle_time",
  396. eventRegion: "app.session",
  397. eventText: "升级",
  398. entryPlanStatus: "no_plan",
  399. entryPlanLevel: "",
  400. entryPlanList: "",
  401. purchaseAudience: "personal",
  402. providerFamily: "zai",
  403. channel: "Z_AI",
  404. },
  405. });
  406. });
  407. it("Account Overlay 确认 Coding Plan 可用时放行闲时任务导航", () => {
  408. h.providerSettingsState.view = {
  409. revision: 2,
  410. addableProviders: [],
  411. providerOrder: [],
  412. providers: [
  413. {
  414. providerId: BUILTIN_MODEL_PROVIDER_IDS.bigmodelIndividualCodingPlan,
  415. enabled: true,
  416. executable: true,
  417. effectiveConfig: {
  418. label: "BigModel Coding Plan",
  419. access: {
  420. type: "zhipu-account",
  421. family: "bigmodel",
  422. mode: "individual-coding-plan",
  423. entitled: true,
  424. },
  425. api: {
  426. type: "anthropic-messages",
  427. baseUrl: "https://example.com",
  428. },
  429. builtinModelIds: ["glm-5"],
  430. enabled: true,
  431. },
  432. issues: [],
  433. models: [],
  434. },
  435. ],
  436. };
  437. const onOpenAutomations = clickStandupTemplate();
  438. expect(h.toast).not.toHaveBeenCalled();
  439. expect(h.setPendingCreateDraft).toHaveBeenCalledOnce();
  440. expect(onOpenAutomations).toHaveBeenCalledOnce();
  441. });
  442. it("Provider Settings 尚未水合时不把未知状态误判为无套餐", () => {
  443. h.providerSettingsState.view = null;
  444. const onOpenAutomations = clickStandupTemplate();
  445. expect(h.toast).not.toHaveBeenCalled();
  446. expect(h.setPendingCreateDraft).toHaveBeenCalledOnce();
  447. expect(onOpenAutomations).toHaveBeenCalledOnce();
  448. });
  449. it("uses the visible English Upgrade copy as the idle-time event text", () => {
  450. vi.spyOn(globalThis.crypto, "randomUUID").mockReturnValue("idle-funnel-en");
  451. h.messages.current["settings.modelProvider.codingPlan.upgrade"] = "Upgrade";
  452. clickStandupTemplate();
  453. const toastOptions = h.toast.mock.calls[0]?.[1];
  454. toastOptions?.onAction?.();
  455. expect(h.openCodingPlanUpgrade.mock.calls[0]?.[0]?.funnelContext?.eventText).toBe("Upgrade");
  456. });
  457. it.each([
  458. {
  459. locale: "zh-CN",
  460. messages: zhCN,
  461. bannerText: "订阅用户新功能体验:创建“闲时任务”,我们将免费在算力富余时段为你完成指派任务。",
  462. bannerTipText: "本功能不消耗订阅用户套餐额度、本功能仅面向订阅用户开放",
  463. fullCopy:
  464. "订阅用户新功能体验:创建“闲时任务”,我们将免费在算力富余时段为你完成指派任务。本功能不消耗订阅用户套餐额度、本功能仅面向订阅用户开放",
  465. copySeparator: "",
  466. },
  467. {
  468. locale: "en-US",
  469. messages: enUS,
  470. bannerText:
  471. 'New feature for subscribers: Create "Idle-time task" , We will complete your assigned task for free during periods of surplus computing power.',
  472. bannerTipText:
  473. "This feature does not consume your subscription plan quota and is available exclusively to subscribers.",
  474. fullCopy:
  475. 'New feature for subscribers: Create "Idle-time task" , We will complete your assigned task for free during periods of surplus computing power. This feature does not consume your subscription plan quota and is available exclusively to subscribers.',
  476. copySeparator: " ",
  477. },
  478. ])(
  479. "$locale 首页展示、提示与模板预填使用同一种语言",
  480. ({ locale, messages, bannerText, bannerTipText, fullCopy, copySeparator }) => {
  481. h.messages.current = messages;
  482. h.locale.current = locale;
  483. h.providerSettingsState.view = {
  484. revision: 2,
  485. addableProviders: [],
  486. providerOrder: [],
  487. providers: [
  488. {
  489. providerId: BUILTIN_MODEL_PROVIDER_IDS.zaiIndividualCodingPlan,
  490. enabled: true,
  491. executable: true,
  492. effectiveConfig: {
  493. label: "Z.ai Coding Plan",
  494. access: {
  495. type: "zhipu-account",
  496. family: "zai",
  497. mode: "individual-coding-plan",
  498. entitled: true,
  499. },
  500. api: {
  501. type: "anthropic-messages",
  502. baseUrl: "https://example.com",
  503. },
  504. builtinModelIds: ["glm-5"],
  505. },
  506. issues: [],
  507. models: [],
  508. },
  509. ],
  510. };
  511. const copy = h.remoteTemplateCopy.standupGitSummary[locale === "zh-CN" ? "cn" : "en"];
  512. const { title, description, prompt } = copy;
  513. const onOpenAutomations = vi.fn();
  514. render(createElement(OffPeakNewTaskEntry, { onOpenAutomations }));
  515. const bannerCopy = screen.getByText(bannerText);
  516. fireEvent.focus(bannerCopy);
  517. const tipCopies = screen.getAllByText(bannerTipText);
  518. expect([bannerText, bannerTipText].join(copySeparator)).toBe(fullCopy);
  519. expect(tipCopies.length).toBeGreaterThan(0);
  520. expect(
  521. tipCopies.some(
  522. (copy) =>
  523. copy.parentElement?.classList.contains("max-w-none") &&
  524. copy.parentElement?.classList.contains("whitespace-nowrap"),
  525. ),
  526. ).toBe(true);
  527. const templateCard = screen.getByRole("button", {
  528. name: `${title} ${description}`,
  529. });
  530. fireEvent.click(templateCard);
  531. expect(h.toast).not.toHaveBeenCalled();
  532. expect(h.setPendingCreateDraft).toHaveBeenCalledWith({
  533. title,
  534. prompt,
  535. telemetrySource: {
  536. eventRegion: "app.session",
  537. templateId: "standupGitSummary",
  538. },
  539. });
  540. expect(onOpenAutomations).toHaveBeenCalledOnce();
  541. },
  542. );
  543. });