Skip to content

Commit

Permalink
[FIX] read value description from user dictionary correctly (#623)
Browse files Browse the repository at this point in the history
* Fix case sensitive attribute access to description

* Fix reading description from user dictionary
  • Loading branch information
surchs authored Nov 13, 2023
1 parent 1161c37 commit 3cf91bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions cypress/fixtures/examples/good/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"sex": {
"Description": "sex of the participant as reported by the participant",
"Levels": {
"M": "male",
"F": "female"
"1": "male",
"2": "female"
}
},
"group": {
Expand Down
18 changes: 7 additions & 11 deletions cypress/unit/store-getter-getValueDescription.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ const state = {
dataDictionary: {
annotated: {
"goodColumn": {
"levels": {
"value1": {
"description": "my description"
},
"value2": {
"description": "my other description"
"Levels": {
"value1": "my description",
"value2": "my other description"
}
}
},
"levelsButNothingElse": {
"levels": {
"Levels": {
}
},
"badColumn": {
Expand All @@ -33,12 +29,12 @@ describe("getValueDescription", () => {
expect(result).to.be.equal("my description");
});

it("Returns an empty string if the value does not have a description", () => {
it("Returns 'no description available' if the value does not have a description", () => {

const resultNoValue = getters.getValueDescription(state)("levelsButNothingElse", "notExistValue");
expect(resultNoValue).to.be.empty;
expect(resultNoValue).to.be.equal("no description available");

const resultNoLevels = getters.getValueDescription(state)("badColumn", "notExistValue");
expect(resultNoLevels).to.be.empty;
expect(resultNoLevels).to.be.equal("no description available");
});
});
4 changes: 2 additions & 2 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ export const getters = {
getValueDescription: (p_state) => (p_columnName, p_value) => {
// Returns the description of a value in a column, if that description exists
// Otherwise it returns an empty string
const description = p_state.dataDictionary.annotated[p_columnName].levels?.[p_value]?.description;
const description = p_state.dataDictionary.annotated[p_columnName].Levels?.[p_value];
if ( typeof description === "undefined" ) {
return "";
return "no description available";
}
return description;
},
Expand Down

0 comments on commit 3cf91bf

Please sign in to comment.