Skip to content

Commit ea5a6ff

Browse files
committed
Resolved PR comments
1 parent 67e73f3 commit ea5a6ff

File tree

3 files changed

+37
-43
lines changed

3 files changed

+37
-43
lines changed

app/javascript/components/record-list/add-record-menu.spec.js

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { fromJS } from "immutable";
22

3-
import { mountedComponent, screen } from "../../test-utils";
3+
import { mountedComponent, screen, userEvent } from "../../test-utils";
44
import { RECORD_PATH } from "../../config";
55
import { PrimeroModuleRecord } from "../application/records";
66

@@ -38,40 +38,42 @@ describe("<AddRecordMenu /> record-list/add-record-menu", () => {
3838
});
3939

4040
it("renders a single <Button /> because user only has access to a single module", () => {
41-
mountedComponent(<AddRecordMenu {...props} /> , state);
41+
mountedComponent(<AddRecordMenu {...props} />, state);
4242

43-
expect(screen.getAllByRole('button')).toHaveLength(1)
43+
expect(screen.getAllByRole("button")).toHaveLength(1);
4444
});
4545

4646
it("renders a single <Menu /> because user has access more than one module", () => {
47-
48-
mountedComponent(<AddRecordMenu {...props} /> , state.merge(fromJS({ user: { modules: ["primerotest-1", "primerotest-3"] } })));
47+
mountedComponent(
48+
<AddRecordMenu {...props} />,
49+
state.merge(fromJS({ user: { modules: ["primerotest-1", "primerotest-3"] } }))
50+
);
4951

50-
expect(screen.getByTestId('menu')).toBeInTheDocument()
51-
52+
expect(screen.getByTestId("menu")).toBeInTheDocument();
5253
});
5354

54-
it("opens a <CreateRecordDialog /> if module allow_searchable_ids", () => {
55+
it("opens a <CreateRecordDialog /> if module allow_searchable_ids", async () => {
56+
const user = userEvent.setup();
5557

56-
57-
mountedComponent(<AddRecordMenu {...props} /> , state.merge(fromJS({ user: { modules: ["primerotest-3"] } })));
58-
59-
expect(screen.getAllByRole('button')).toHaveLength(1)
58+
mountedComponent(
59+
<AddRecordMenu {...{ ...props }} />,
60+
state.merge(fromJS({ user: { modules: ["primerotest-3"] } }))
61+
);
62+
await user.click(screen.getByTestId("new-record"));
63+
expect(screen.getAllByRole("presentation")).toHaveLength(1);
6064
});
6165

6266
it("does not render <CreateRecordDialog /> if module does not allow_searchable_ids", () => {
63-
64-
65-
mountedComponent(<AddRecordMenu {...props} /> , state.merge(fromJS({ user: { modules: ["primerotest-1"] } })));
66-
67-
expect(screen.queryByTestId('CreateRecordDialog')).toBeNull()
68-
67+
mountedComponent(<AddRecordMenu {...props} />, state.merge(fromJS({ user: { modules: ["primerotest-1"] } })));
68+
expect(screen.queryByTestId("CreateRecordDialog")).toBeNull();
6969
});
7070

7171
it("does not render <CreateRecordDialog /> if recordType is not cases", () => {
72+
mountedComponent(
73+
<AddRecordMenu {...{ recordType: RECORD_PATH.tracing_requests }} />,
74+
state.merge(fromJS({ user: { modules: ["primerotest-1"] } }))
75+
);
7276

73-
mountedComponent(<AddRecordMenu { ...{recordType: RECORD_PATH.tracing_requests} } /> , state.merge(fromJS({ user: { modules: ["primerotest-1"] } })));
74-
75-
expect(screen.queryByTestId('CreateRecordDialog')).toBeNull()
77+
expect(screen.queryByTestId("CreateRecordDialog")).toBeNull();
7678
});
7779
});

app/javascript/components/record-list/container.spec.js

+13-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
2-
3-
import { Route } from "react-router-dom";
41
import { fromJS, OrderedMap } from "immutable";
52

63
import { ACTIONS } from "../permissions";
@@ -11,7 +8,6 @@ import { PrimeroModuleRecord } from "../application/records";
118
import RecordList from "./container";
129

