Skip to content

Commit

Permalink
Implemented getColumnNames getter
Browse files Browse the repository at this point in the history
- Implemented getColumnNames getter in refactored store
- Implemented unit test for getColumnNames getter
- Updated components dependent on getColumnNames
  • Loading branch information
rmanaem authored Jan 5, 2023
1 parent b01dd2e commit bd1868d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
6 changes: 3 additions & 3 deletions components/column-linking-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@
...mapGetters([
"categoryClasses",
"columns",
"getColumnNames",
"getColumnDescription",
"columnToCategoryMap"
]),
tableRows() {
return this.columns.map(column => ({
return this.getColumnNames.map(column => ({
category: this.columnToCategoryMap[column],
column: column.name,
column: column,
description: this.getColumnDescription(column.name)
}));
}
Expand Down
11 changes: 5 additions & 6 deletions cypress/component/column-linking-table.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ describe("The column-linking-table component", () => {
};
},

columns: () => {
getColumnNames: () => {

return [

{ name: "participant_id" },
{ name: "age" },
{ name: "sex" }
"participant_id",
"age",
"sex"
];
},

Expand Down Expand Up @@ -98,7 +97,7 @@ describe("The column-linking-table component", () => {
it("can alter link relation (add/remove) between a column and a category", () => {

// 0. The first category and column
const participantIDColumn = store.getters.columns()[0].name;
const participantIDColumn = store.getters.getColumnNames()[0];
const subjectIDCategory = store.getters.categories()[0];

// 1. Arrange - Set up the spy, mount the component, and bind the spy to it
Expand Down
19 changes: 19 additions & 0 deletions cypress/unit/store-getter-getColumnNames.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getters } from "~/store/index-refactor";

describe("getColumnNames", () => {
it("Returns an array of all column names in the data table", () => {
const { getColumnNames } = getters;
const state = {
dataTable: [
{
"column1": "value1", "column2": "value2"
},
{
"column1": "value3", "column2": "value4"
}
]
};
const columnNames = getColumnNames(state);
expect(columnNames).to.deep.equal(["column1", "column2"]);
});
});
5 changes: 5 additions & 0 deletions store/index-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export const getters = {
return "";
}
return description;
},

getColumnNames(p_state) {
return (0 === p_state.dataTable.length) ? [] : Object.keys(p_state.dataTable[0]);
}

};


Expand Down

0 comments on commit bd1868d

Please sign in to comment.