Skip to content

Commit fccc586

Browse files
committed
fix BoxesView FE test
1 parent a533953 commit fccc586

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

front/src/types/generated/graphql.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ export type CreatedBoxDataDimensions = {
284284
__typename?: 'CreatedBoxDataDimensions';
285285
category?: Maybe<Array<Maybe<DimensionInfo>>>;
286286
product?: Maybe<Array<Maybe<ProductDimensionInfo>>>;
287+
tag?: Maybe<Array<Maybe<TagDimensionInfo>>>;
287288
};
288289

289290
export type CreatedBoxesData = DataCube & {
@@ -300,6 +301,7 @@ export type CreatedBoxesResult = {
300301
gender?: Maybe<ProductGender>;
301302
itemsCount?: Maybe<Scalars['Int']>;
302303
productId?: Maybe<Scalars['Int']>;
304+
tagIds?: Maybe<Array<Scalars['Int']>>;
303305
};
304306

305307
export type DataCube = {
@@ -527,12 +529,6 @@ export type Metrics = {
527529
};
528530

529531

530-
export type MetricsMovedStockOverviewArgs = {
531-
after?: InputMaybe<Scalars['Date']>;
532-
before?: InputMaybe<Scalars['Date']>;
533-
};
534-
535-
536532
export type MetricsNumberOfBeneficiariesServedArgs = {
537533
after?: InputMaybe<Scalars['Date']>;
538534
before?: InputMaybe<Scalars['Date']>;

front/src/views/Boxes/BoxesView.test.tsx

+20-13
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { GraphQLError } from "graphql";
33
import userEvent from "@testing-library/user-event";
44
import { base2 } from "mocks/bases";
55
import { organisation1, organisation2 } from "mocks/organisations";
6-
import { screen, render, waitFor } from "tests/test-utils";
6+
import { screen, render, waitFor, within } from "tests/test-utils";
77
import { generateMoveBoxRequest } from "queries/dynamic-mutations";
88
import { ErrorBoundary } from "@sentry/react";
99
import { AlertWithoutAction } from "components/Alerts";
1010
import { TableSkeleton } from "components/Skeletons";
1111
import { Suspense } from "react";
12+
import { cache } from "queries/cache";
1213
import Boxes, { ACTION_OPTIONS_FOR_BOXESVIEW_QUERY, BOXES_FOR_BOXESVIEW_QUERY } from "./BoxesView";
1314

1415
const boxesQuery = {
@@ -356,7 +357,7 @@ const actionsQuery = {
356357
},
357358
};
358359

359-
const gqlRequestPrep = generateMoveBoxRequest(["4495955", "1481666"], 17);
360+
const gqlRequestPrep = generateMoveBoxRequest(["8650860", "1481666"], 17);
360361

361362
const moveBoxesMutation = {
362363
request: {
@@ -366,9 +367,9 @@ const moveBoxesMutation = {
366367
result: {
367368
data: {
368369
// TODO: the data should be placed in the mocks
369-
moveBox4495955: {
370+
moveBox8650860: {
370371
__typename: "Box",
371-
labelIdentifier: "4495955",
372+
labelIdentifier: "8650860",
372373
location: {
373374
__typename: "ClassicLocation",
374375
id: "17",
@@ -436,6 +437,7 @@ describe("4.8.1 - Initial load of Page", () => {
436437
routePath: "/bases/:baseId/boxes",
437438
initialUrl: "/bases/2/boxes",
438439
mocks: [boxesQuery, actionsQuery],
440+
cache,
439441
addTypename: true,
440442
globalPreferences: {
441443
dispatch: vi.fn(),
@@ -478,6 +480,7 @@ describe("4.8.1 - Initial load of Page", () => {
478480
routePath: "/bases/:baseId/boxes",
479481
initialUrl: "/bases/2/boxes",
480482
mocks,
483+
cache,
481484
addTypename: true,
482485
globalPreferences: {
483486
dispatch: vi.fn(),
@@ -511,6 +514,7 @@ describe("4.8.1 - Initial load of Page", () => {
511514
routePath: "/bases/:baseId/boxes",
512515
initialUrl: "/bases/2/boxes",
513516
mocks: [boxesQuery, actionsQuery],
517+
cache,
514518
addTypename: true,
515519
globalPreferences: {
516520
dispatch: vi.fn(),
@@ -545,6 +549,7 @@ describe("4.8.2 - Selecting rows and performing bulk actions", () => {
545549
routePath: "/bases/:baseId/boxes",
546550
initialUrl: "/bases/2/boxes",
547551
mocks: [boxesQuery, actionsQuery, moveBoxesMutation],
552+
cache,
548553
addTypename: true,
549554
globalPreferences: {
550555
dispatch: vi.fn(),
@@ -558,14 +563,15 @@ describe("4.8.2 - Selecting rows and performing bulk actions", () => {
558563
);
559564

560565
// Test case 4.8.2.1 - Select two checkboxes and perform bulk moves
561-
562566
const row1 = await screen.findByRole("row", { name: /8650860/i }, { timeout: 5000 });
563-
// eslint-disable-next-line testing-library/no-node-access
564-
const checkbox1 = row1.querySelector('input[type="checkbox"]');
567+
const checkbox1 = within(row1).getByRole("checkbox", {
568+
name: /toggle row selected/i,
569+
});
565570

566571
const row2 = await screen.findByRole("row", { name: /1481666/i });
567-
// eslint-disable-next-line testing-library/no-node-access
568-
const checkbox2 = row2.querySelector('input[type="checkbox"]');
572+
const checkbox2 = within(row2).getByRole("checkbox", {
573+
name: /toggle row selected/i,
574+
});
569575

570576
if (checkbox1 && checkbox2) {
571577
expect(checkbox1).not.toBeChecked();
@@ -576,25 +582,26 @@ describe("4.8.2 - Selecting rows and performing bulk actions", () => {
576582
await user.click(checkbox2);
577583
await waitFor(() => expect(checkbox2).toBeChecked());
578584

579-
const moveBoxesButton = screen.getByRole("button", {
585+
const moveBoxesButton = await screen.findByRole("button", {
580586
name: /move to/i,
581587
});
582588

583589
await user.click(moveBoxesButton);
584590

585591
expect(
586592
await screen.findByRole("menuitem", {
587-
name: /wh2/i,
593+
name: /wh1/i,
588594
}),
589595
).toBeInTheDocument();
590596

591597
await user.click(
592598
screen.getByRole("menuitem", {
593-
name: /wh2/i,
599+
name: /wh1/i,
594600
}),
595601
);
596602

597-
expect((await screen.findAllByText(/wh2/i)).length).toBe(2);
603+
expect(await within(row1).findByText(/wh1/i)).toBeInTheDocument();
604+
expect(await within(row2).findByText(/wh1/i)).toBeInTheDocument();
598605
}
599606
}, 15000);
600607
});

0 commit comments

Comments
 (0)