Skip to content

Commit 1bc0b2c

Browse files
Merge branch 'develop_react_upgrade' into trigyn-testcases-record-actions-transitions-components-referrals
Conflicts: app/javascript/components/record-actions/transitions/components/referrals/component.spec.js app/javascript/components/record-actions/transitions/components/referrals/form-internal.spec.js app/javascript/components/record-actions/transitions/components/referrals/provided-consent.spec.js app/javascript/components/record-actions/transitions/components/referrals/provided-form.spec.js
2 parents d328010 + b363569 commit 1bc0b2c

File tree

323 files changed

+6202
-8924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

323 files changed

+6202
-8924
lines changed

app/javascript/__mocks__/fileMock.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "test-file-stub";

app/javascript/components/action-button/component.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function Component({
4141

4242
return (
4343
<ButtonType
44+
data-testid="action-button"
4445
id={buttonID}
4546
icon={icon}
4647
cancel={cancel}

app/javascript/components/action-dialog/component.jsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ const ActionDialog = ({
132132
}, [open, fetchAction]);
133133

134134
return (
135-
// eslint-disable-next-line jsx-a11y/no-static-element-interactions,jsx-a11y/click-events-have-key-events
136-
<div onClick={stopPropagation} data-testid="action-dialog">
135+
<div onClick={stopPropagation}>
137136
<Dialog
138137
open={open}
139138
onClose={onCloseDialog}

app/javascript/components/charts/bar-chart/component.jsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ const BarChart = ({ data, description, showDetails = false, hideLegend = false,
8484

8585
return (
8686
<div>
87-
{!showDetails ? <p className={css.description}>{description}</p> : null}
88-
<canvas id="reportGraph" ref={chartRef} height={!showDetails ? null : 400} />
87+
{!showDetails ? (
88+
<p className={css.description} data-testid="paragraph">
89+
{description}
90+
</p>
91+
) : null}
92+
<canvas id="reportGraph" data-testid="canvas" ref={chartRef} height={!showDetails ? null : 400} />
8993
</div>
9094
);
9195
};

app/javascript/components/charts/bar-chart/component.unit.test.js app/javascript/components/charts/bar-chart/component.spec.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
22

33
import { Map } from "immutable";
4+
import { mountedComponent, screen } from "test-utils";
45

56
import { buildGraphData } from "../../report/utils";
6-
import { setupMountedThemeComponent } from "../../../test";
77

88
import BarChart from "./component";
99

@@ -28,13 +28,14 @@ describe("<BarChart />", () => {
2828
});
2929
const showDetails = false;
3030
const description = "Number of cases broken down by nationality";
31-
const component = setupMountedThemeComponent(BarChart, {
31+
const props = {
3232
...buildGraphData(data, { t: () => "Total" }, { agencies }),
3333
description,
3434
showDetails
35-
});
35+
};
3636

37-
expect(component.find("p").props().children).to.equal("Number of cases broken down by nationality");
38-
expect(component.find("canvas")).to.have.lengthOf(1);
37+
mountedComponent(<BarChart {...props} />);
38+
expect(screen.getByText("Number of cases broken down by nationality")).toBeInTheDocument();
39+
expect(screen.getByTestId("canvas")).toBeInTheDocument();
3940
});
4041
});

app/javascript/components/charts/table-values/component.unit.test.js app/javascript/components/charts/table-values/component.spec.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
22

33
import { fromJS } from "immutable";
4-
import { TableRow } from "@material-ui/core";
4+
import { mountedComponent, screen } from "test-utils";
55

66
import { buildTableData } from "../../report/utils";
7-
import { abbrMonthNames, setupMountedComponent, stub } from "../../../test";
7+
import { abbrMonthNames, stub } from "../../../test";
88

99
import TableValues from "./component";
1010

@@ -74,13 +74,14 @@ describe("<TableValues />", () => {
7474
}
7575
];
7676

77-
const { component } = setupMountedComponent(TableValues, {
77+
const props = {
7878
...buildTableData(data, window.I18n, { agencies })
79-
});
79+
};
8080

81-
expect(component.find(TableRow)).to.have.lengthOf(6);
81+
mountedComponent(<TableValues />, props);
82+
expect(screen.getAllByRole("table")).toHaveLength(1);
83+
expect(screen.getAllByRole("columnheader")).toHaveLength(2);
8284
});
83-
8485
afterEach(() => {
8586
if (stubI18n) {
8687
window.I18n.t.restore();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
3+
import TableHeader from "./component";
4+
5+
describe("<TableValues />/components/<TableHeader/ >", () => {
6+
it("should render the correct number of headers", () => {
7+
const props = {
8+
columns: [
9+
{
10+
items: ["Category 1", "report.total"],
11+
colspan: 2
12+
},
13+
{
14+
items: ["6 - 11", "report.total"],
15+
colspan: 0
16+
}
17+
]
18+
};
19+
20+
mountedComponent(<TableHeader />, props);
21+
expect(screen.getAllByRole("row")).toHaveLength(1);
22+
expect(screen.getAllByRole("cell")).toHaveLength(2);
23+
});
24+
});

app/javascript/components/charts/table-values/components/table-header/component.unit.test.js

-32
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
3+
import CustomSnackbarProvider from "./component";
4+
5+
describe("<CustomSnackbarProvider /> - Component", () => {
6+
it("renders <CustomSnackbarProvider/> children", () => {
7+
const props = {
8+
children: <div>snackbar child</div>
9+
};
10+
11+
mountedComponent(<CustomSnackbarProvider {...props} />);
12+
expect(screen.getByText("snackbar child")).toBeInTheDocument();
13+
});
14+
});

app/javascript/components/custom-snackbar-provider/component.unit.test.js

-25
This file was deleted.

app/javascript/components/dashboard/badged-indicator/component.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const BadgedIndicator = ({ data, lookup, sectionTitle, indicator, loading, error
4949

5050
return (
5151
<>
52-
<LoadingIndicator {...loadingIndicatorProps}>
52+
<LoadingIndicator {...loadingIndicatorProps} data-testid="badged-indicator">
5353
<div className={css.sectionTitle}>{sectionTitle}</div>
5454
<div className={css.content}>{dashboardChips}</div>
5555
</LoadingIndicator>

app/javascript/components/dashboard/dashboard-chip/component.jsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ const DashboardChip = ({ label, type, handleClick }) => {
1111
const classes = clsx(css.chip, css[type]);
1212

1313
return (
14-
<Button id={`chip-${type}`} label={label} className={classes} onClick={handler} variant="text">
14+
<Button
15+
data-testid="chip-button"
16+
id={`chip-${type}`}
17+
label={label}
18+
className={classes}
19+
onClick={handler}
20+
variant="text"
21+
>
1522
{label}
1623
</Button>
1724
);

app/javascript/components/dashboard/dashboard-table/component.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const DashboardTable = ({ columns, data, query, title, pathname }) => {
6666
};
6767

6868
return (
69-
<div className={css.tableContainer}>
69+
<div className={css.tableContainer} data-testid="dashboard-table">
7070
<MUIDataTable {...tableOptions} />
7171
</div>
7272
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
import { fromJS } from "immutable";
3+
4+
import DashboardTable from "./component";
5+
6+
describe("<DashboardTable />", () => {
7+
const props = {
8+
columns: [],
9+
data: [],
10+
query: [],
11+
title: "testTitle",
12+
pathname: "/cases"
13+
};
14+
15+
const state = fromJS({
16+
user: {
17+
permissions: {
18+
cases: ["manage"]
19+
}
20+
}
21+
});
22+
23+
beforeEach(() => {
24+
mountedComponent(<DashboardTable {...props} />, state);
25+
});
26+
27+
it("renders a MUIDataTable />", () => {
28+
expect(screen.getByRole("grid")).toBeInTheDocument();
29+
});
30+
31+
it("should render text", () => {
32+
expect(screen.queryAllByText("testTitle")).toBeTruthy();
33+
});
34+
});

app/javascript/components/dashboard/dashboard-table/component.unit.test.js

-58
This file was deleted.

app/javascript/components/dashboard/flag-box/component.unit.test.js app/javascript/components/dashboard/flag-box/component.spec.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
2-
1+
import { mountedComponent, screen } from "test-utils";
32
import { fromJS } from "immutable";
43

5-
import { setupMountedComponent } from "../../../test";
6-
7-
import FlagBoxItem from "./components/flag-box-item";
84
import FlagBox from "./component";
95

106
describe("<FlagBox />", () => {
11-
let component;
127
const props = {
138
flags: fromJS([
149
{
@@ -33,10 +28,10 @@ describe("<FlagBox />", () => {
3328
};
3429

3530
beforeEach(() => {
36-
({ component } = setupMountedComponent(FlagBox, props, {}));
31+
mountedComponent(<FlagBox {...props} />);
3732
});
3833

3934
it("should render 2 FlagBoxItem", () => {
40-
expect(component.find(FlagBoxItem)).to.have.lengthOf(2);
35+
expect(screen.getAllByRole("button")).toHaveLength(2);
4136
});
4237
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
3+
import FlagBoxItem from "./component";
4+
5+
describe("<FlagBoxItem />", () => {
6+
const props = {
7+
date: "2020-12-10",
8+
reason: "Reason 1",
9+
recordId: "41a3e69b-991a-406e-b0ee-9123cb60c983",
10+
title: "User 1",
11+
user: "primero_test"
12+
};
13+
14+
beforeEach(() => {
15+
mountedComponent(<FlagBoxItem {...props} />);
16+
});
17+
18+
it("should render a h4 tag", () => {
19+
expect(screen.getByRole("heading")).toHaveTextContent("User 1");
20+
});
21+
22+
it("should render a span tag", () => {
23+
expect(screen.getByText("2020-12-10")).toBeInTheDocument();
24+
});
25+
26+
it("should render a p tag", () => {
27+
expect(screen.getByText("Reason 1")).toBeInTheDocument();
28+
});
29+
30+
it("should render a span tag", () => {
31+
expect(screen.getByText("primero_test")).toBeInTheDocument();
32+
});
33+
});

0 commit comments

Comments
 (0)