useTelemetry.test.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { afterEach, describe, expect, it, vi } from "vitest";
  2. const originalDateTimeFormat = Intl.DateTimeFormat;
  3. afterEach(() => {
  4. Intl.DateTimeFormat = originalDateTimeFormat;
  5. });
  6. describe("useTelemetry helpers", () => {
  7. it("uses provided Intl-like options when collecting renderer telemetry context", async () => {
  8. const { collectTelemetryRendererContext } = await import("@zcode/shared");
  9. const context = collectTelemetryRendererContext({
  10. intlLocale: "en-US",
  11. timeZone: "Asia/Shanghai",
  12. screen: {
  13. width: 3024,
  14. height: 1964,
  15. },
  16. });
  17. expect(context).toEqual({
  18. clientTimezone: "Asia/Shanghai",
  19. clientLanguage: "en-US",
  20. screenResolution: "3024x1964",
  21. });
  22. });
  23. it("falls back to Intl resolved locale and time zone", async () => {
  24. Intl.DateTimeFormat = vi.fn(() => ({
  25. resolvedOptions: () => ({
  26. locale: "en-US",
  27. timeZone: "Asia/Shanghai",
  28. }),
  29. })) as typeof Intl.DateTimeFormat;
  30. const { collectTelemetryRendererContext } = await import("@zcode/shared");
  31. const context = collectTelemetryRendererContext({
  32. screen: {
  33. width: 3024,
  34. height: 1964,
  35. },
  36. });
  37. expect(context).toEqual({
  38. clientTimezone: "Asia/Shanghai",
  39. clientLanguage: "en-US",
  40. screenResolution: "3024x1964",
  41. });
  42. });
  43. });