Skip to content

Commit

Permalink
R2-2640 - National ID of last case appears on next case you click
Browse files Browse the repository at this point in the history
  • Loading branch information
aespinoza-quoin committed Oct 9, 2023
1 parent ba2ae5b commit 8c4d0db
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/javascript/components/record-form/form/record-form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ const RecordForm = ({
const redirectToIncident = RECORD_TYPES.cases === recordType ? { redirectToIncident: false } : {};

if (record) {
const recordFormValues = { ...initialValues, ...record.toJS(), ...redirectToIncident };
const recordFormValues = {
...(mode.isNew ? constructInitialValues(forms.values()) : {}),
...record.toJS(),
...redirectToIncident
};

const subformValues = sortSubformValues(recordFormValues, forms.values());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TextField as MuiTextField } from "formik-material-ui";

import { NUMERIC_FIELD } from "../constants";
import { getRecordForms } from "../selectors";
import { RECORD_TYPES } from "../../../config";
import { RECORD_TYPES, CASES } from "../../../config";
import { setupMountedComponent, stub } from "../../../test";
import { FieldRecord, FormSectionRecord } from "../records";

Expand Down Expand Up @@ -306,6 +306,86 @@ describe("<RecordForm />", () => {
});
});

describe("when an record exists", () => {
const initialStateRecordExists = Map({
forms: Map({
formSections: Map({
1: FormSectionRecord({
id: 1,
name: {
en: "Form Section 1"
},
unique_id: "form_section_1",
module_ids: ["some_module"],
visible: true,
is_nested: false,
parent_form: RECORD_TYPES.cases,
fields: [1, 2, 3]
})
}),
fields: Map({
1: FieldRecord({
id: 1,
name: "field_1",
display_name: {
en: "Field 1"
},
type: TEXT_FIELD_NAME,
required: true,
visible: true
}),
2: FieldRecord({
id: 2,
name: "field_2",
display_name: {
en: "Field 2"
},
type: TEXT_FIELD_NAME,
visible: true,
selected_value: "field_2_value"
}),
3: FieldRecord({
id: 3,
name: "field_age",
display_name: {
en: "Field Age"
},
type: NUMERIC_FIELD,
visible: true
})
})
})
});
const queryRecordExists = {
recordType: RECORD_TYPES.cases,
primeroModule: "some_module"
};
const formsRecordsEdit = getRecordForms(initialStateRecordExists, queryRecordExists);

const recordValues = { age: "4", name_first: "test" };

it("should set the values for the case selected", () => {
const { component: fromCaseComponent } = setupMountedComponent(RecordForm, {
bindSubmitForm: () => {},
forms: formsRecordsEdit,
handleToggleNav: () => {},
mobileDisplay: false,
mode: { isNew: false, isEdit: true, isShow: false },
onSubmit: () => {},
record: fromJS(recordValues),
recordType: CASES,
selectedForm: "form_section_1",
incidentFromCase: {},
externalComponents: () => {},
setFormikValuesForNav: () => {}
});

expect(fromCaseComponent.find(FormikForm).props().values).to.deep.equal({
...recordValues
});
});
});

it("renders component with valid props", () => {
const incidentsProps = { ...component.find(RecordForm).props() };

Expand Down

0 comments on commit 8c4d0db

Please sign in to comment.