Skip to content

Commit eeba7dc

Browse files
Merge pull request #458 from primeroIMS/trigyn-testcases-record-form-form-field-types
Trigyn testcases record form form field types
2 parents 5a773c9 + fe2c44a commit eeba7dc

20 files changed

+826
-1110
lines changed

app/javascript/components/record-form/form/field-types/date-field-picker.jsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,15 @@ const DateFieldPicker = ({ dateIncludeTime, dateProps, displayName, fieldTouched
3030
return (
3131
<MuiPickersUtilsProvider utils={DateFnsUtils} locale={localize(i18n)}>
3232
{dateIncludeTime ? (
33-
<DateTimePicker {...dialogLabels} {...dateProps} helperText={helpText} label={label} />
33+
<DateTimePicker
34+
data-testid="date-time-picker"
35+
{...dialogLabels}
36+
{...dateProps}
37+
helperText={helpText}
38+
label={label}
39+
/>
3440
) : (
35-
<DatePicker {...dialogLabels} {...dateProps} helperText={helpText} label={label} />
41+
<DatePicker data-testid="date-picker" {...dialogLabels} {...dateProps} helperText={helpText} label={label} />
3642
)}
3743
</MuiPickersUtilsProvider>
3844
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { mountedComponent, screen } from "../../../../test-utils";
2+
3+
import DateFieldPicker from "./date-field-picker";
4+
5+
describe("<DateFieldPicker />", () => {
6+
const formProps = {
7+
initialValues: {
8+
date_field_picker: ""
9+
}
10+
};
11+
12+
const props = {
13+
dateIncludeTime: true,
14+
dateProps: {},
15+
displayName: { en: "Date Test" },
16+
fieldTouched: false,
17+
fieldError: "",
18+
helperText: ""
19+
};
20+
21+
describe("when dateIncludeTime is true", () => {
22+
it("should a DateTimePicker component", () => {
23+
mountedComponent(<DateFieldPicker {...props} />, {}, [], {}, formProps);
24+
expect(screen.getByTestId("date-time-picker")).toBeInTheDocument();
25+
});
26+
27+
it("should render the correct helpText", () => {
28+
mountedComponent(<DateFieldPicker {...props} />, {}, [], {}, formProps);
29+
expect(screen.getByText("fields.date_help_with_time")).toBeInTheDocument();
30+
});
31+
});
32+
33+
describe("when dateIncludeTime is false", () => {
34+
const dateIncludeProp = {
35+
...props,
36+
dateIncludeTime: false
37+
};
38+
39+
it("should a DatePicker component", () => {
40+
mountedComponent(<DateFieldPicker {...dateIncludeProp} />, {}, [], {}, formProps);
41+
expect(screen.getByTestId("date-picker")).toBeInTheDocument();
42+
});
43+
44+
it("should render the correct helpText", () => {
45+
mountedComponent(<DateFieldPicker {...dateIncludeProp} />, {}, [], {}, formProps);
46+
expect(screen.getByText("fields.date_help")).toBeInTheDocument();
47+
});
48+
});
49+
50+
describe("when ne locale", () => {
51+
it("renders Nepali date picker if locale ne", () => {
52+
global.I18n.locale = "ne";
53+
mountedComponent(<DateFieldPicker {...props} />, {}, [], {}, formProps);
54+
expect(screen.getByTestId("nepali-container")).toBeInTheDocument();
55+
});
56+
});
57+
});

app/javascript/components/record-form/form/field-types/date-field-picker.unit.test.js

-74
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { DEFAULT_DATE_VALUES } from "../../../../config";
2+
import { fireEvent, mountedComponent, screen, setScreenSizeToMobile, waitFor } from "../../../../test-utils";
3+
import { DATE_FIELD } from "../../../form";
4+
import { FieldRecord } from "../../records";
5+
6+
import DateField from "./date-field";
7+
8+
describe("<DateField />", () => {
9+
setScreenSizeToMobile(false);
10+
11+
describe("when is date of birth field", () => {
12+
const props = {
13+
field: FieldRecord({
14+
name: "date_of_birth",
15+
type: DATE_FIELD,
16+
display_name_en: "Text test field"
17+
}),
18+
formik: {
19+
values: []
20+
},
21+
label: "Date of birth",
22+
mode: {
23+
isShow: false,
24+
isEdit: true
25+
},
26+
name: "date_of_birth"
27+
};
28+
29+
describe.skip("and the age field is visible", () => {
30+
const formProps = { initialValues: { date_of_birth: null } };
31+
32+
const ageProsp = { ...props, formSection: { fields: [{ name: "age", visible: true }] } };
33+
34+
it("should set the age field", () => {
35+
mountedComponent(<DateField {...ageProsp} />, {}, [], {}, formProps);
36+
expect(screen.getByRole("textbox")).toBeInTheDocument();
37+
});
38+
});
39+
40+
describe.skip("and the age field is not visible", () => {
41+
const formProps = { initialValues: { date_of_birth: null } };
42+
43+
it("should not set the age field", () => {
44+
mountedComponent(<DateField {...props} />, {}, [], {}, formProps);
45+
expect(screen.getByRole("textbox")).toBeInTheDocument();
46+
});
47+
});
48+
});
49+
50+
describe.skip("when is date field with a default value", () => {
51+
const props = {
52+
field: FieldRecord({
53+
name: "date_of_interview",
54+
type: DATE_FIELD,
55+
display_name_en: "Date of Interview",
56+
selected_value: DEFAULT_DATE_VALUES.TODAY
57+
}),
58+
formik: {
59+
values: []
60+
},
61+
label: "Date of Interview",
62+
name: "date_of_interview"
63+
};
64+
65+
const formProps = { initialValues: {} };
66+
67+
const modeProps = {
68+
...props,
69+
mode: { isNew: true }
70+
};
71+
72+
it("sets the date default value as string if the mode is new", () => {
73+
mountedComponent(<DateField {...modeProps} />, {}, [], {}, formProps);
74+
expect(screen.getByRole("textbox")).toBeInTheDocument();
75+
});
76+
77+
it("sets the datetime default value as string if the mode is new", () => {
78+
const newProps = {
79+
...props,
80+
field: FieldRecord({
81+
name: "date_of_interview",
82+
type: DATE_FIELD,
83+
display_name_en: "Date of Interview",
84+
selected_value: DEFAULT_DATE_VALUES.TODAY,
85+
date_include_time: true
86+
}),
87+
mode: { isNew: true }
88+
};
89+
90+
mountedComponent(<DateField {...newProps} />, {}, [], {}, formProps);
91+
expect(screen.getByRole("textbox")).toBeInTheDocument();
92+
});
93+
94+
it("should clear the current value if the mode is new and the clear button is clicked", async () => {
95+
const clearProps = {
96+
...props,
97+
mode: { isNew: true }
98+
};
99+
100+
mountedComponent(<DateField {...clearProps} />, {}, [], {}, formProps);
101+
fireEvent.click(screen.getByRole("textbox"));
102+
await fireEvent.click(screen.getByText("buttons.clear").closest("button"));
103+
await waitFor(() => expect(screen.getByRole("textbox").value).toBe(""));
104+
});
105+
106+
it("should not set the default value if the mode is not new", () => {
107+
const notNewProps = {
108+
...props,
109+
mode: { isEdit: true }
110+
};
111+
112+
mountedComponent(<DateField {...notNewProps} />, {}, [], {}, formProps);
113+
expect(screen.getByRole("textbox")).toBeInTheDocument();
114+
});
115+
});
116+
});

0 commit comments

Comments
 (0)