Skip to content

Commit cd9fe8d

Browse files
committed
Reverted deleted old test file
1 parent c007ea0 commit cd9fe8d

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
2+
3+
import { fromJS } from "immutable";
4+
5+
import { setupMountedComponent } from "../../../../test";
6+
import { mapEntriesToRecord } from "../../../../libs";
7+
import { FormSectionRecord } from "../../../record-form/records";
8+
import { RECORD_TYPES } from "../../../../config/constants";
9+
import { PrimeroModuleRecord } from "../../../application/records";
10+
import { ACTIONS } from "../../../permissions";
11+
12+
import FormsList from "./component";
13+
import ReorderActions from "./components/reorder-actions";
14+
import FormFilters from "./components/form-filters";
15+
import FormGroup from "./components/form-group";
16+
17+
describe("<FormsList />", () => {
18+
let component;
19+
20+
const formSections = [
21+
{
22+
id: 1,
23+
unique_id: "form_section_1",
24+
parent_form: "case",
25+
module_ids: ["primeromodule-cp"],
26+
order: 1,
27+
form_group_id: "group_1",
28+
order_form_group: 2
29+
},
30+
{
31+
id: 2,
32+
unique_id: "form_section_2",
33+
parent_form: "case",
34+
module_ids: ["primeromodule-cp"],
35+
order: 2,
36+
form_group_id: "group_1",
37+
order_form_group: 2
38+
},
39+
{
40+
id: 5,
41+
unique_id: "form_section_5",
42+
parent_form: "case",
43+
module_ids: ["primeromodule-cp"],
44+
order: 1,
45+
form_group_id: "group_2",
46+
order_form_group: 1
47+
}
48+
];
49+
50+
const initialState = fromJS({
51+
application: {
52+
modules: [
53+
PrimeroModuleRecord({
54+
unique_id: "primeromodule-cp",
55+
name: "CP",
56+
associated_record_types: [RECORD_TYPES.cases, RECORD_TYPES.tracing_requests, RECORD_TYPES.incidents]
57+
})
58+
]
59+
},
60+
records: {
61+
admin: {
62+
forms: {
63+
formSections: mapEntriesToRecord(formSections, FormSectionRecord, true)
64+
}
65+
}
66+
},
67+
forms: fromJS({
68+
options: {
69+
lookups: [
70+
{
71+
id: 51,
72+
unique_id: "lookup-form-group-cp-case",
73+
name: {
74+
en: "Form Groups - CP Case"
75+
},
76+
values: [
77+
{
78+
id: "group_1",
79+
disabled: false,
80+
display_text: {
81+
en: "Group 1"
82+
}
83+
},
84+
{
85+
id: "group_2",
86+
disabled: false,
87+
display_text: {
88+
en: "Group 2"
89+
}
90+
}
91+
]
92+
}
93+
]
94+
}
95+
}),
96+
user: {
97+
permissions: {
98+
metadata: [ACTIONS.MANAGE]
99+
}
100+
}
101+
});
102+
103+
beforeEach(() => {
104+
({ component } = setupMountedComponent(FormsList, {}, initialState));
105+
});
106+
107+
it("renders <PageHeading />", () => {
108+
expect(component.find("header h1").text()).to.equal("forms.label");
109+
});
110+
111+
it("renders <FormFilters />", () => {
112+
expect(component.find(FormFilters)).to.have.lengthOf(1);
113+
});
114+
115+
it("renders form sections", () => {
116+
expect(component.find(FormGroup)).to.have.lengthOf(2);
117+
});
118+
119+
describe("when there are no records", () => {
120+
const stateWithoutRecords = initialState.setIn(["records", "admin", "forms", "formSections"], fromJS([]));
121+
122+
beforeEach(() => {
123+
({ component } = setupMountedComponent(FormsList, {}, stateWithoutRecords));
124+
});
125+
126+
it("renders <FormFilters/>", () => {
127+
expect(component.find(FormFilters)).to.have.lengthOf(1);
128+
});
129+
130+
it("does not renders form sections", () => {
131+
expect(component.find(FormGroup)).to.have.lengthOf(0);
132+
});
133+
});
134+
135+
describe("when there reorder is enabled", () => {
136+
const stateReorderEnabled = initialState.setIn(["records", "admin", "forms", "reorderedForms", "enabled"], true);
137+
138+
beforeEach(() => {
139+
({ component } = setupMountedComponent(FormsList, {}, stateReorderEnabled));
140+
});
141+
142+
it("renders the <RorderActions />", () => {
143+
expect(component.find(ReorderActions)).to.have.lengthOf(1);
144+
});
145+
146+
it("disable the <FormFilters/>", () => {
147+
expect(component.find(FormFilters).props().disabled).to.be.true;
148+
});
149+
});
150+
});

0 commit comments

Comments
 (0)