Skip to content

Commit b363569

Browse files
Merge pull request #456 from primeroIMS/trigyn-testcase-incidents-from-case
Trigyn testcase incidents from case
2 parents e7bf11f + 3a6da55 commit b363569

File tree

9 files changed

+209
-330
lines changed

9 files changed

+209
-330
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
import { fromJS } from "immutable";
3+
4+
import { RECORD_TYPES } from "../../../../config";
5+
6+
import IncidentDetail from "./component";
7+
8+
describe("<IncidentDetail /> - Component", () => {
9+
const props = {
10+
css: {
11+
titleHeader: {}
12+
},
13+
handleSubmit: () => {},
14+
incidentCaseId: "case-unique-id-1",
15+
incidentCaseIdDisplay: "case-short-id-1",
16+
incidentDateInterview: "2020-Oct-02",
17+
incidentDate: "2020-Oct-01",
18+
incidentUniqueID: "e25c5cb1-1257-472e-b2ec-05f568a3b51e",
19+
incidentType: "test",
20+
mode: { isShow: true, isEdit: false },
21+
setFieldValue: () => {},
22+
recordType: RECORD_TYPES.cases,
23+
handleCreateIncident: () => {}
24+
};
25+
26+
const initialState = fromJS({
27+
user: {
28+
permissions: {
29+
incidents: ["read", "write"]
30+
}
31+
}
32+
});
33+
34+
beforeEach(() => {
35+
mountedComponent(<IncidentDetail {...props} />, initialState);
36+
});
37+
38+
it("render IncidentDetail component", () => {
39+
expect(screen.getByText("incidents.date_of_incident")).toBeInTheDocument();
40+
});
41+
42+
it("render a DisplayData", () => {
43+
expect(screen.getAllByTestId("display-data")).toHaveLength(3);
44+
});
45+
46+
it("render a DisplayData with action button", () => {
47+
expect(screen.getAllByRole("button")).toHaveLength(2);
48+
});
49+
});

app/javascript/components/incidents-from-case/components/detail/component.unit.test.js

-82
This file was deleted.

app/javascript/components/incidents-from-case/components/panel/component.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const Component = ({
6969
};
7070

7171
return (
72-
<div key={incident.get("unique_id")}>
72+
<div key={incident.get("unique_id")} data-testid="panel">
7373
<Accordion expanded={expanded} onChange={handleExpanded} className={css.panel}>
7474
<AccordionSummary
7575
expandIcon={<ExpandMoreIcon />}

app/javascript/components/incidents-from-case/components/panel/component.unit.test.js app/javascript/components/incidents-from-case/components/panel/component.spec.js

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

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

6-
import LookupValue from "../../../record-form/form/subforms/subform-header-lookup";
7-
import { setupMountedComponent } from "../../../../test";
8-
import IncidentSummary from "../summary";
9-
import IncidentDetail from "../detail";
106
import { RECORD_TYPES } from "../../../../config";
11-
import * as R from "../../../record-form/records";
7+
import { FieldRecord } from "../../../record-form/records";
128
import { mapEntriesToRecord } from "../../../../libs";
139

1410
import IncidentPanel from "./component";
1511

1612
describe("<IncidentPanel /> - Component", () => {
17-
let component;
1813
const props = {
1914
incident: fromJS({
2015
created_by: "primero_gbv",
@@ -101,51 +96,27 @@ describe("<IncidentPanel /> - Component", () => {
10196
}
10297
]
10398
},
104-
fields: mapEntriesToRecord(fields, R.FieldRecord)
99+
fields: mapEntriesToRecord(fields, FieldRecord)
105100
}
106101
});
107102

108103
beforeEach(() => {
109-
({ component } = setupMountedComponent(IncidentPanel, props, initialState));
104+
mountedComponent(<IncidentPanel {...props} />, initialState);
110105
});
111106

112107
it("render IncidentPanel component", () => {
113-
expect(component.find(IncidentPanel)).to.have.length(1);
108+
expect(screen.getByTestId("panel")).toBeInTheDocument();
114109
});
115110

116-
it("render a Accordions", () => {
117-
expect(component.find(Accordion)).to.have.lengthOf(1);
118-
expect(component.find(AccordionSummary)).to.have.lengthOf(1);
119-
expect(component.find(AccordionDetails)).to.have.lengthOf(1);
111+
it("render IncidentSummary component", () => {
112+
expect(screen.getAllByTestId("incidentsummary")).toHaveLength(1);
120113
});
121114

122-
it("render a IncidentSummary", () => {
123-
expect(component.find(IncidentSummary)).to.have.lengthOf(1);
115+
it("render IncidentDetail component", () => {
116+
expect(screen.getByText("incidents.date_of_incident")).toBeInTheDocument();
124117
});
125118

126-
it("render a IncidentDetail", () => {
127-
expect(component.find(IncidentDetail)).to.have.lengthOf(1);
128-
});
129-
130-
describe("with violence-type-lookup", () => {
131-
it("should use the lookup defined in the option_strings_source", () => {
132-
expect(component.find(IncidentDetail).find(LookupValue).props().optionsStringSource).to.equal(
133-
"lookup-gbv-sexual-violence-type"
134-
);
135-
});
136-
137-
it("renders the translated value", () => {
138-
expect(component.find(IncidentDetail).find(LookupValue).text()).to.equal("Test1");
139-
});
140-
});
141-
142-
it("renders component with valid props", () => {
143-
const incidentsProps = { ...component.find(IncidentPanel).props() };
144-
145-
["incident", "incidentCaseId", "css", "mode", "setFieldValue", "handleSubmit", "recordType"].forEach(property => {
146-
expect(incidentsProps).to.have.property(property);
147-
delete incidentsProps[property];
148-
});
149-
expect(incidentsProps).to.be.empty;
119+
it("with violence-type-lookup-renders the translated value", () => {
120+
expect(screen.getAllByText("Test1")).toHaveLength(2);
150121
});
151122
});

app/javascript/components/incidents-from-case/components/summary/component.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { NAME_SUMMARY } from "../../constants";
77

88
const Component = ({ css, incidentDate, incidentType }) => {
99
return (
10-
<Grid container spacing={2} alignItems="center">
10+
<Grid container spacing={2} alignItems="center" data-testid="incidentsummary">
1111
<Grid item md={10} xs={8}>
1212
<div className={css.wrapper}>
1313
<div className={css.titleHeader}>{incidentDate}</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { mountedComponent, screen } from "test-utils";
2+
import { fromJS } from "immutable";
3+
4+
import IncidentSummary from "./component";
5+
6+
describe("<IncidentSummary /> - Component", () => {
7+
const props = {
8+
incidentDate: "2020-Oct-01",
9+
css: {
10+
titleHeader: {}
11+
},
12+
incidentType: <></>
13+
};
14+
15+
beforeEach(() => {
16+
mountedComponent(<IncidentSummary {...props} />, fromJS({}));
17+
});
18+
19+
it("render IncidentSummary component", () => {
20+
expect(screen.getByText("2020-Oct-01")).toBeInTheDocument();
21+
});
22+
});

app/javascript/components/incidents-from-case/components/summary/component.unit.test.js

-41
This file was deleted.

0 commit comments

Comments
 (0)