Skip to content

Commit 4854e28

Browse files
Merge pull request #463 from primeroIMS/trigyn-testcase-form
Trigyn testcase form
2 parents d0c4f43 + 9bfc411 commit 4854e28

Some content is hidden

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

42 files changed

+645
-941
lines changed

app/javascript/components/flagging/components/dialog-tabs/component.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ describe("<DialogTabs /> - Component", () => {
1515
});
1616

1717
it("should render the DialogTabs", () => {
18-
screen.debug();
1918
expect(screen.getByText("flags.flags_tab")).toBeInTheDocument();
2019
expect(screen.getByText("flags.add_flag_tab")).toBeInTheDocument();
2120
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { screen, mountedComponent, spy } from "test-utils";
2+
import { fromJS } from "immutable";
3+
import { object, string } from "yup";
4+
5+
import Form from "./component";
6+
import { FORM_MODE_DIALOG } from "./constants";
7+
import { FormSectionRecord, FieldRecord } from "./records";
8+
9+
describe("<Form>", () => {
10+
const formSubmit = spy();
11+
const FORM_ID = "test-form";
12+
13+
const formSections = fromJS([
14+
FormSectionRecord({
15+
unique_id: "notes_section",
16+
fields: [
17+
FieldRecord({
18+
display_name: "Test Field 1",
19+
name: "test_field_1",
20+
type: "text_field"
21+
}),
22+
FieldRecord({
23+
display_name: "Test Field 2",
24+
name: "test_field_2",
25+
type: "textarea"
26+
})
27+
]
28+
})
29+
]);
30+
31+
const props = {
32+
formSections,
33+
mode: FORM_MODE_DIALOG,
34+
onSubmit: formSubmit,
35+
validations: object().shape({
36+
test_field_1: string().required()
37+
}),
38+
formID: FORM_ID
39+
};
40+
41+
it("renders form based on formSection props", () => {
42+
mountedComponent(<Form {...props} />);
43+
expect(screen.getAllByText("Test Field 1")).toBeTruthy();
44+
expect(screen.getAllByText("Test Field 2")).toBeTruthy();
45+
});
46+
47+
it.todo("should set form with initial values");
48+
49+
it.todo("should not submit form when invalid");
50+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved.
2+
import { screen, mountedFormComponent } from "test-utils";
3+
import { DragDropContext, Droppable } from "react-beautiful-dnd";
4+
5+
import DraggableOption from "./component";
6+
7+
describe("<Form /> - components/<DraggableOption />", () => {
8+
beforeEach(() => {
9+
// eslint-disable-next-line react/display-name
10+
const Component = props => (
11+
<DragDropContext>
12+
<Droppable droppableId="droppable" type="field">
13+
{() => (
14+
<DraggableOption
15+
name="field_1"
16+
index={0}
17+
option={{ id: "option_1", display_text: "Display text 1", disabled: false }}
18+
defaultOptionId="option_1"
19+
{...props}
20+
/>
21+
)}
22+
</Droppable>
23+
</DragDropContext>
24+
);
25+
26+
mountedFormComponent(<Component mode="edit" />);
27+
});
28+
29+
it("renders a TextInput for display_text", () => {
30+
expect(document.querySelector("input[name='field_1.option_strings_text[0].display_text.en'")).toBeInTheDocument();
31+
});
32+
33+
it("renders a SwitchInput", () => {
34+
expect(screen.getByTestId("switch-input")).toBeInTheDocument();
35+
});
36+
});

app/javascript/components/form/components/draggable-option/component.unit.test.js

-57
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { screen, mountedFormComponent } from "test-utils";
2+
3+
import FormAction from "./form-action";
4+
5+
describe("<Form /> - components/<FormAction />", () => {
6+
const buttonMessage = "Test save";
7+
const props = {
8+
actionHandler: () => {},
9+
text: buttonMessage
10+
};
11+
12+
it("renders a Fab component", () => {
13+
mountedFormComponent(<FormAction {...props} />);
14+
expect(screen.getByRole("button")).toBeInTheDocument();
15+
expect(screen.getByText(buttonMessage)).toBeInTheDocument();
16+
});
17+
});

app/javascript/components/form/components/form-action.unit.test.js

-43
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { screen, mountedFormComponent } from "test-utils";
2+
import { fromJS } from "immutable";
3+
4+
import { FieldRecord } from "../records";
5+
import { RADIO_FIELD, DIALOG_TRIGGER, DOCUMENT_FIELD } from "../constants";
6+
7+
import FormSectionField from "./form-section-field";
8+
9+
describe("<Form /> - components/<FormSectionField />", () => {
10+
it("renders a text field", () => {
11+
const field = FieldRecord({ name: "test_field", type: "text_field" });
12+
13+
mountedFormComponent(<FormSectionField field={field} />);
14+
expect(document.querySelector("#test_field")).toBeInTheDocument();
15+
});
16+
17+
it("renders an error field", () => {
18+
const field = FieldRecord({ name: "test_field", type: "error_field" });
19+
20+
// eslint-disable-next-line react/display-name
21+
const Component = props => {
22+
return <FormSectionField {...props} field={field} checkErrors={fromJS(["name"])} formMode={fromJS({})} />;
23+
};
24+
25+
mountedFormComponent(<Component />, {
26+
errors: [
27+
{
28+
name: "name",
29+
message: "test-error"
30+
}
31+
]
32+
});
33+
expect(screen.getByText("test-error")).toBeInTheDocument();
34+
});
35+
36+
it("renders a radio button field", () => {
37+
const field = FieldRecord({
38+
name: "radio_test_field",
39+
id: "radio_test_field",
40+
type: RADIO_FIELD,
41+
option_strings_text: {
42+
en: [
43+
{
44+
id: "yes",
45+
label: "Yes"
46+
},
47+
{
48+
id: "no",
49+
label: "No"
50+
}
51+
]
52+
}
53+
});
54+
55+
mountedFormComponent(<FormSectionField field={field} />);
56+
expect(document.querySelector("#radio_test_field")).toBeInTheDocument();
57+
});
58+
59+
it("renders a buttons link", () => {
60+
const field = FieldRecord({ name: "test_field", type: DIALOG_TRIGGER, display_name: { en: "Test Field" } });
61+
62+
mountedFormComponent(<FormSectionField field={field} />);
63+
expect(screen.getByText("Test Field")).toBeInTheDocument();
64+
});
65+
66+
it("renders an attachement field", () => {
67+
const field = FieldRecord({ name: "test_document_field", type: DOCUMENT_FIELD });
68+
69+
mountedFormComponent(<FormSectionField field={field} />);
70+
expect(document.querySelector("#test_document_field")).toBeInTheDocument();
71+
});
72+
});

app/javascript/components/form/components/form-section-field.unit.test.js

-108
This file was deleted.

0 commit comments

Comments
 (0)