diff --git a/cypress/unit/store-getter-getUniqueValues.cy.js b/cypress/unit/store-getter-getUniqueValues.cy.js index 5858a360..6220a508 100644 --- a/cypress/unit/store-getter-getUniqueValues.cy.js +++ b/cypress/unit/store-getter-getUniqueValues.cy.js @@ -1,47 +1,57 @@ import { getters } from "~/store"; let store; +let state; describe("getUniqueValues getter", () => { beforeEach(() => { + state = { - store = { + columnToCategoryMap: { + column1: "Diagnosis", + column2: "Age", + column3: "Sex" + }, - state: { + dataDictionary: { - columnToCategoryMap: { + annotated: { - column1: "Diagnosis", - column2: "Age", - column3: "Sex" - }, + column1: { missingValues: [] }, + column2: { missingValues: [] }, + column3: { missingValues: ["column3_value1", "column3_value2"] } + } + }, - dataDictionary: { + dataTable: [ - annotated: { + { column1: 1, column2: "column2_value1", column3: "column3_value1" }, + { column1: 2, column2: "column2_value2", column3: "column3_value2" }, + { column1: 1, column2: "column2_value3", column3: "column3_value3" }, + { column1: 3, column2: "column2_value2", column3: "column3_value4" } + ] + }; - column1: { missingValues: [] }, - column2: { missingValues: [] }, - column3: { missingValues: ["column3_value1", "column3_value2"] } - } - }, + store = { + getters: { + // getColumnsForCategory: () => (p_category) => { + // return ["column1", "column2", "column3"]; + // }, + getColumnsForCategory: getters.getColumnsForCategory(state), - dataTable: [ + getUniqueColumnValues: getters.getUniqueColumnValues(state) + }, - { column1: 1, column2: "column2_value1", column3: "column3_value1" }, - { column1: 2, column2: "column2_value2", column3: "column3_value2" }, - { column1: 1, column2: "column2_value3", column3: "column3_value3" }, - { column1: 3, column2: "column2_value2", column3: "column3_value4" } - ] - } - }; - }); + state: state + }; + } + ); it("Retrieves unique values of a single column", () => { // Act - const diagnosisUniqueValues = getters.getUniqueValues(store.state)("Diagnosis"); + const diagnosisUniqueValues = getters.getUniqueValues(store.state, store.getters)("Diagnosis"); // Assert expect(diagnosisUniqueValues).to.deep.equal({ "column1": [1, 2, 3] }); @@ -50,10 +60,11 @@ describe("getUniqueValues getter", () => { it("Retrieves unique values of a multiple columns", () => { // Setup + // We change the state by reference because the state passed to the getters needs to reflect that change store.state.columnToCategoryMap.column2 = "Diagnosis"; // Act - const diagnosisUniqueValues = getters.getUniqueValues(store.state)("Diagnosis"); + const diagnosisUniqueValues = getters.getUniqueValues(store.state, store.getters)("Diagnosis"); // Assert expect(diagnosisUniqueValues).to.deep.equal({ @@ -66,7 +77,7 @@ describe("getUniqueValues getter", () => { it("Retrieve unique value list of maximum length", () => { // Act - const diagnosisUniqueValues = getters.getUniqueValues(store.state)("Diagnosis", 2); + const diagnosisUniqueValues = getters.getUniqueValues(store.state, store.getters)("Diagnosis", 2); // Assert expect(diagnosisUniqueValues).to.deep.equal({ "column1": [1, 2]}); @@ -75,7 +86,7 @@ describe("getUniqueValues getter", () => { it("Make sure no missing values are included in unique values", () => { // Act - const diagnosisUniqueValues = getters.getUniqueValues(store.state)("Sex"); + const diagnosisUniqueValues = getters.getUniqueValues(store.state, store.getters)("Sex"); // Assert expect(diagnosisUniqueValues).to.deep.equal({ "column3": ["column3_value3", "column3_value4"]}); diff --git a/store/index.js b/store/index.js index 7543f503..2c254499 100644 --- a/store/index.js +++ b/store/index.js @@ -560,7 +560,7 @@ export const getters = { return columns; }, - getUniqueColumnValues: (p_state, p_getters) => (columnName, p_maxValues="None") => { + getUniqueColumnValues: (p_state) => (columnName, p_maxValues="None") => { let uniqueColumnValues = new Set(); for ( let index = 0; index < p_state.dataTable.length; index++ ) { @@ -591,7 +591,7 @@ export const getters = { const columns = p_getters.getColumnsForCategory(p_category); const uniqueValues = {}; for (const column of columns) { - uniqueValues[column] = p_getters.getUniqueColumnValues(column); + uniqueValues[column] = p_getters.getUniqueColumnValues(column, p_maxValues); } return uniqueValues; },