provider-settings-presentation-cases.mjs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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(`openrouter template label ${width}/${locale}`, async () => {
  13. const { browser, origin, artifacts } = getEnvironment();
  14. const page = await browser.newPage({ viewport: { width, height: 1000 } });
  15. try {
  16. await page.goto(`${origin}fixture?${new URLSearchParams({ locale, theme })}`);
  17. const card = page.getByTestId("model-provider-template-item-openrouter");
  18. await card.waitFor();
  19. assert.equal((await card.innerText()).trim(), "OpenRouter");
  20. await card.hover();
  21. await page
  22. .getByRole("tooltip")
  23. .filter({ hasText: /^OpenRouter$/ })
  24. .waitFor();
  25. await mkdir(artifacts, { recursive: true });
  26. await page.screenshot({ path: join(artifacts, `openrouter-label-${width}.png`) });
  27. } finally {
  28. await page.close();
  29. }
  30. });
  31. test(`subagent selection error copy ${width}/${locale}`, async () => {
  32. const { browser, origin, artifacts } = getEnvironment();
  33. const context = await browser.newContext({
  34. viewport: { width, height: 1000 },
  35. permissions: ["clipboard-read", "clipboard-write"],
  36. });
  37. const page = await context.newPage();
  38. try {
  39. await page.goto(
  40. `${origin}fixture?${new URLSearchParams({ locale, theme, access: "account", selectionError: "1" })}`,
  41. );
  42. await page
  43. .getByTestId("subagent-error")
  44. .getByText(locale === "zh-CN" ? "执行失败" : "Failed", { exact: true })
  45. .hover();
  46. const detail = page
  47. .locator('[data-slot="tooltip-content"]')
  48. .filter({ hasText: "reasoning-level-missing" });
  49. await detail.waitFor();
  50. assert.match(await detail.innerText(), /未选择思考档位/);
  51. // Radix 还生成一份 aria 隐藏描述,点击实际展示的复制按钮。
  52. await detail.locator('button:not([role="tooltip"] button)').click();
  53. const copied = await page.evaluate(() => navigator.clipboard.readText());
  54. assert.match(copied, /reason=reasoning-level-missing/);
  55. assert.match(copied, /selection=account:bigmodel-team-coding-plan\/GLM-5\.3/);
  56. assert.match(copied, /No reasoning level selected/);
  57. await mkdir(artifacts, { recursive: true });
  58. await page.screenshot({ path: join(artifacts, `subagent-error-${width}.png`) });
  59. } finally {
  60. await context.close();
  61. }
  62. });
  63. }
  64. for (const [width, locale, theme] of [
  65. [390, "zh-CN", "light"],
  66. [1200, "en-US", "dark"],
  67. ]) {
  68. test(`coding plan vision badge in settings and picker ${width}/${theme}`, async () => {
  69. const { browser, origin, artifacts } = getEnvironment();
  70. const page = await browser.newPage({ viewport: { width, height: 1100 } });
  71. try {
  72. for (const access of ["start-zai", "start-bigmodel", "account", "team", "manual"]) {
  73. await page.goto(
  74. `${origin}fixture?${new URLSearchParams({ locale, theme, access, vision: "1" })}`,
  75. );
  76. const label = locale === "zh-CN" ? "视觉" : "Vision";
  77. const detail = page.getByTestId("detail");
  78. await detail.getByText("GLM-5.3", { exact: true }).waitFor();
  79. const main = detail.getByText("GLM-5.3", { exact: true }).locator("..");
  80. const flash = detail.getByText("GLM-5.3-Flash", { exact: true }).locator("..");
  81. assert.equal(await main.getByText(label, { exact: true }).count(), 0);
  82. assert.equal(await flash.getByText(label, { exact: true }).count(), 1);
  83. await page.getByRole("button", { name: "Pick model", exact: true }).click();
  84. const menu = page.getByRole("menu");
  85. await menu.waitFor();
  86. const mainItem = menu.getByRole("menuitemradio").filter({ hasText: /^GLM-5\.3$/ });
  87. const flashItem = menu.getByRole("menuitemradio").filter({ hasText: /GLM-5\.3-Flash/ });
  88. assert.equal(await mainItem.count(), 1);
  89. assert.equal(await mainItem.getByText(label, { exact: true }).count(), 0);
  90. assert.equal(await flashItem.getByText(label, { exact: true }).count(), 1);
  91. await mkdir(artifacts, { recursive: true });
  92. await page.screenshot({ path: join(artifacts, `vision-${access}-${width}.png`) });
  93. }
  94. } finally {
  95. await page.close();
  96. }
  97. });
  98. }
  99. }