From 3cf91bfad5970b81ebffe51aca81b9f07e66c80b Mon Sep 17 00:00:00 2001 From: Sebastian Urchs Date: Mon, 13 Nov 2023 09:02:33 -0500 Subject: [PATCH] [FIX] read value description from user dictionary correctly (#623) * Fix case sensitive attribute access to description * Fix reading description from user dictionary --- cypress/fixtures/examples/good/example.json | 4 ++-- .../store-getter-getValueDescription.cy.js | 18 +++++++----------- store/index.js | 4 ++-- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/cypress/fixtures/examples/good/example.json b/cypress/fixtures/examples/good/example.json index df6d885c..61a584fe 100644 --- a/cypress/fixtures/examples/good/example.json +++ b/cypress/fixtures/examples/good/example.json @@ -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": { diff --git a/cypress/unit/store-getter-getValueDescription.cy.js b/cypress/unit/store-getter-getValueDescription.cy.js index 649ffc06..6aa0ecd1 100644 --- a/cypress/unit/store-getter-getValueDescription.cy.js +++ b/cypress/unit/store-getter-getValueDescription.cy.js @@ -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": { @@ -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"); }); }); \ No newline at end of file diff --git a/store/index.js b/store/index.js index aa93e7a0..1e14964e 100644 --- a/store/index.js +++ b/store/index.js @@ -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; },