webRemoteControlDeviceInfo.test.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { describe, expect, it } from "vitest";
  2. import { collectWebRemoteControlMobileDeviceInfo } from "../src/webRemoteControlDeviceInfo.js";
  3. describe("collectWebRemoteControlMobileDeviceInfo", () => {
  4. it("collects stable browser device info without requiring mobile-only APIs", () => {
  5. const deviceInfo = collectWebRemoteControlMobileDeviceInfo({
  6. appVersion: "1.7.0",
  7. now: () => 123,
  8. navigatorLike: {
  9. userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)",
  10. language: "zh-CN",
  11. languages: ["zh-CN", "en-US"],
  12. platform: "iPhone",
  13. onLine: true,
  14. },
  15. windowLike: {
  16. innerWidth: 390,
  17. innerHeight: 844,
  18. devicePixelRatio: 3,
  19. screen: {
  20. width: 390,
  21. height: 844,
  22. },
  23. },
  24. dateTimeFormat: () => ({
  25. resolvedOptions: () => ({ timeZone: "Asia/Shanghai" }),
  26. }),
  27. });
  28. expect(deviceInfo).toEqual({
  29. platform: "web",
  30. version: "1.7.0",
  31. name: "mobile-browser",
  32. userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)",
  33. language: "zh-CN",
  34. languages: ["zh-CN", "en-US"],
  35. browserPlatform: "iPhone",
  36. viewport: {
  37. width: 390,
  38. height: 844,
  39. devicePixelRatio: 3,
  40. },
  41. screen: {
  42. width: 390,
  43. height: 844,
  44. },
  45. timezone: "Asia/Shanghai",
  46. online: true,
  47. updatedAt: 123,
  48. });
  49. });
  50. });