provider-settings-presentation-cases.mjs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import assert from "node:assert/strict";
  2. import { mkdir } from "node:fs/promises";
  3. import { join } from "node:path";
  4. import { test } from "node:test";
  5. import { registerProviderAppIconCases } from "./provider-app-icon-cases.mjs";
  6. export function registerProviderPresentationCases(getEnvironment) {
  7. registerProviderAppIconCases(getEnvironment);
  8. for (const [width, locale, theme] of [
  9. [390, "zh-CN", "light"],
  10. [1200, "en-US", "dark"],
  11. ]) {
  12. test(`mimo templates ${width}/${locale}`, async () => {
  13. const { browser, origin, artifacts } = getEnvironment();
  14. const page = await browser.newPage({ viewport: { width, height: 1000 } });
  15. const mutations = [],
  16. errors = [];
  17. page.on("pageerror", (error) => errors.push(String(error)));
  18. await page.route("**/mutation", async (route) => {
  19. mutations.push(route.request().postDataJSON());
  20. await route.fulfill({ status: 200, body: "{}" });
  21. });
  22. try {
  23. for (const [id, label, url] of [
  24. ["xiaomi-mimo", "Xiaomi MiMo API", "https://api.xiaomimimo.com/anthropic"],
  25. [
  26. "xiaomi-mimo-token-plan",
  27. "Xiaomi MiMo Token Plan",
  28. "https://token-plan-cn.xiaomimimo.com/anthropic",
  29. ],
  30. ]) {
  31. await page.goto(`${origin}fixture?${new URLSearchParams({ locale, theme })}`);
  32. const card = page.getByTestId(`model-provider-template-item-${id}`);
  33. await card.waitFor();
  34. assert.equal((await card.innerText()).trim(), label);
  35. await card.locator("img").evaluate((image) => image.decode());
  36. assert.match(await card.locator("img").getAttribute("src"), /mimo/i);
  37. await card.hover();
  38. await page
  39. .getByRole("tooltip")
  40. .filter({ hasText: new RegExp(`^${label}$`) })
  41. .waitFor();
  42. await page.keyboard.press("Escape");
  43. await mkdir(artifacts, { recursive: true });
  44. await page.screenshot({ path: join(artifacts, `mimo-templates-${width}.png`) });
  45. const count = mutations.length;
  46. await card.click();
  47. await page.locator(`input[value="${url}"]`).waitFor();
  48. assert.equal(mutations.length, count + 1);
  49. assert.deepEqual(mutations.at(-1), { action: "create", payload: id });
  50. assert.equal(
  51. await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth),
  52. true,
  53. );
  54. await mkdir(artifacts, { recursive: true });
  55. await page.screenshot({ path: join(artifacts, `mimo-${id}-${width}.png`) });
  56. }
  57. assert.deepEqual(mutations, [
  58. { action: "create", payload: "xiaomi-mimo" },
  59. { action: "create", payload: "xiaomi-mimo-token-plan" },
  60. ]);
  61. assert.deepEqual(errors, []);
  62. } finally {
  63. await page.close();
  64. }
  65. });
  66. test(`openrouter template label ${width}/${locale}`, async () => {
  67. const { browser, origin, artifacts } = getEnvironment();
  68. const page = await browser.newPage({ viewport: { width, height: 1000 } });
  69. try {
  70. await page.goto(`${origin}fixture?${new URLSearchParams({ locale, theme })}`);
  71. const card = page.getByTestId("model-provider-template-item-openrouter");
  72. await card.waitFor();
  73. assert.equal((await card.innerText()).trim(), "OpenRouter");
  74. await card.hover();
  75. await page
  76. .getByRole("tooltip")
  77. .filter({ hasText: /^OpenRouter$/ })
  78. .waitFor();
  79. await mkdir(artifacts, { recursive: true });
  80. await page.screenshot({ path: join(artifacts, `openrouter-label-${width}.png`) });
  81. } finally {
  82. await page.close();
  83. }
  84. });
  85. test(`subagent selection error copy ${width}/${locale}`, async () => {
  86. const { browser, origin, artifacts } = getEnvironment();
  87. const context = await browser.newContext({
  88. viewport: { width, height: 1000 },
  89. permissions: ["clipboard-read", "clipboard-write"],
  90. });
  91. const page = await context.newPage();
  92. try {
  93. await page.goto(
  94. `${origin}fixture?${new URLSearchParams({ locale, theme, access: "account", selectionError: "1" })}`,
  95. );
  96. await page
  97. .getByTestId("subagent-error")
  98. .getByText(locale === "zh-CN" ? "执行失败" : "Failed", { exact: true })
  99. .hover();
  100. const detail = page
  101. .locator('[data-slot="tooltip-content"]')
  102. .filter({ hasText: "reasoning-level-missing" });
  103. await detail.waitFor();
  104. assert.match(await detail.innerText(), /未选择思考档位/);
  105. // Radix 还生成一份 aria 隐藏描述,点击实际展示的复制按钮。
  106. await detail.locator('button:not([role="tooltip"] button)').click();
  107. const copied = await page.evaluate(() => navigator.clipboard.readText());
  108. assert.match(copied, /reason=reasoning-level-missing/);
  109. assert.match(copied, /selection=account:bigmodel-team-coding-plan\/GLM-5\.3/);
  110. assert.match(copied, /No reasoning level selected/);
  111. await mkdir(artifacts, { recursive: true });
  112. await page.screenshot({ path: join(artifacts, `subagent-error-${width}.png`) });
  113. } finally {
  114. await context.close();
  115. }
  116. });
  117. }
  118. for (const [width, locale, theme] of [
  119. [390, "zh-CN", "light"],
  120. [1200, "en-US", "dark"],
  121. ]) {
  122. test(`coding plan vision badge in settings and picker ${width}/${theme}`, async () => {
  123. const { browser, origin, artifacts } = getEnvironment();
  124. const page = await browser.newPage({ viewport: { width, height: 1100 } });
  125. try {
  126. for (const access of ["start-zai", "start-bigmodel", "account", "team", "manual"]) {
  127. await page.goto(
  128. `${origin}fixture?${new URLSearchParams({ locale, theme, access, vision: "1" })}`,
  129. );
  130. const label = locale === "zh-CN" ? "视觉" : "Vision";
  131. const detail = page.getByTestId("detail");
  132. await detail.getByText("GLM-5.3", { exact: true }).waitFor();
  133. const main = detail.getByText("GLM-5.3", { exact: true }).locator("..");
  134. const flash = detail.getByText("GLM-5.3-Flash", { exact: true }).locator("..");
  135. assert.equal(await main.getByText(label, { exact: true }).count(), 0);
  136. assert.equal(await flash.getByText(label, { exact: true }).count(), 1);
  137. await page.getByRole("button", { name: "Pick model", exact: true }).click();
  138. const menu = page.getByRole("menu");
  139. await menu.waitFor();
  140. const mainItem = menu.getByRole("menuitemradio").filter({ hasText: /^GLM-5\.3$/ });
  141. const flashItem = menu.getByRole("menuitemradio").filter({ hasText: /GLM-5\.3-Flash/ });
  142. assert.equal(await mainItem.count(), 1);
  143. assert.equal(await mainItem.getByText(label, { exact: true }).count(), 0);
  144. assert.equal(await flashItem.getByText(label, { exact: true }).count(), 1);
  145. await mkdir(artifacts, { recursive: true });
  146. await page.screenshot({ path: join(artifacts, `vision-${access}-${width}.png`) });
  147. }
  148. } finally {
  149. await page.close();
  150. }
  151. });
  152. }
  153. }