Skip to content

Commit

Permalink
Refactor getter 'getAnnotationComponent' (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmoza authored Feb 6, 2023
1 parent f0bb666 commit a5e35f0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 3 deletions.
59 changes: 59 additions & 0 deletions cypress/unit/store-getter-getAnnotationComponent.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { getters } from "~/store";

describe("The getAnnotationComponent getter", () => {

let store = {};

beforeEach(() => {

store = {

state: {

categories: {

"Subject ID": {},
"Age": {

componentName: "annot-continuous-values"
},
"Sex": {

componentName: "annot-categorical"
},
"Diagnosis": {

componentName: "annot-categorical"
}
}
}
};
});

it("Get the component name for the 'Age' category", () => {

// Act
const componentName = getters.getAnnotationComponent(store.state)("Age");

// Assert
expect(componentName).to.equal("annot-continuous-values");
});

it("Get the component name for the 'Sex' category", () => {

// Act
const componentName = getters.getAnnotationComponent(store.state)("Sex");

// Assert
expect(componentName).to.equal("annot-categorical");
});

it("Get the component name for the 'Diagnosis' category", () => {

// Act
const componentName = getters.getAnnotationComponent(store.state)("Diagnosis");

// Assert
expect(componentName).to.equal("annot-categorical");
});
});
20 changes: 17 additions & 3 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ export const state = () => ({
categories: {

"Subject ID": {},
"Age": {},
"Sex": {},
"Diagnosis": {}
"Age": {

componentName: "annot-continuous-values"
},
"Sex": {

componentName: "annot-categorical"
},
"Diagnosis": {

componentName: "annot-categorical"
}
},

colorInfo: {
Expand Down Expand Up @@ -91,6 +100,11 @@ export const state = () => ({

export const getters = {

getAnnotationComponent: (p_state) => (p_category) => {

return p_state.categories[p_category].componentName;
},

getCategoryNames (p_state) {


Expand Down

0 comments on commit a5e35f0

Please sign in to comment.