offpeak-team-entry.fixture.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { useState } from "react";
  2. import type { IServiceAccessor, ProviderSettingsView } from "@zcode/services";
  3. import type { IPlatformService } from "@zcode/shared";
  4. import { ServiceProvider } from "@/hooks/useServices.js";
  5. import { PlatformProvider } from "@/hooks/usePlatform.js";
  6. import { connectProviderSettingsSnapshot } from "@/lib/providerSettingsSnapshot.js";
  7. import { OffPeakNewTaskEntry } from "@/v4/OffPeakNewTaskEntry.js";
  8. import { useOffPeakTaskStore } from "@/store/offPeakTaskStore.js";
  9. const query = new URLSearchParams(location.search);
  10. const family = query.get("family") ?? "bigmodel";
  11. const providerId = `account:${family}-team-coding-plan`;
  12. const view = {
  13. revision: 1,
  14. providerTemplates: [],
  15. providers: [
  16. {
  17. providerId,
  18. enabled: true,
  19. executable: true,
  20. models: [],
  21. issues: [],
  22. effectiveConfig: {
  23. access: {
  24. type: "zhipu-account",
  25. accountType: family,
  26. mode: "team-coding-plan",
  27. entitled: !query.has("noPlan"),
  28. },
  29. },
  30. },
  31. ],
  32. } as unknown as ProviderSettingsView;
  33. const services = {
  34. providerSettingsService: {
  35. async getView() {
  36. return view;
  37. },
  38. onDidChange() {
  39. return { dispose() {} };
  40. },
  41. },
  42. settingService: {
  43. async get() {
  44. return { providerFamilyDomain: family };
  45. },
  46. },
  47. clientScenesService: {
  48. async list() {
  49. return { code: 0, data: [] };
  50. },
  51. },
  52. codingPlanSubscriptionService: {
  53. async getOffPeakClientConfig() {
  54. return {
  55. enabled: !query.has("grayOff"),
  56. ...(query.has("inactive") ? { codingPlanActive: false } : {}),
  57. };
  58. },
  59. },
  60. offPeakTaskService: {
  61. async list() {
  62. return [];
  63. },
  64. async getCodingPlanSupport() {
  65. return { supported: true, providerId };
  66. },
  67. async getTakeNumberAvailability() {
  68. return { canTakeNumber: true };
  69. },
  70. },
  71. } as unknown as IServiceAccessor;
  72. // 不让未渲染的 Team 场景抢走另一个 fixture 的 Registry 订阅。
  73. if (new URLSearchParams(location.search).has("teamEntry")) {
  74. void connectProviderSettingsSnapshot(services.providerSettingsService).ready;
  75. }
  76. // 只替换外部服务;实际首页组件、模板草稿、套餐分类和灰度门控一起验收。
  77. export function OffPeakTeamEntryFixture() {
  78. const [opened, setOpened] = useState(0);
  79. const state = useOffPeakTaskStore();
  80. return (
  81. <ServiceProvider services={services}>
  82. <PlatformProvider platform={{} as IPlatformService}>
  83. <button data-testid="dismiss-entry" onClick={() => state.dismissNewTaskBanner()}>
  84. 关闭入口
  85. </button>
  86. <OffPeakNewTaskEntry onOpenAutomations={() => setOpened((n) => n + 1)} />
  87. <output data-testid="team-opened">{opened}</output>
  88. <output data-testid="team-loaded">
  89. {String(state.grayConfig !== null && !state.loading)}
  90. </output>
  91. <output data-testid="team-draft">{JSON.stringify(state.pendingCreateDraft)}</output>
  92. </PlatformProvider>
  93. </ServiceProvider>
  94. );
  95. }