1310
describe("<RecordList />", () => {
14-
1511
const initialState = fromJS({
1612
records: {
1713
FiltersTabs: {
@@ -305,41 +301,39 @@ describe("<RecordList />", () => {
305301
});
306302

307303
it("renders record list table", done => {
308-
mountedComponent(<RecordList />,initialState, ["/cases"])
309-
expect(screen.getByRole('toolbar')).toBeInTheDocument()
304+
mountedComponent(<RecordList />, initialState, ["/cases"]);
305+
expect(screen.getByRole("toolbar")).toBeInTheDocument();
310306
done();
311307
});
312308

313309
it("renders record view modal", done => {
314-
mountedComponent(<RecordList />,initialState, ["/cases"])
315-
expect(screen.getAllByText('messages.record_list.rows_per_page')).toHaveLength(2)
316-
310+
mountedComponent(<RecordList />, initialState, ["/cases"]);
311+
expect(screen.getAllByText("messages.record_list.rows_per_page")).toHaveLength(2);
312+
317313
done();
318314
});
319315

320316
it("opens the view modal when a record is clicked", () => {
321-
mountedComponent(<RecordList />,initialState, ["/cases"])
322-
expect(screen.getAllByText('messages.record_list.rows_per_page')).toHaveLength(2)
317+
mountedComponent(<RecordList />, initialState, ["/cases"]);
318+
expect(screen.getAllByText("messages.record_list.rows_per_page")).toHaveLength(2);
323319
});
324320

325321
it("renders filters", () => {
326-
mountedComponent(<RecordList />,initialState, ["/cases"])
327-
expect(screen.getByTestId('filters')).toBeInTheDocument()
328-
322+
mountedComponent(<RecordList />, initialState, ["/cases"]);
323+
expect(screen.getByTestId("filters")).toBeInTheDocument();
329324
});
330325

331326
describe("when offline", () => {
332-
333327
it("when a record is clicked it does not open the view modal", () => {
334-
mountedComponent(<RecordList />,initialState.setIn(["application", "online"], false), ["/cases"])
335-
expect(screen.getByTestId('filters')).toBeInTheDocument()
328+
mountedComponent(<RecordList />, initialState.setIn(["application", "online"], false), ["/cases"]);
329+
expect(screen.queryAllByRole("presentation")).toHaveLength(0);
336330
});
337331
});
338332

339333
describe("when age is 0", () => {
340334
it("renders a 0 in the cell ", () => {
341-
mountedComponent(<RecordList />,initialState.setIn(["application", "online"], false), ["/cases"])
342-
expect(screen.getAllByText('0-0 messages.record_list.of 0')).toHaveLength(2)
335+
mountedComponent(<RecordList />, initialState.setIn(["application", "online"], false), ["/cases"]);
336+
expect(screen.getAllByText("0-0 messages.record_list.of 0")).toHaveLength(2);
343337
});
344338
});
345339
});

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"test:coverage": "NODE_ENV=test nyc --nycrc-path './.nycrc.yml' npm run test:all",
2424
"test:run": "NODE_ENV=test mocha --timeout 8000 --check-leaks --parallel --reporter=dot --exit",
2525
"test:all-bb": "NODE_ENV=test mocha --timeout 8000 --check-leaks --reporter=dot './app/javascript/**/*.unit.test.js'",
26-
"test:new": "NODE_ENV=test NODE_OPTIONS='--max-old-space-size=6144' jest --no-compilation-cache --clearMocks --forceExit",
27-
"test:new:profile": "NODE_ENV=test NODE_OPTIONS='--max-old-space-size=6144' node --no-compilation-cache --expose-gc ./node_modules/.bin/jest --runInBand --logHeapUsage --detectOpenHandles",
28-
"test:new:debug": "npm run test:new:profile -- --inspect-brk",
26+
"test:new": "NODE_ENV=test jest",
2927
"jscpd": "npm run jscpd:run 'app/javascript/**'",
3028
"jscpd:run": "jscpd",
3129
"lint": "npm run lint:run -- --fix",

0 commit comments

Comments
 (0)