providerModelModalityOptions.test.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // @vitest-environment jsdom
  2. import { createElement, useState } from "react";
  3. import { cleanup, fireEvent, render, screen } from "@testing-library/react";
  4. import { afterEach, describe, expect, it, vi } from "vitest";
  5. import { ProviderModelInputModalityOptions } from "@/settings/model-provider-section/ProviderModelModalityOptions.js";
  6. vi.mock("@/i18n/IntlProvider.js", () => ({
  7. useZCodeIntl: () => ({
  8. intl: {
  9. formatMessage: ({ id }: { id: string }) => id.split(".").at(-1)?.toUpperCase() ?? id,
  10. },
  11. }),
  12. }));
  13. afterEach(cleanup);
  14. describe("ProviderModelInputModalityOptions", () => {
  15. it("展示并切换 PDF,同时不暴露尚未开放的 Audio", () => {
  16. function Harness() {
  17. const [value, setValue] = useState({
  18. supportsText: true,
  19. supportsImage: false,
  20. supportsVideo: false,
  21. supportsAudio: true,
  22. supportsPdf: false,
  23. });
  24. return createElement(ProviderModelInputModalityOptions, { value, onChange: setValue });
  25. }
  26. const { container } = render(createElement(Harness));
  27. expect(container.querySelector('[data-model-input-modality="audio"]')).toBeNull();
  28. const pdf = screen.getByRole("button", { name: "PDF" });
  29. expect(pdf.getAttribute("aria-pressed")).toBe("false");
  30. fireEvent.click(pdf);
  31. expect(pdf.getAttribute("aria-pressed")).toBe("true");
  32. expect((screen.getByRole("button", { name: "TEXT" }) as HTMLButtonElement).disabled).toBe(true);
  33. });
  34. });