webRemoteControlTaskSync.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { describe, expect, it, vi } from "vitest";
  2. import {
  3. logDeferredWebRemoteControlTaskSnapshot,
  4. shouldSyncWebRemoteControlTaskSnapshot,
  5. } from "@/lib/webRemoteControlTaskSync.js";
  6. describe("shouldSyncWebRemoteControlTaskSnapshot", () => {
  7. it("defers empty task snapshots while the remote-control task queries are loading", () => {
  8. expect(
  9. shouldSyncWebRemoteControlTaskSnapshot({
  10. enabled: true,
  11. archivedLoading: false,
  12. pinnedLoading: false,
  13. timelineLoading: true,
  14. }),
  15. ).toBe(false);
  16. });
  17. it("allows a loaded empty snapshot so main can clear stale tasks", () => {
  18. expect(
  19. shouldSyncWebRemoteControlTaskSnapshot({
  20. enabled: true,
  21. archivedLoading: false,
  22. pinnedLoading: false,
  23. timelineLoading: false,
  24. }),
  25. ).toBe(true);
  26. });
  27. it("defers non-empty task snapshots while any remote-control task query is still loading", () => {
  28. expect(
  29. shouldSyncWebRemoteControlTaskSnapshot({
  30. enabled: true,
  31. archivedLoading: false,
  32. pinnedLoading: true,
  33. timelineLoading: true,
  34. }),
  35. ).toBe(false);
  36. });
  37. it("defers snapshots while archived remote-control task query is still loading", () => {
  38. expect(
  39. shouldSyncWebRemoteControlTaskSnapshot({
  40. enabled: true,
  41. archivedLoading: true,
  42. pinnedLoading: false,
  43. timelineLoading: false,
  44. }),
  45. ).toBe(false);
  46. });
  47. it("logs deferred partial snapshots as debug without calling them empty snapshots", () => {
  48. const logger = {
  49. debug: vi.fn(),
  50. info: vi.fn(),
  51. };
  52. logDeferredWebRemoteControlTaskSnapshot(logger, {
  53. archivedLoading: false,
  54. pinnedLoading: true,
  55. timelineLoading: false,
  56. });
  57. expect(logger.info).not.toHaveBeenCalled();
  58. expect(logger.debug).toHaveBeenCalledWith(
  59. expect.not.stringContaining("空任务快照"),
  60. {
  61. archivedLoading: false,
  62. pinnedLoading: true,
  63. timelineLoading: false,
  64. },
  65. );
  66. });
  67. });