-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in R2-3132-case-incident-error (pull request #7001)
R2-3132: Fixing issue where incorrect violence type field is selected for case to incident form
- Loading branch information
Showing
3 changed files
with
60 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
app/javascript/components/incidents-from-case/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved. | ||
|
||
/* eslint-disable import/prefer-default-export */ | ||
import { MODULES } from "../../config"; | ||
import { selectModule } from "../application"; | ||
|
||
import { CP_VIOLENCE_TYPE, GBV_VIOLENCE_TYPE } from "./components/panel/constants"; | ||
|
||
function getViolenceType(state, moduleID) { | ||
const defaultModule = moduleID === MODULES.GBV ? GBV_VIOLENCE_TYPE : CP_VIOLENCE_TYPE; | ||
const selectedModule = selectModule(state, moduleID); | ||
|
||
return selectedModule.getIn(["options", "violation_type_field"], defaultModule); | ||
} | ||
|
||
export { getViolenceType }; |
42 changes: 42 additions & 0 deletions
42
app/javascript/components/incidents-from-case/selectors.unit.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2014 - 2023 UNICEF. All rights reserved. | ||
|
||
import { fromJS } from "immutable"; | ||
|
||
import { PrimeroModuleRecord } from "../application/records"; | ||
import { MODULES } from "../../config"; | ||
|
||
import { getViolenceType } from "./selectors"; | ||
import { CP_VIOLENCE_TYPE, GBV_VIOLENCE_TYPE } from "./components/panel/constants"; | ||
|
||
const state = fromJS({ | ||
user: { | ||
modules: ["test1"] | ||
}, | ||
application: { | ||
modules: [ | ||
PrimeroModuleRecord({ unique_id: "test1", options: { violation_type_field: "test1_violence_type_field_id" } }) | ||
] | ||
} | ||
}); | ||
|
||
describe("<IncidentFromCase /> - Selectors", () => { | ||
describe("getViolenceType", () => { | ||
it("should return violence type field id from store", () => { | ||
const violenceType = getViolenceType(state, "test1"); | ||
|
||
expect(violenceType).to.deep.equal("test1_violence_type_field_id"); | ||
}); | ||
|
||
it("should return violence type field id from store", () => { | ||
const violenceType = getViolenceType(state, MODULES.CP); | ||
|
||
expect(violenceType).to.deep.equal(CP_VIOLENCE_TYPE); | ||
}); | ||
|
||
it("should return violence type field id from store", () => { | ||
const violenceType = getViolenceType(state, MODULES.GBV); | ||
|
||
expect(violenceType).to.deep.equal(GBV_VIOLENCE_TYPE); | ||
}); | ||
}); | ||
}); |