Skip to content

Commit 131b4d6

Browse files
Merge pull request #371 from primeroIMS/trigyn-testcases-record-form-form-nav-components-nav-item
Trigyn testcases record form form nav components nav item
2 parents b4dea3c + 3a59280 commit 131b4d6

File tree

3 files changed

+14
-43
lines changed

3 files changed

+14
-43
lines changed

app/javascript/components/jewel/component.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const Jewel = ({ value, isForm, isList, isError }) => {
1515

1616
if (isError && !isForm) {
1717
return (
18-
<>
18+
<div data-testid="jewel-error">
1919
{value}
2020
<Circle className={classes} />
21-
</>
21+
</div>
2222
);
2323
}
2424

app/javascript/components/record-form/nav/components/nav-item/component.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const Component = ({
6262

6363
return (
6464
<ListItem
65+
data-testid="list-item"
6566
id={`${formId}-${group}`}
6667
selected={selectedForm === formId && !isNested}
6768
button
@@ -73,7 +74,9 @@ const Component = ({
7374
}}
7475
disabled={disabledApplication}
7576
>
76-
<ListItemText className={groupItem ? css.nestedItem : css.item}>{formText()}</ListItemText>
77+
<ListItemText data-testid="list-item-text" className={groupItem ? css.nestedItem : css.item}>
78+
{formText()}
79+
</ListItemText>
7780
{isNested && (open ? <ExpandMore /> : <ExpandLess />)}
7881
</ListItem>
7982
);

app/javascript/components/record-form/nav/components/nav-item/component.unit.test.js app/javascript/components/record-form/nav/components/nav-item/component.spec.js

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

33
import { fromJS, Map, OrderedMap } from "immutable";
4-
import { ListItem, ListItemText } from "@material-ui/core";
54

6-
import Jewel from "../../../../jewel";
7-
import { setupMountedComponent } from "../../../../../test";
5+
import { mountedComponent, screen } from "../../../../../test-utils";
86
import { FormSectionRecord, FieldRecord } from "../../../records";
97

108
import NavItem from "./component";
119

1210
describe("<NavItem />", () => {
13-
let component;
14-
1511
const record = fromJS({
1612
case_id: "12345",
1713
case_id_display: "3c9d076",
@@ -100,7 +96,7 @@ describe("<NavItem />", () => {
10096
const props = {
10197
form: {},
10298
groupItem: false,
103-
handleClick: () => {},
99+
handleClick: () => { },
104100
isNested: false,
105101
isNew: false,
106102
itemsOfGroup: [],
@@ -111,46 +107,18 @@ describe("<NavItem />", () => {
111107
hasError: true
112108
};
113109

114-
beforeEach(() => {
115-
({ component } = setupMountedComponent(NavItem, props, initialState));
116-
});
117-
118110
it("renders a ListItem component />", () => {
119-
expect(component.find(ListItem)).to.have.lengthOf(1);
120-
});
121-
122-
it("renders a ListItemText component />", () => {
123-
expect(component.find(ListItemText)).to.have.lengthOf(1);
124-
});
125-
126-
it("should render valid props", () => {
127-
const NavItemProps = { ...component.find(NavItem).props() };
128-
129-
expect(component.find(NavItem)).to.have.lengthOf(1);
130-
[
131-
"form",
132-
"groupItem",
133-
"handleClick",
134-
"isNested",
135-
"isNew",
136-
"itemsOfGroup",
137-
"name",
138-
"open",
139-
"recordAlerts",
140-
"selectedForm",
141-
"hasError"
142-
].forEach(property => {
143-
expect(NavItemProps).to.have.property(property);
144-
delete NavItemProps[property];
145-
});
146-
expect(NavItemProps).to.be.empty;
111+
mountedComponent(<NavItem {...props} />, initialState);
112+
expect(screen.getAllByTestId("list-item")).toHaveLength(1);
147113
});
148114

149115
it("renders a ListItemText component />", () => {
150-
expect(component.find(ListItemText)).to.have.lengthOf(1);
116+
mountedComponent(<NavItem {...props} />, initialState);
117+
expect(screen.getAllByTestId("list-item-text")).toHaveLength(1);
151118
});
152119

153120
it("renders <Jewel/> for error", () => {
154-
expect(component.find(Jewel)).to.have.lengthOf(1);
121+
mountedComponent(<NavItem {...props} />, initialState);
122+
expect(screen.getAllByTestId("jewel-error")).toHaveLength(1);
155123
});
156124
});

0 commit comments

Comments
 (0)