|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 2 |
|
| 3 | +/** The key the module under test writes; kept here so a rename fails loudly in one place. */ |
| 4 | +const STORAGE_KEY = "tdev:dashboard-agent:watching"; |
| 5 | + |
3 | 6 | type StorageListener = (event: { key: string | null }) => void; |
4 | 7 |
|
5 | 8 | const store = new Map<string, string>(); |
@@ -27,8 +30,8 @@ const { |
27 | 30 |
|
28 | 31 | /** What another tab writing the key looks like here. */ |
29 | 32 | function otherTabWrote(organizationId: string) { |
30 | | - store.set("tdev:dashboard-agent:watching", JSON.stringify([organizationId])); |
31 | | - for (const listener of storageListeners) listener({ key: "tdev:dashboard-agent:watching" }); |
| 33 | + store.set(STORAGE_KEY, JSON.stringify([organizationId])); |
| 34 | + for (const listener of storageListeners) listener({ key: STORAGE_KEY }); |
32 | 35 | } |
33 | 36 |
|
34 | 37 | describe("watch activity", () => { |
@@ -98,20 +101,20 @@ describe("watch activity", () => { |
98 | 101 |
|
99 | 102 | describe("a corrupt key", () => { |
100 | 103 | it("reads as nothing known when the value is not an array", () => { |
101 | | - store.set("tdev:dashboard-agent:watching", JSON.stringify({ org_1: true })); |
| 104 | + store.set(STORAGE_KEY, JSON.stringify({ org_1: true })); |
102 | 105 |
|
103 | 106 | expect(hasWatchActivity("org_1")).toBe(false); |
104 | 107 | expect(shouldPollWakeFeed({ serverUnreadWakes: 0, organizationId: "org_1" })).toBe(false); |
105 | 108 | }); |
106 | 109 |
|
107 | 110 | it("keeps the ids out of an array holding other things", () => { |
108 | | - store.set("tdev:dashboard-agent:watching", JSON.stringify([{ id: "org_1" }, "org_2", 7])); |
| 111 | + store.set(STORAGE_KEY, JSON.stringify([{ id: "org_1" }, "org_2", 7])); |
109 | 112 |
|
110 | 113 | expect(hasWatchActivity("org_1")).toBe(false); |
111 | 114 | expect(hasWatchActivity("org_2")).toBe(true); |
112 | 115 |
|
113 | 116 | rememberWatchActivity("org_3"); |
114 | | - expect(store.get("tdev:dashboard-agent:watching")).toBe(JSON.stringify(["org_2", "org_3"])); |
| 117 | + expect(store.get(STORAGE_KEY)).toBe(JSON.stringify(["org_2", "org_3"])); |
115 | 118 | }); |
116 | 119 | }); |
117 | 120 |
|
|
0 commit comments