History

Prepare datamodel for multi-environment (#1765)

Julius Marminge committed 7 months ago

Commit b96308f1 parent 72b7f90121 files · +10206 −4969Browse files

Showing the changes to apps/web/src/threadSelectionStore.test.ts (1 of 121 files). Show all

Unified · Split

apps/web/src/threadSelectionStore.test.ts+53−53
@@ -21,9 +21,9 @@ describe("threadSelectionStore", () => { · 20 unmodified lines
21 useThreadSelectionStore.getState().toggleThread(THREAD_A);21 useThreadSelectionStore.getState().toggleThread(THREAD_A);
22 22
23 const state = useThreadSelectionStore.getState();23 const state = useThreadSelectionStore.getState();
24 expect(state.selectedThreadIds.has(THREAD_A)).toBe(true);24 expect(state.selectedThreadKeys.has(THREAD_A)).toBe(true);
25 expect(state.selectedThreadIds.size).toBe(1);25 expect(state.selectedThreadKeys.size).toBe(1);
26 expect(state.anchorThreadId).toBe(THREAD_A);26 expect(state.anchorThreadKey).toBe(THREAD_A);
27 });27 });
28 28
29 it("removes a thread that is already selected", () => {29 it("removes a thread that is already selected", () => {
@@ -32,8 +32,8 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
32 store.toggleThread(THREAD_A);32 store.toggleThread(THREAD_A);
33 33
34 const state = useThreadSelectionStore.getState();34 const state = useThreadSelectionStore.getState();
35 expect(state.selectedThreadIds.has(THREAD_A)).toBe(false);35 expect(state.selectedThreadKeys.has(THREAD_A)).toBe(false);
36 expect(state.selectedThreadIds.size).toBe(0);36 expect(state.selectedThreadKeys.size).toBe(0);
37 });37 });
38 38
39 it("preserves existing selections when toggling a new thread", () => {39 it("preserves existing selections when toggling a new thread", () => {
@@ -42,9 +42,9 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
42 store.toggleThread(THREAD_B);42 store.toggleThread(THREAD_B);
43 43
44 const state = useThreadSelectionStore.getState();44 const state = useThreadSelectionStore.getState();
45 expect(state.selectedThreadIds.has(THREAD_A)).toBe(true);45 expect(state.selectedThreadKeys.has(THREAD_A)).toBe(true);
46 expect(state.selectedThreadIds.has(THREAD_B)).toBe(true);46 expect(state.selectedThreadKeys.has(THREAD_B)).toBe(true);
47 expect(state.selectedThreadIds.size).toBe(2);47 expect(state.selectedThreadKeys.size).toBe(2);
48 });48 });
49 49
50 it("sets anchor to the newly added thread", () => {50 it("sets anchor to the newly added thread", () => {
@@ -52,7 +52,7 @@ describe("threadSelectionStore", () => { · 1 unmodified line
52 store.toggleThread(THREAD_A);52 store.toggleThread(THREAD_A);
53 store.toggleThread(THREAD_B);53 store.toggleThread(THREAD_B);
54 54
55 expect(useThreadSelectionStore.getState().anchorThreadId).toBe(THREAD_B);55 expect(useThreadSelectionStore.getState().anchorThreadKey).toBe(THREAD_B);
56 });56 });
57 57
58 it("preserves anchor when deselecting a non-anchor thread", () => {58 it("preserves anchor when deselecting a non-anchor thread", () => {
@@ -61,7 +61,7 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
61 store.toggleThread(THREAD_B);61 store.toggleThread(THREAD_B);
62 store.toggleThread(THREAD_A); // deselect A, anchor should stay B62 store.toggleThread(THREAD_A); // deselect A, anchor should stay B
63 63
64 expect(useThreadSelectionStore.getState().anchorThreadId).toBe(THREAD_B);64 expect(useThreadSelectionStore.getState().anchorThreadKey).toBe(THREAD_B);
65 });65 });
66 });66 });
67 67
@@ -70,8 +70,8 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
70 useThreadSelectionStore.getState().setAnchor(THREAD_B);70 useThreadSelectionStore.getState().setAnchor(THREAD_B);
71 71
72 const state = useThreadSelectionStore.getState();72 const state = useThreadSelectionStore.getState();
73 expect(state.anchorThreadId).toBe(THREAD_B);73 expect(state.anchorThreadKey).toBe(THREAD_B);
74 expect(state.selectedThreadIds.size).toBe(0);74 expect(state.selectedThreadKeys.size).toBe(0);
75 });75 });
76 76
77 it("enables range select from a plain-click anchor", () => {77 it("enables range select from a plain-click anchor", () => {
@@ -80,10 +80,10 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
80 store.rangeSelectTo(THREAD_D, ORDERED); // shift-click D80 store.rangeSelectTo(THREAD_D, ORDERED); // shift-click D
81 81
82 const state = useThreadSelectionStore.getState();82 const state = useThreadSelectionStore.getState();
83 expect(state.selectedThreadIds.has(THREAD_B)).toBe(true);83 expect(state.selectedThreadKeys.has(THREAD_B)).toBe(true);
84 expect(state.selectedThreadIds.has(THREAD_C)).toBe(true);84 expect(state.selectedThreadKeys.has(THREAD_C)).toBe(true);
85 expect(state.selectedThreadIds.has(THREAD_D)).toBe(true);85 expect(state.selectedThreadKeys.has(THREAD_D)).toBe(true);
86 expect(state.selectedThreadIds.size).toBe(3);86 expect(state.selectedThreadKeys.size).toBe(3);
87 });87 });
88 88
89 it("is a no-op when anchor is already set to the same thread", () => {89 it("is a no-op when anchor is already set to the same thread", () => {
@@ -105,8 +105,8 @@ describe("threadSelectionStore", () => { · 15 unmodified lines
105 store.setAnchor(THREAD_C);105 store.setAnchor(THREAD_C);
106 106
107 const state = useThreadSelectionStore.getState();107 const state = useThreadSelectionStore.getState();
108 expect(state.anchorThreadId).toBe(THREAD_C);108 expect(state.anchorThreadKey).toBe(THREAD_C);
109 expect(state.selectedThreadIds.size).toBe(0);109 expect(state.selectedThreadKeys.size).toBe(0);
110 });110 });
111 });111 });
112 112
@@ -115,9 +115,9 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
115 useThreadSelectionStore.getState().rangeSelectTo(THREAD_C, ORDERED);115 useThreadSelectionStore.getState().rangeSelectTo(THREAD_C, ORDERED);
116 116
117 const state = useThreadSelectionStore.getState();117 const state = useThreadSelectionStore.getState();
118 expect(state.selectedThreadIds.has(THREAD_C)).toBe(true);118 expect(state.selectedThreadKeys.has(THREAD_C)).toBe(true);
119 expect(state.selectedThreadIds.size).toBe(1);119 expect(state.selectedThreadKeys.size).toBe(1);
120 expect(state.anchorThreadId).toBe(THREAD_C);120 expect(state.anchorThreadKey).toBe(THREAD_C);
121 });121 });
122 122
123 it("selects range from anchor to target (forward)", () => {123 it("selects range from anchor to target (forward)", () => {
@@ -126,10 +126,10 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
126 store.rangeSelectTo(THREAD_D, ORDERED);126 store.rangeSelectTo(THREAD_D, ORDERED);
127 127
128 const state = useThreadSelectionStore.getState();128 const state = useThreadSelectionStore.getState();
129 expect(state.selectedThreadIds.has(THREAD_B)).toBe(true);129 expect(state.selectedThreadKeys.has(THREAD_B)).toBe(true);
130 expect(state.selectedThreadIds.has(THREAD_C)).toBe(true);130 expect(state.selectedThreadKeys.has(THREAD_C)).toBe(true);
131 expect(state.selectedThreadIds.has(THREAD_D)).toBe(true);131 expect(state.selectedThreadKeys.has(THREAD_D)).toBe(true);
132 expect(state.selectedThreadIds.size).toBe(3);132 expect(state.selectedThreadKeys.size).toBe(3);
133 });133 });
134 134
135 it("selects range from anchor to target (backward)", () => {135 it("selects range from anchor to target (backward)", () => {
@@ -138,10 +138,10 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
138 store.rangeSelectTo(THREAD_B, ORDERED);138 store.rangeSelectTo(THREAD_B, ORDERED);
139 139
140 const state = useThreadSelectionStore.getState();140 const state = useThreadSelectionStore.getState();
141 expect(state.selectedThreadIds.has(THREAD_B)).toBe(true);141 expect(state.selectedThreadKeys.has(THREAD_B)).toBe(true);
142 expect(state.selectedThreadIds.has(THREAD_C)).toBe(true);142 expect(state.selectedThreadKeys.has(THREAD_C)).toBe(true);
143 expect(state.selectedThreadIds.has(THREAD_D)).toBe(true);143 expect(state.selectedThreadKeys.has(THREAD_D)).toBe(true);
144 expect(state.selectedThreadIds.size).toBe(3);144 expect(state.selectedThreadKeys.size).toBe(3);
145 });145 });
146 146
147 it("keeps anchor stable across multiple range selects", () => {147 it("keeps anchor stable across multiple range selects", () => {
@@ -151,11 +151,11 @@ describe("threadSelectionStore", () => { · 3 unmodified lines
151 store.rangeSelectTo(THREAD_E, ORDERED); // extends B-E (anchor stays B)151 store.rangeSelectTo(THREAD_E, ORDERED); // extends B-E (anchor stays B)
152 152
153 const state = useThreadSelectionStore.getState();153 const state = useThreadSelectionStore.getState();
154 expect(state.anchorThreadId).toBe(THREAD_B);154 expect(state.anchorThreadKey).toBe(THREAD_B);
155 expect(state.selectedThreadIds.has(THREAD_B)).toBe(true);155 expect(state.selectedThreadKeys.has(THREAD_B)).toBe(true);
156 expect(state.selectedThreadIds.has(THREAD_C)).toBe(true);156 expect(state.selectedThreadKeys.has(THREAD_C)).toBe(true);
157 expect(state.selectedThreadIds.has(THREAD_D)).toBe(true);157 expect(state.selectedThreadKeys.has(THREAD_D)).toBe(true);
158 expect(state.selectedThreadIds.has(THREAD_E)).toBe(true);158 expect(state.selectedThreadKeys.has(THREAD_E)).toBe(true);
159 });159 });
160 160
161 it("falls back to toggle when anchor is not in the ordered list", () => {161 it("falls back to toggle when anchor is not in the ordered list", () => {
@@ -166,8 +166,8 @@ describe("threadSelectionStore", () => { · 4 unmodified lines
166 166
167 const state = useThreadSelectionStore.getState();167 const state = useThreadSelectionStore.getState();
168 // Should have added C and reset anchor to C168 // Should have added C and reset anchor to C
169 expect(state.selectedThreadIds.has(THREAD_C)).toBe(true);169 expect(state.selectedThreadKeys.has(THREAD_C)).toBe(true);
170 expect(state.anchorThreadId).toBe(THREAD_C);170 expect(state.anchorThreadKey).toBe(THREAD_C);
171 });171 });
172 172
173 it("falls back to toggle when target is not in the ordered list", () => {173 it("falls back to toggle when target is not in the ordered list", () => {
@@ -177,8 +177,8 @@ describe("threadSelectionStore", () => { · 3 unmodified lines
177 store.rangeSelectTo(unknownThread, ORDERED);177 store.rangeSelectTo(unknownThread, ORDERED);
178 178
179 const state = useThreadSelectionStore.getState();179 const state = useThreadSelectionStore.getState();
180 expect(state.selectedThreadIds.has(unknownThread)).toBe(true);180 expect(state.selectedThreadKeys.has(unknownThread)).toBe(true);
181 expect(state.anchorThreadId).toBe(unknownThread);181 expect(state.anchorThreadKey).toBe(unknownThread);
182 });182 });
183 183
184 it("selects the single thread when anchor equals target", () => {184 it("selects the single thread when anchor equals target", () => {
@@ -187,8 +187,8 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
187 store.rangeSelectTo(THREAD_C, ORDERED); // range from C to C187 store.rangeSelectTo(THREAD_C, ORDERED); // range from C to C
188 188
189 const state = useThreadSelectionStore.getState();189 const state = useThreadSelectionStore.getState();
190 expect(state.selectedThreadIds.has(THREAD_C)).toBe(true);190 expect(state.selectedThreadKeys.has(THREAD_C)).toBe(true);
191 expect(state.selectedThreadIds.size).toBe(1);191 expect(state.selectedThreadKeys.size).toBe(1);
192 });192 });
193 193
194 it("preserves previously selected threads outside the range", () => {194 it("preserves previously selected threads outside the range", () => {
@@ -200,11 +200,11 @@ describe("threadSelectionStore", () => { · 5 unmodified lines
200 store.rangeSelectTo(THREAD_D, ORDERED);200 store.rangeSelectTo(THREAD_D, ORDERED);
201 201
202 const state = useThreadSelectionStore.getState();202 const state = useThreadSelectionStore.getState();
203 expect(state.selectedThreadIds.has(THREAD_A)).toBe(true);203 expect(state.selectedThreadKeys.has(THREAD_A)).toBe(true);
204 expect(state.selectedThreadIds.has(THREAD_B)).toBe(true);204 expect(state.selectedThreadKeys.has(THREAD_B)).toBe(true);
205 expect(state.selectedThreadIds.has(THREAD_C)).toBe(true);205 expect(state.selectedThreadKeys.has(THREAD_C)).toBe(true);
206 expect(state.selectedThreadIds.has(THREAD_D)).toBe(true);206 expect(state.selectedThreadKeys.has(THREAD_D)).toBe(true);
207 expect(state.selectedThreadIds.size).toBe(4);207 expect(state.selectedThreadKeys.size).toBe(4);
208 });208 });
209 });209 });
210 210
@@ -216,8 +216,8 @@ describe("threadSelectionStore", () => { · 5 unmodified lines
216 store.clearSelection();216 store.clearSelection();
217 217
218 const state = useThreadSelectionStore.getState();218 const state = useThreadSelectionStore.getState();
219 expect(state.selectedThreadIds.size).toBe(0);219 expect(state.selectedThreadKeys.size).toBe(0);
220 expect(state.anchorThreadId).toBeNull();220 expect(state.anchorThreadKey).toBeNull();
221 });221 });
222 222
223 it("is a no-op when already empty", () => {223 it("is a no-op when already empty", () => {
@@ -226,7 +226,7 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
226 const stateAfter = useThreadSelectionStore.getState();226 const stateAfter = useThreadSelectionStore.getState();
227 227
228 // Should be referentially the same (no unnecessary re-render)228 // Should be referentially the same (no unnecessary re-render)
229 expect(stateAfter.selectedThreadIds).toBe(stateBefore.selectedThreadIds);229 expect(stateAfter.selectedThreadKeys).toBe(stateBefore.selectedThreadKeys);
230 });230 });
231 });231 });
232 232
@@ -239,8 +239,8 @@ describe("threadSelectionStore", () => { · 6 unmodified lines
239 store.removeFromSelection([THREAD_A, THREAD_C]);239 store.removeFromSelection([THREAD_A, THREAD_C]);
240 240
241 const state = useThreadSelectionStore.getState();241 const state = useThreadSelectionStore.getState();
242 expect(state.selectedThreadIds.has(THREAD_B)).toBe(true);242 expect(state.selectedThreadKeys.has(THREAD_B)).toBe(true);
243 expect(state.selectedThreadIds.size).toBe(1);243 expect(state.selectedThreadKeys.size).toBe(1);
244 });244 });
245 245
246 it("clears anchor when the anchor thread is removed", () => {246 it("clears anchor when the anchor thread is removed", () => {
@@ -249,7 +249,7 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
249 store.toggleThread(THREAD_B); // anchor = B249 store.toggleThread(THREAD_B); // anchor = B
250 store.removeFromSelection([THREAD_B]);250 store.removeFromSelection([THREAD_B]);
251 251
252 expect(useThreadSelectionStore.getState().anchorThreadId).toBeNull();252 expect(useThreadSelectionStore.getState().anchorThreadKey).toBeNull();
253 });253 });
254 254
255 it("preserves anchor when the anchor thread is not removed", () => {255 it("preserves anchor when the anchor thread is not removed", () => {
@@ -258,7 +258,7 @@ describe("threadSelectionStore", () => { · 2 unmodified lines
258 store.toggleThread(THREAD_B); // anchor = B258 store.toggleThread(THREAD_B); // anchor = B
259 store.removeFromSelection([THREAD_A]);259 store.removeFromSelection([THREAD_A]);
260 260
261 expect(useThreadSelectionStore.getState().anchorThreadId).toBe(THREAD_B);261 expect(useThreadSelectionStore.getState().anchorThreadKey).toBe(THREAD_B);
262 });262 });
263 263
264 it("is a no-op when none of the specified threads are selected", () => {264 it("is a no-op when none of the specified threads are selected", () => {
@@ -268,7 +268,7 @@ describe("threadSelectionStore", () => { · 3 unmodified lines
268 store.removeFromSelection([THREAD_B, THREAD_C]);268 store.removeFromSelection([THREAD_B, THREAD_C]);
269 const stateAfter = useThreadSelectionStore.getState();269 const stateAfter = useThreadSelectionStore.getState();
270 270
271 expect(stateAfter.selectedThreadIds).toBe(stateBefore.selectedThreadIds);271 expect(stateAfter.selectedThreadKeys).toBe(stateBefore.selectedThreadKeys);
272 });272 });
273 });273 });
274 274

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t