Skip to content

Commit 8040e3f

Browse files
authored
test(map): cover cluster→task navigation guard in MapScreen (#156)
Extend MapScreen.test.tsx with the cluster-expansion interaction that was previously untested: a multi-task cluster callout must NOT navigate (guard `if (!isCluster && firstTask)`), while a count:null promoted single-task marker must navigate to TaskDetail with the correct taskId. The existing single-marker navigation test is retained. Closes #147
1 parent 58fe466 commit 8040e3f

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/__tests__/MapScreen.test.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,57 @@ describe('MapScreen — with location and tasks', () => {
262262
taskId: 'task-1',
263263
});
264264
});
265+
266+
it('does NOT navigate when a multi-task cluster callout is pressed', () => {
267+
// 11 tasks in the same coarse grid bucket → one cluster with count > 1.
268+
const clustered = Array.from({ length: 11 }, (_, i) =>
269+
makeTask(`c${i}`, 51.5 + i * 0.0001, -0.1 + i * 0.0001),
270+
);
271+
defaultFeed(clustered);
272+
let tree: renderer.ReactTestRenderer;
273+
void act(() => {
274+
tree = renderer.create(<MapScreen />);
275+
});
276+
277+
const clusterNodes = tree!.root.findAll(
278+
n =>
279+
typeof n.props.testID === 'string' &&
280+
n.props.testID.startsWith('cluster-'),
281+
);
282+
expect(clusterNodes.length).toBeGreaterThan(0);
283+
284+
void act(() => {
285+
clusterNodes[0]!.props.onCalloutPress?.();
286+
});
287+
288+
// The guard `if (!isCluster && firstTask)` must prevent navigation for a
289+
// multi-task cluster (no zoom/expand available in Jest).
290+
expect(mockNavigate).not.toHaveBeenCalled();
291+
});
292+
293+
it('navigates when a count:null promoted cluster (single task) callout is pressed', () => {
294+
// 10 tasks collapse into one multi-task cluster; a lone task in a different
295+
// grid bucket is promoted to a single marker with count === null.
296+
const lone = makeTask('lone', 52.5, 0.5);
297+
const clustered = Array.from({ length: 10 }, (_, i) =>
298+
makeTask(`c${i}`, 51.5 + i * 0.0001, -0.1 + i * 0.0001),
299+
);
300+
defaultFeed([lone, ...clustered]);
301+
302+
let tree: renderer.ReactTestRenderer;
303+
void act(() => {
304+
tree = renderer.create(<MapScreen />);
305+
});
306+
307+
const loneNode = tree!.root.findAll(n => n.props.testID === 'marker-lone');
308+
expect(loneNode.length).toBeGreaterThan(0);
309+
310+
void act(() => {
311+
loneNode[0]!.props.onCalloutPress?.();
312+
});
313+
314+
expect(mockNavigate).toHaveBeenCalledWith('TaskDetail', {
315+
taskId: 'lone',
316+
});
317+
});
265318
});

0 commit comments

Comments
 (0)