Skip to content

Commit de175f7

Browse files
Merge pull request #459 from primeroIMS/trigyn-testcases-record-from-from-subforms-subform-dialog-fields
Trigyn testcases record from from subforms subform dialog fields
2 parents 21dbd33 + f944cac commit de175f7

File tree

3 files changed

+94
-258
lines changed

3 files changed

+94
-258
lines changed

app/javascript/components/record-form/form/subforms/subform-dialog-fields/component.spec.js

+93-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { mountedComponent, screen } from "../../../../../test-utils";
1+
import { fromJS } from "immutable";
2+
import { mountedComponent, screen, userEvent } from "../../../../../test-utils";
23
import { FieldRecord, FormSectionRecord } from "../../../records";
34
import { TEXT_FIELD } from "../../../constants";
45

@@ -46,7 +47,7 @@ describe("<SubformDialogFields />", () => {
4647
describe("when a field of a subform is also a subform", () => {
4748
const subFormProps = {
4849
mode: { isShow: true },
49-
formSection: { unqique_id: "test_id" },
50+
formSection: { unique_id: "test_id" },
5051
recordType: "cases",
5152
recordModuleID: "primeromodule-cp",
5253
parentValues: {},
@@ -60,6 +61,7 @@ describe("<SubformDialogFields />", () => {
6061
unique_id: "perpetratorsId",
6162
visible: true,
6263
type: "subform",
64+
display_name: { en: "Perpetrators Subform" },
6365
subform_section_id: FormSectionRecord({
6466
unique_id: "perpetrators",
6567
fields: [
@@ -79,7 +81,17 @@ describe("<SubformDialogFields />", () => {
7981

8082
it("render the SubformFieldSubform", () => {
8183
mountedComponent(<SubformDialogFields {...subFormProps} />, {}, [], {}, { registerField: () => {} });
82-
expect(screen.getByTestId("subform-field-subform")).toBeInTheDocument(1);
84+
expect(screen.getByTestId("subform-field-subform")).toBeInTheDocument();
85+
});
86+
87+
it("render the SubformField", () => {
88+
mountedComponent(<SubformDialogFields {...subFormProps} />, {}, [], {}, { registerField: () => {} });
89+
expect(screen.getByTestId("subform-field")).toBeInTheDocument();
90+
});
91+
92+
it("render the subform", () => {
93+
mountedComponent(<SubformDialogFields {...subFormProps} />, {}, [], {}, { registerField: () => {} });
94+
expect(screen.getByText("Perpetrators Subform")).toBeInTheDocument();
8395
});
8496
});
8597

@@ -114,4 +126,82 @@ describe("<SubformDialogFields />", () => {
114126
expect(screen.getAllByTestId("form-section-field")).toHaveLength(1);
115127
});
116128
});
129+
130+
describe("when a field has tag properties", () => {
131+
const tagProps = {
132+
mode: { isEdit: true },
133+
formSection: { unique_id: "test_id" },
134+
field: FieldRecord({
135+
name: "attack_on_hospitals",
136+
subform_section_id: FormSectionRecord({
137+
unique_id: "attack_on_hospitals",
138+
fields: [
139+
FieldRecord({
140+
name: "facility_attack_type",
141+
visible: true,
142+
type: "select_box",
143+
multiple: true,
144+
option_strings_source: "lookup lookup-facility-attack-type",
145+
option_strings_condition: {
146+
hospitals: { in: { violation_category: ["attack_on_hospitals"] } }
147+
}
148+
})
149+
]
150+
})
151+
}),
152+
recordType: "cases",
153+
recordModuleID: "primeromodule-cp",
154+
values: {},
155+
parentValues: {
156+
violation_category: ["attack_on_hospitals", "killing"]
157+
}
158+
};
159+
160+
const stateWithLookups = fromJS({
161+
forms: {
162+
options: {
163+
lookups: [
164+
{
165+
id: 1,
166+
name: { en: "Facility Attack Type" },
167+
unique_id: "lookup-facility-attack-type",
168+
values: [
169+
{ id: "attack_on_hospitals", display_text: { en: "Attack on hospitals" }, tags: ["hospitals"] },
170+
{ id: "other", display_text: { en: "Other" }, tags: [] }
171+
]
172+
}
173+
]
174+
}
175+
}
176+
});
177+
178+
it("renders the options tagged as hospitals if the condition is met", async () => {
179+
mountedComponent(<SubformDialogFields {...tagProps} />, stateWithLookups, [], {}, { registerField: () => {} });
180+
const user = userEvent.setup();
181+
182+
const autoCompleteDropdown = screen.getByRole("button", { name: "Open" });
183+
184+
await user.click(autoCompleteDropdown);
185+
186+
expect(screen.getByText("Attack on hospitals")).toBeInTheDocument();
187+
});
188+
189+
it("renders all options if the condition is not met", async () => {
190+
mountedComponent(
191+
<SubformDialogFields {...{ ...tagProps, parentValues: {} }} />,
192+
stateWithLookups,
193+
[],
194+
{},
195+
{ registerField: () => {} }
196+
);
197+
const user = userEvent.setup();
198+
199+
const autoCompleteDropdown = screen.getByRole("button", { name: "Open" });
200+
201+
await user.click(autoCompleteDropdown);
202+
203+
expect(screen.getByText("Attack on hospitals")).toBeInTheDocument();
204+
expect(screen.getByText("Other")).toBeInTheDocument();
205+
});
206+
});
117207
});

app/javascript/components/record-form/form/subforms/subform-dialog-fields/component.unit.test.js

-254
This file was deleted.

app/javascript/components/record-form/form/subforms/subform-field-subform/component.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const Component = ({ isViolation, parentTitle, parentValues, fieldProps, violati
2323
setExpanded(!expanded);
2424
};
2525
const renderSubform = (
26-
<div className={css.subFormField}>
26+
<div className={css.subFormField} data-testid="subform-field">
2727
<SubformField
2828
{...{
2929
...fieldProps,

0 commit comments

Comments
 (0)