Skip to content

Commit 261ebae

Browse files
fixing unit test
1 parent 867de94 commit 261ebae

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

web/libs/editor/src/components/TaskSummary/__tests__/TaskSummary.test.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2+
import type { ReactElement } from "react";
13
import { render, screen } from "@testing-library/react";
24
import type { MSTAnnotation, MSTStore } from "../../../stores/types";
35
import TaskSummary from "../TaskSummary";
46

7+
const createTestQueryClient = () =>
8+
new QueryClient({
9+
defaultOptions: {
10+
queries: { retry: false },
11+
},
12+
});
13+
14+
const renderWithQueryClient = (ui: ReactElement) => {
15+
const queryClient = createTestQueryClient();
16+
return render(<QueryClientProvider client={queryClient}>{ui}</QueryClientProvider>);
17+
};
18+
519
// Polyfill for Object.groupBy which may not be available in test environment
620
if (!Object.groupBy) {
721
Object.groupBy = <T, K extends PropertyKey>(
@@ -165,7 +179,7 @@ describe("TaskSummary", () => {
165179
const annotations = [createMockAnnotation()];
166180
const store = createMockStore();
167181

168-
render(<TaskSummary annotations={annotations} store={store} />);
182+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
169183

170184
expect(screen.getByText("Task Summary")).toBeInTheDocument();
171185
expect(screen.getByText("Task Data")).toBeInTheDocument();
@@ -181,7 +195,7 @@ describe("TaskSummary", () => {
181195
},
182196
});
183197

184-
render(<TaskSummary annotations={annotations} store={store} />);
198+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
185199

186200
expect(screen.getByText("Agreement")).toBeInTheDocument();
187201
expect(screen.getByText("85.5%")).toBeInTheDocument();
@@ -197,7 +211,7 @@ describe("TaskSummary", () => {
197211
},
198212
});
199213

200-
render(<TaskSummary annotations={annotations} store={store} />);
214+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
201215

202216
// Backend controls agreement visibility, so if we have a number, show it
203217
expect(screen.getByText("Agreement")).toBeInTheDocument();
@@ -210,7 +224,7 @@ describe("TaskSummary", () => {
210224
project: null,
211225
});
212226

213-
render(<TaskSummary annotations={annotations} store={store} />);
227+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
214228

215229
// Backend controls agreement visibility, so if we have a number, show it
216230
expect(screen.getByText("Agreement")).toBeInTheDocument();
@@ -226,7 +240,7 @@ describe("TaskSummary", () => {
226240
];
227241
const store = createMockStore();
228242

229-
render(<TaskSummary annotations={annotations} store={store} />);
243+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
230244

231245
expect(screen.getByText("Annotations")).toBeInTheDocument();
232246
expect(screen.getByText("2")).toBeInTheDocument(); // Only submitted annotations
@@ -241,7 +255,7 @@ describe("TaskSummary", () => {
241255
];
242256
const store = createMockStore();
243257

244-
render(<TaskSummary annotations={annotations} store={store} />);
258+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
245259

246260
expect(screen.getByText("Predictions")).toBeInTheDocument();
247261
expect(screen.getByText("2")).toBeInTheDocument(); // Only submitted predictions
@@ -266,7 +280,7 @@ describe("TaskSummary", () => {
266280
]),
267281
});
268282

269-
render(<TaskSummary annotations={annotations} store={store} />);
283+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
270284

271285
expect(screen.getByText("Annotator")).toBeInTheDocument();
272286
expect(screen.getByText("sentiment")).toBeInTheDocument();
@@ -288,7 +302,7 @@ describe("TaskSummary", () => {
288302
]),
289303
});
290304

291-
render(<TaskSummary annotations={annotations} store={store} />);
305+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
292306

293307
// Object tags should appear in the data summary (as header and badge)
294308
expect(screen.getAllByText("text")).toHaveLength(2); // header + badge
@@ -299,7 +313,7 @@ describe("TaskSummary", () => {
299313
const annotations: MSTAnnotation[] = [];
300314
const store = createMockStore();
301315

302-
render(<TaskSummary annotations={annotations} store={store} />);
316+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
303317

304318
// Should show 0 for both annotations and predictions
305319
expect(screen.getByText("Annotations")).toBeInTheDocument();
@@ -322,7 +336,7 @@ describe("TaskSummary", () => {
322336
},
323337
});
324338

325-
render(<TaskSummary annotations={annotations} store={store} />);
339+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
326340

327341
// Should not display agreement when it's undefined
328342
expect(screen.queryByText("Agreement")).not.toBeInTheDocument();
@@ -351,7 +365,7 @@ describe("TaskSummary", () => {
351365
names: new Map([controlWithPerRegion]),
352366
});
353367

354-
render(<TaskSummary annotations={annotations} store={store} />);
368+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
355369

356370
expect(screen.getByText("regionLabel")).toBeInTheDocument();
357371
});
@@ -367,7 +381,7 @@ describe("TaskSummary", () => {
367381
]),
368382
});
369383

370-
render(<TaskSummary annotations={annotations} store={store} />);
384+
renderWithQueryClient(<TaskSummary annotations={annotations} store={store} />);
371385

372386
// Only valid object tags with $ prefix should appear (as header and badge)
373387
expect(screen.getAllByText("text")).toHaveLength(2); // header + badge

0 commit comments

Comments
 (0)