From d5d2f03371f73d8851edfc99e807ae49fb8d433e Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Wed, 11 Jan 2023 10:43:21 -0600 Subject: [PATCH 1/9] feat(gwasUnifiedFlowOutcomeCard): initial commit --- .../GWASV2/Components/Covariates/Covariates.css | 6 ++++-- .../Covariates/CovariatesCardsList.jsx | 17 +++++++++++++++-- .../Steps/SelectCovariates/SelectCovariates.jsx | 11 +++++++---- .../Steps/SelectOutcome/SelectOutcome.jsx | 11 +++++++---- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/Analysis/GWASV2/Components/Covariates/Covariates.css b/src/Analysis/GWASV2/Components/Covariates/Covariates.css index 2974e0740f..086f89d65c 100644 --- a/src/Analysis/GWASV2/Components/Covariates/Covariates.css +++ b/src/Analysis/GWASV2/Components/Covariates/Covariates.css @@ -11,13 +11,15 @@ margin-top: 8px; } +.GWASV2 .outcome-card { + background: #cae6f1; +} + .GWASV2 .dichotomous-card { - width: 189px; background: #ebfad3; } .GWASV2 .continuous-card { - width: 189px; background: #fde3d6; } diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx index d9fd428448..90a631673a 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx @@ -5,8 +5,16 @@ import { Card } from 'antd'; const { Meta } = Card; -const CovariatesCardsList = ({ covariates, deleteCovariate }) => ( +const CovariatesCardsList = ({ covariates, outcome, deleteCovariate }) => (
+ {outcome && ( + + + + )} {covariates.map((covariate, key) => ( {covariate.provided_name && ( @@ -53,8 +61,13 @@ const CovariatesCardsList = ({ covariates, deleteCovariate }) => ( ); CovariatesCardsList.propTypes = { - covariates: PropTypes.array.isRequired, + covariates: PropTypes.array, + outcome: PropTypes.object, deleteCovariate: PropTypes.func.isRequired, }; +CovariatesCardsList.defaultProps = { + outcome: null, + covariates: [], +}; export default CovariatesCardsList; diff --git a/src/Analysis/GWASV2/Steps/SelectCovariates/SelectCovariates.jsx b/src/Analysis/GWASV2/Steps/SelectCovariates/SelectCovariates.jsx index 45089d64fc..75eeb3b4c7 100644 --- a/src/Analysis/GWASV2/Steps/SelectCovariates/SelectCovariates.jsx +++ b/src/Analysis/GWASV2/Steps/SelectCovariates/SelectCovariates.jsx @@ -82,10 +82,13 @@ const SelectCovariates = ({
dispatch({ - type: ACTIONS.DELETE_COVARIATE, - payload: chosenCovariate, - })} + outcome={outcome} + deleteCovariate={(chosenCovariate) => + dispatch({ + type: ACTIONS.DELETE_COVARIATE, + payload: chosenCovariate, + }) + } />
diff --git a/src/Analysis/GWASV2/Steps/SelectOutcome/SelectOutcome.jsx b/src/Analysis/GWASV2/Steps/SelectOutcome/SelectOutcome.jsx index 8e0edc3b83..ef5fbf390a 100644 --- a/src/Analysis/GWASV2/Steps/SelectOutcome/SelectOutcome.jsx +++ b/src/Analysis/GWASV2/Steps/SelectOutcome/SelectOutcome.jsx @@ -76,10 +76,13 @@ const SelectOutcome = ({
dispatch({ - type: ACTIONS.DELETE_COVARIATE, - payload: chosenCovariate, - })} + outcome={outcome} + deleteCovariate={(chosenCovariate) => + dispatch({ + type: ACTIONS.DELETE_COVARIATE, + payload: chosenCovariate, + }) + } />
From c74838fd626143dba3c01188308edb88673185b7 Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Thu, 12 Jan 2023 11:15:47 -0600 Subject: [PATCH 2/9] feat(gwasUnifiedFlowOutcomeCard): Added unit test for CovariatesCard.js --- .../Covariates/CovariatesCardList.test.js | 74 +++++++++++++++++++ .../Covariates/CovariatesCardsList.jsx | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.js diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.js b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.js new file mode 100644 index 0000000000..37e9612220 --- /dev/null +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.js @@ -0,0 +1,74 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import { DeleteOutlined } from '@ant-design/icons'; +import { Card } from 'antd'; +import CovariatesCardsList from './CovariatesCardsList'; + +describe('CovariatesCardsList component', () => { + let wrapper; + let mockDeleteCovariate; + + beforeEach(() => { + mockDeleteCovariate = jest.fn(); + + const mockProps = { + outcome: { provided_name: 'test outcome' }, + covariates: [ + { provided_name: 'test dichotomous covariate', concept_id: null }, + { concept_name: 'test continuous covariate', concept_id: '123' }, + ], + deleteCovariate: mockDeleteCovariate, + }; + + wrapper = mount(); + console.log(wrapper.debug()); + }); + + it('should render an outcome card', () => { + expect(wrapper.find('.outcome-card').exists()).toBe(true); + expect(wrapper.find('.outcome-card .ant-card-meta-title').text()).toBe( + 'Outcome' + ); + expect( + wrapper.find('.outcome-card .ant-card-meta-description').text() + ).toBe('test outcome'); + }); + + it('should render two covariate cards', () => { + expect(wrapper.find('.dichotomous-card').exists()).toBe(true); + expect(wrapper.find('.dichotomous-card .ant-card-meta-title').text()).toBe( + 'Dichotomous Covariate' + ); + expect( + wrapper.find('.dichotomous-card .ant-card-meta-description').text() + ).toBe('test dichotomous covariate'); + + expect(wrapper.find('.continuous-card').exists()).toBe(true); + expect(wrapper.find('.continuous-card .ant-card-meta-title').text()).toBe( + 'Continuous Covariate' + ); + expect( + wrapper.find('.continuous-card .ant-card-meta-description').text() + ).toBe('test continuous covariate'); + }); + + it('should call deleteCovariate when the delete icon is clicked', () => { + wrapper + .find(DeleteOutlined) + .first() + .simulate('click'); + expect(mockDeleteCovariate).toHaveBeenCalledWith({ + provided_name: 'test dichotomous covariate', + concept_id: null, + }); + + wrapper + .find(DeleteOutlined) + .last() + .simulate('click'); + expect(mockDeleteCovariate).toHaveBeenCalledWith({ + concept_name: 'test continuous covariate', + concept_id: '123', + }); + }); +}); diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx index 90a631673a..a47faff564 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx @@ -10,7 +10,7 @@ const CovariatesCardsList = ({ covariates, outcome, deleteCovariate }) => ( {outcome && ( From d58ff2c91528045c27e6a5c6be4e43f75321d61e Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Fri, 13 Jan 2023 08:35:52 -0600 Subject: [PATCH 3/9] feat(gwasUnifiedFlowOutcomeCard): Updated test to use ValidInitialState data for outcome and updated CovariatesCardList keys to use covariate obj --- ...st.test.js => CovariatesCardList.test.jsx} | 43 ++++++++++++------- .../Covariates/CovariatesCardsList.jsx | 4 +- .../SelectCovariates/SelectCovariates.jsx | 10 ++--- .../Steps/SelectOutcome/SelectOutcome.jsx | 10 ++--- 4 files changed, 37 insertions(+), 30 deletions(-) rename src/Analysis/GWASV2/Components/Covariates/{CovariatesCardList.test.js => CovariatesCardList.test.jsx} (69%) diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.js b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx similarity index 69% rename from src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.js rename to src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx index 37e9612220..7b22820093 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.js +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx @@ -1,8 +1,8 @@ import React from 'react'; import { mount } from 'enzyme'; import { DeleteOutlined } from '@ant-design/icons'; -import { Card } from 'antd'; import CovariatesCardsList from './CovariatesCardsList'; +import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; describe('CovariatesCardsList component', () => { let wrapper; @@ -12,16 +12,15 @@ describe('CovariatesCardsList component', () => { mockDeleteCovariate = jest.fn(); const mockProps = { - outcome: { provided_name: 'test outcome' }, + outcome: ValidInitialState.outcome, covariates: [ - { provided_name: 'test dichotomous covariate', concept_id: null }, - { concept_name: 'test continuous covariate', concept_id: '123' }, + { provided_name: 'test dichotomous covariate', concept_id: 123 }, + { concept_name: 'test continuous covariate', concept_id: 456 }, ], deleteCovariate: mockDeleteCovariate, }; wrapper = mount(); - console.log(wrapper.debug()); }); it('should render an outcome card', () => { @@ -31,24 +30,36 @@ describe('CovariatesCardsList component', () => { ); expect( wrapper.find('.outcome-card .ant-card-meta-description').text() - ).toBe('test outcome'); + ).toBe('Attribute8'); }); it('should render two covariate cards', () => { expect(wrapper.find('.dichotomous-card').exists()).toBe(true); - expect(wrapper.find('.dichotomous-card .ant-card-meta-title').text()).toBe( - 'Dichotomous Covariate' - ); expect( - wrapper.find('.dichotomous-card .ant-card-meta-description').text() + wrapper + .find('.dichotomous-card .ant-card-meta-title') + .last() + .text() + ).toBe('Dichotomous Covariate'); + expect( + wrapper + .find('.dichotomous-card .ant-card-meta-description') + .last() + .text() ).toBe('test dichotomous covariate'); expect(wrapper.find('.continuous-card').exists()).toBe(true); - expect(wrapper.find('.continuous-card .ant-card-meta-title').text()).toBe( - 'Continuous Covariate' - ); expect( - wrapper.find('.continuous-card .ant-card-meta-description').text() + wrapper + .find('.continuous-card .ant-card-meta-title') + .last() + .text() + ).toBe('Continuous Covariate'); + expect( + wrapper + .find('.continuous-card .ant-card-meta-description') + .last() + .text() ).toBe('test continuous covariate'); }); @@ -59,7 +70,7 @@ describe('CovariatesCardsList component', () => { .simulate('click'); expect(mockDeleteCovariate).toHaveBeenCalledWith({ provided_name: 'test dichotomous covariate', - concept_id: null, + concept_id: 123, }); wrapper @@ -68,7 +79,7 @@ describe('CovariatesCardsList component', () => { .simulate('click'); expect(mockDeleteCovariate).toHaveBeenCalledWith({ concept_name: 'test continuous covariate', - concept_id: '123', + concept_id: 456, }); }); }); diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx index a47faff564..0d11d08315 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx @@ -16,10 +16,10 @@ const CovariatesCardsList = ({ covariates, outcome, deleteCovariate }) => ( )} {covariates.map((covariate, key) => ( - + {covariate.provided_name && ( - dispatch({ - type: ACTIONS.DELETE_COVARIATE, - payload: chosenCovariate, - }) - } + deleteCovariate={(chosenCovariate) => dispatch({ + type: ACTIONS.DELETE_COVARIATE, + payload: chosenCovariate, + })} /> diff --git a/src/Analysis/GWASV2/Steps/SelectOutcome/SelectOutcome.jsx b/src/Analysis/GWASV2/Steps/SelectOutcome/SelectOutcome.jsx index ef5fbf390a..2bb3c24915 100644 --- a/src/Analysis/GWASV2/Steps/SelectOutcome/SelectOutcome.jsx +++ b/src/Analysis/GWASV2/Steps/SelectOutcome/SelectOutcome.jsx @@ -77,12 +77,10 @@ const SelectOutcome = ({ - dispatch({ - type: ACTIONS.DELETE_COVARIATE, - payload: chosenCovariate, - }) - } + deleteCovariate={(chosenCovariate) => dispatch({ + type: ACTIONS.DELETE_COVARIATE, + payload: chosenCovariate, + })} /> From ceab7299f642df92bdd02b40218040e1e13ad234 Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Fri, 13 Jan 2023 08:42:08 -0600 Subject: [PATCH 4/9] feat(gwasUnifiedFlowOutcomeCard): Cleaned up code formatting for CovariatesCardList.test.jsx --- .../Covariates/CovariatesCardList.test.jsx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx index 7b22820093..5057d1693c 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx @@ -6,11 +6,9 @@ import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; describe('CovariatesCardsList component', () => { let wrapper; - let mockDeleteCovariate; + const mockDeleteCovariate = jest.fn(); beforeEach(() => { - mockDeleteCovariate = jest.fn(); - const mockProps = { outcome: ValidInitialState.outcome, covariates: [ @@ -19,17 +17,16 @@ describe('CovariatesCardsList component', () => { ], deleteCovariate: mockDeleteCovariate, }; - wrapper = mount(); }); it('should render an outcome card', () => { expect(wrapper.find('.outcome-card').exists()).toBe(true); expect(wrapper.find('.outcome-card .ant-card-meta-title').text()).toBe( - 'Outcome' + 'Outcome', ); expect( - wrapper.find('.outcome-card .ant-card-meta-description').text() + wrapper.find('.outcome-card .ant-card-meta-description').text(), ).toBe('Attribute8'); }); @@ -39,13 +36,13 @@ describe('CovariatesCardsList component', () => { wrapper .find('.dichotomous-card .ant-card-meta-title') .last() - .text() + .text(), ).toBe('Dichotomous Covariate'); expect( wrapper .find('.dichotomous-card .ant-card-meta-description') .last() - .text() + .text(), ).toBe('test dichotomous covariate'); expect(wrapper.find('.continuous-card').exists()).toBe(true); @@ -53,13 +50,13 @@ describe('CovariatesCardsList component', () => { wrapper .find('.continuous-card .ant-card-meta-title') .last() - .text() + .text(), ).toBe('Continuous Covariate'); expect( wrapper .find('.continuous-card .ant-card-meta-description') .last() - .text() + .text(), ).toBe('test continuous covariate'); }); @@ -72,7 +69,6 @@ describe('CovariatesCardsList component', () => { provided_name: 'test dichotomous covariate', concept_id: 123, }); - wrapper .find(DeleteOutlined) .last() From d47ab4af982ea3c0d8fa6d4adf2ba7907546da5b Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Fri, 13 Jan 2023 10:19:14 -0600 Subject: [PATCH 5/9] feat(gwasUnifiedFlowStyleSidebars): Wrote storybook for CovariatesCardsList --- .../Covariates/CovariatesCardList.stories.jsx | 30 +++++++++++++++++++ .../Covariates/CovariatesCardList.test.jsx | 29 +++++++++--------- .../InitialStates/ValidInitialState.js | 5 ++++ 3 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.stories.jsx diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.stories.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.stories.jsx new file mode 100644 index 0000000000..a43bef77ec --- /dev/null +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.stories.jsx @@ -0,0 +1,30 @@ +import React, { useState } from 'react'; +import CovariatesCardsList from './CovariatesCardsList'; +import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; +import './Covariates.css'; +import '../../Steps/SelectCovariates/SelectCovariates.css'; +import '../../GWASV2.css'; + +export default { + title: 'Tests3/GWASV2/CovariatesCardsList', + component: CovariatesCardsList, +}; + +const Template = (args) => ( +
+
+
+
+ + alert('called deleteCovariate Method') + } + /> +
+
+
+); + +export const SuccessState = Template.bind({}); +SuccessState.args = ValidInitialState; diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx index 5057d1693c..55334632cb 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx @@ -11,10 +11,7 @@ describe('CovariatesCardsList component', () => { beforeEach(() => { const mockProps = { outcome: ValidInitialState.outcome, - covariates: [ - { provided_name: 'test dichotomous covariate', concept_id: 123 }, - { concept_name: 'test continuous covariate', concept_id: 456 }, - ], + covariates: ValidInitialState.covariates, deleteCovariate: mockDeleteCovariate, }; wrapper = mount(); @@ -23,26 +20,26 @@ describe('CovariatesCardsList component', () => { it('should render an outcome card', () => { expect(wrapper.find('.outcome-card').exists()).toBe(true); expect(wrapper.find('.outcome-card .ant-card-meta-title').text()).toBe( - 'Outcome', + 'Outcome' ); expect( - wrapper.find('.outcome-card .ant-card-meta-description').text(), + wrapper.find('.outcome-card .ant-card-meta-description').text() ).toBe('Attribute8'); }); - it('should render two covariate cards', () => { + it('should render covariate cards', () => { expect(wrapper.find('.dichotomous-card').exists()).toBe(true); expect( wrapper .find('.dichotomous-card .ant-card-meta-title') .last() - .text(), + .text() ).toBe('Dichotomous Covariate'); expect( wrapper .find('.dichotomous-card .ant-card-meta-description') .last() - .text(), + .text() ).toBe('test dichotomous covariate'); expect(wrapper.find('.continuous-card').exists()).toBe(true); @@ -50,14 +47,14 @@ describe('CovariatesCardsList component', () => { wrapper .find('.continuous-card .ant-card-meta-title') .last() - .text(), + .text() ).toBe('Continuous Covariate'); expect( wrapper .find('.continuous-card .ant-card-meta-description') .last() - .text(), - ).toBe('test continuous covariate'); + .text() + ).toBe('Attribute83'); }); it('should call deleteCovariate when the delete icon is clicked', () => { @@ -66,16 +63,18 @@ describe('CovariatesCardsList component', () => { .first() .simulate('click'); expect(mockDeleteCovariate).toHaveBeenCalledWith({ + variable_type: 'custom_dichotomous', provided_name: 'test dichotomous covariate', - concept_id: 123, + concept_id: 2000000123, }); wrapper .find(DeleteOutlined) .last() .simulate('click'); expect(mockDeleteCovariate).toHaveBeenCalledWith({ - concept_name: 'test continuous covariate', - concept_id: 456, + variable_type: 'concept', + concept_name: 'Attribute83', + concept_id: 2000000873, }); }); }); diff --git a/src/Analysis/GWASV2/TestData/InitialStates/ValidInitialState.js b/src/Analysis/GWASV2/TestData/InitialStates/ValidInitialState.js index 26b0ae9d1c..ebf74037f5 100644 --- a/src/Analysis/GWASV2/TestData/InitialStates/ValidInitialState.js +++ b/src/Analysis/GWASV2/TestData/InitialStates/ValidInitialState.js @@ -10,6 +10,11 @@ const ValidInitialState = { size: 510904, }, covariates: [ + { + variable_type: 'custom_dichotomous', + provided_name: 'test dichotomous covariate', + concept_id: 2000000123, + }, { variable_type: 'concept', concept_id: 2000000873, From 79530b3a8a3277836e1c889e553fa4afab22bf40 Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Fri, 13 Jan 2023 10:35:45 -0600 Subject: [PATCH 6/9] feat(gwasUnifiedFlowStyleSidebars): Changed outcome card title to Outcome Phenotype to match design --- .../GWASV2/Components/Covariates/CovariatesCardList.test.jsx | 2 +- .../GWASV2/Components/Covariates/CovariatesCardsList.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx index 55334632cb..0d934bcbe1 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx @@ -20,7 +20,7 @@ describe('CovariatesCardsList component', () => { it('should render an outcome card', () => { expect(wrapper.find('.outcome-card').exists()).toBe(true); expect(wrapper.find('.outcome-card .ant-card-meta-title').text()).toBe( - 'Outcome' + 'Outcome Phenotype' ); expect( wrapper.find('.outcome-card .ant-card-meta-description').text() diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx index 0d11d08315..eb9e59a174 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardsList.jsx @@ -10,7 +10,7 @@ const CovariatesCardsList = ({ covariates, outcome, deleteCovariate }) => ( {outcome && ( From 4f8ec406c509d59d38eb883436b7f95d31a53c58 Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Tue, 17 Jan 2023 09:27:13 -0600 Subject: [PATCH 7/9] feat(gwasUnifiedFlowOutcomeCard): Changed all instances of InitialValidState to ValidState --- .../Covariates/CovariatesCardList.stories.jsx | 4 +-- .../Covariates/CovariatesCardList.test.jsx | 18 +++++----- .../JobInputModal/JobInputModal.stories.jsx | 4 +-- .../JobInputModal/JobInputModal.test.jsx | 4 +-- .../SelectConfiguration.stories.jsx | 4 +-- .../SelectConfiguration.test.jsx | 4 +-- .../SelectHare/SelectHareDropDown.test.jsx | 34 +++++++++---------- .../ValidState.js} | 4 +-- 8 files changed, 38 insertions(+), 38 deletions(-) rename src/Analysis/GWASV2/TestData/{InitialStates/ValidInitialState.js => States/ValidState.js} (94%) diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.stories.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.stories.jsx index a43bef77ec..8b7860445c 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.stories.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.stories.jsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import CovariatesCardsList from './CovariatesCardsList'; -import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; +import ValidState from '../../TestData/States/ValidState'; import './Covariates.css'; import '../../Steps/SelectCovariates/SelectCovariates.css'; import '../../GWASV2.css'; @@ -27,4 +27,4 @@ const Template = (args) => ( ); export const SuccessState = Template.bind({}); -SuccessState.args = ValidInitialState; +SuccessState.args = ValidState; diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx index 0d934bcbe1..89ec4a967c 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { mount } from 'enzyme'; import { DeleteOutlined } from '@ant-design/icons'; import CovariatesCardsList from './CovariatesCardsList'; -import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; +import ValidState from '../../TestData/States/ValidState'; describe('CovariatesCardsList component', () => { let wrapper; @@ -10,8 +10,8 @@ describe('CovariatesCardsList component', () => { beforeEach(() => { const mockProps = { - outcome: ValidInitialState.outcome, - covariates: ValidInitialState.covariates, + outcome: ValidState.outcome, + covariates: ValidState.covariates, deleteCovariate: mockDeleteCovariate, }; wrapper = mount(); @@ -20,10 +20,10 @@ describe('CovariatesCardsList component', () => { it('should render an outcome card', () => { expect(wrapper.find('.outcome-card').exists()).toBe(true); expect(wrapper.find('.outcome-card .ant-card-meta-title').text()).toBe( - 'Outcome Phenotype' + 'Outcome Phenotype', ); expect( - wrapper.find('.outcome-card .ant-card-meta-description').text() + wrapper.find('.outcome-card .ant-card-meta-description').text(), ).toBe('Attribute8'); }); @@ -33,13 +33,13 @@ describe('CovariatesCardsList component', () => { wrapper .find('.dichotomous-card .ant-card-meta-title') .last() - .text() + .text(), ).toBe('Dichotomous Covariate'); expect( wrapper .find('.dichotomous-card .ant-card-meta-description') .last() - .text() + .text(), ).toBe('test dichotomous covariate'); expect(wrapper.find('.continuous-card').exists()).toBe(true); @@ -47,13 +47,13 @@ describe('CovariatesCardsList component', () => { wrapper .find('.continuous-card .ant-card-meta-title') .last() - .text() + .text(), ).toBe('Continuous Covariate'); expect( wrapper .find('.continuous-card .ant-card-meta-description') .last() - .text() + .text(), ).toBe('Attribute83'); }); diff --git a/src/Analysis/GWASV2/Components/JobInputModal/JobInputModal.stories.jsx b/src/Analysis/GWASV2/Components/JobInputModal/JobInputModal.stories.jsx index a7cc624ca6..344e74d794 100644 --- a/src/Analysis/GWASV2/Components/JobInputModal/JobInputModal.stories.jsx +++ b/src/Analysis/GWASV2/Components/JobInputModal/JobInputModal.stories.jsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; +import ValidState from '../../TestData/InitialStates/ValidState'; import JobInputModal from './JobInputModal'; export default { @@ -24,7 +24,7 @@ const MockTemplate = () => { finalPopulationSizes, outcome, selectedStudyPopulationCohort, - } = ValidInitialState; + } = ValidState; return (
null; @@ -21,7 +21,7 @@ const { finalPopulationSizes, outcome, selectedStudyPopulationCohort, -} = ValidInitialState; +} = ValidState; describe('JobInputModal', () => { let wrapper; diff --git a/src/Analysis/GWASV2/Components/SelectConfiguration/SelectConfiguration.stories.jsx b/src/Analysis/GWASV2/Components/SelectConfiguration/SelectConfiguration.stories.jsx index 8eebba7b80..4af68178e7 100644 --- a/src/Analysis/GWASV2/Components/SelectConfiguration/SelectConfiguration.stories.jsx +++ b/src/Analysis/GWASV2/Components/SelectConfiguration/SelectConfiguration.stories.jsx @@ -5,7 +5,7 @@ import SelectionConfiguration from './SelectConfiguration'; import { rest } from 'msw'; import { QueryClient, QueryClientProvider } from 'react-query'; import '../../GWASV2.css'; -import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; +import ValidState from '../../TestData/States/ValidState'; export default { title: 'Tests3/GWASV2/SelectConfiguration', @@ -19,7 +19,7 @@ const mockedQueryClient = new QueryClient({ }); const MockTemplate = () => { - const [state, dispatch] = useReducer(reducer, ValidInitialState); + const [state, dispatch] = useReducer(reducer, ValidState); return ( diff --git a/src/Analysis/GWASV2/Components/SelectConfiguration/SelectConfiguration.test.jsx b/src/Analysis/GWASV2/Components/SelectConfiguration/SelectConfiguration.test.jsx index 80fedd4251..e2823255ee 100644 --- a/src/Analysis/GWASV2/Components/SelectConfiguration/SelectConfiguration.test.jsx +++ b/src/Analysis/GWASV2/Components/SelectConfiguration/SelectConfiguration.test.jsx @@ -1,7 +1,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import SelectConfiguration from './SelectConfiguration'; -import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; +import ValidState from '../../TestData/States/ValidState'; import ACTIONS from '../../Utils/StateManagement/Actions'; describe('SelectConfiguration component', () => { @@ -14,7 +14,7 @@ describe('SelectConfiguration component', () => { covariates, outcome, imputationScore, - } = ValidInitialState; + } = ValidState; beforeEach(() => { wrapper = shallow( diff --git a/src/Analysis/GWASV2/Components/SelectHare/SelectHareDropDown.test.jsx b/src/Analysis/GWASV2/Components/SelectHare/SelectHareDropDown.test.jsx index 1c16a6bbcd..68d63642dc 100644 --- a/src/Analysis/GWASV2/Components/SelectHare/SelectHareDropDown.test.jsx +++ b/src/Analysis/GWASV2/Components/SelectHare/SelectHareDropDown.test.jsx @@ -3,7 +3,7 @@ import { mount } from 'enzyme'; import { Select } from 'antd'; import { QueryClient, QueryClientProvider } from 'react-query'; import SelectHareDropDown from './SelectHareDropDown'; -import ValidInitialState from '../../TestData/InitialStates/ValidInitialState'; +import ValidState from '../../TestData/States/ValidState'; import ACTIONS from '../../Utils/StateManagement/Actions'; import { SourceContextProvider } from '../../Utils/Source'; import { @@ -30,7 +30,8 @@ fetchConceptStatsByHareSubset.mockResolvedValue({ ], }); useSourceFetch.mockResolvedValue({ - sourceId: 2, loading: false, + sourceId: 2, + loading: false, }); // Other generic arguments and functions shared by tests below: @@ -43,7 +44,8 @@ const mountDropDownForOutcome = ( selectedStudyPopulationCohort, covariates, outcome, - dispatch) => mount( + dispatch, +) => mount( { let wrapper; - const { - selectedStudyPopulationCohort, - covariates, - outcome, - } = ValidInitialState; + const { selectedStudyPopulationCohort, covariates, outcome } = ValidState; let dispatch; beforeEach(() => { dispatch = jest.fn(); // use mount() instead of shallow(): - wrapper = mountDropDownForOutcome(selectedStudyPopulationCohort, + wrapper = mountDropDownForOutcome( + selectedStudyPopulationCohort, covariates, outcome, - dispatch); + dispatch, + ); }); it('should render the SelectHareDropDown component', async () => { expect(wrapper.find(SelectHareDropDown).exists()).toBe(true); @@ -107,10 +107,7 @@ describe('SelectHareDropDown component - Quantitative outcome test scenarios', ( describe('SelectHareDropDown component - Dichotomous (case/control) test scenarios', () => { let wrapper; - const { - selectedStudyPopulationCohort, - covariates, - } = ValidInitialState; + const { selectedStudyPopulationCohort, covariates } = ValidState; // Custom dichotomous (case/control) outcome type: const outcome = { variable_type: 'custom_dichotomous', @@ -121,10 +118,12 @@ describe('SelectHareDropDown component - Dichotomous (case/control) test scenari beforeEach(() => { dispatch = jest.fn(); - wrapper = mountDropDownForOutcome(selectedStudyPopulationCohort, + wrapper = mountDropDownForOutcome( + selectedStudyPopulationCohort, covariates, outcome, - dispatch); + dispatch, + ); }); it('should render the SelectHareDropDown component', async () => { expect(wrapper.find(SelectHareDropDown).exists()).toBe(true); @@ -154,7 +153,8 @@ describe('SelectHareDropDown component - Dichotomous (case/control) test scenari payload: [ { population: 'Control', size: 39648 }, { population: 'Case', size: 39648 }, - { population: 'Total', size: 39648 * 2 }], + { population: 'Total', size: 39648 * 2 }, + ], }); }); }); diff --git a/src/Analysis/GWASV2/TestData/InitialStates/ValidInitialState.js b/src/Analysis/GWASV2/TestData/States/ValidState.js similarity index 94% rename from src/Analysis/GWASV2/TestData/InitialStates/ValidInitialState.js rename to src/Analysis/GWASV2/TestData/States/ValidState.js index ebf74037f5..7b7ada2731 100644 --- a/src/Analysis/GWASV2/TestData/InitialStates/ValidInitialState.js +++ b/src/Analysis/GWASV2/TestData/States/ValidState.js @@ -1,4 +1,4 @@ -const ValidInitialState = { +const ValidState = { outcome: { variable_type: 'concept', concept_id: 2000000873, @@ -48,4 +48,4 @@ const ValidInitialState = { }, ], }; -export default ValidInitialState; +export default ValidState; From 95184de6330a4cb953407ec05ff642775801d36a Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Tue, 17 Jan 2023 10:25:42 -0600 Subject: [PATCH 8/9] feat(gwasUnifiedFlowOutcomeCard): Updated CovariatesCardList test to use Valid state objs instead of hard coded values; updated ref to Valid state in JobInputModal; Updated ValidState to use correct data --- .../Covariates/CovariatesCardList.test.jsx | 38 +++++++++---------- .../JobInputModal/JobInputModal.stories.jsx | 2 +- .../GWASV2/TestData/States/ValidState.js | 4 +- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx index 89ec4a967c..83023cc0fe 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx @@ -8,6 +8,14 @@ describe('CovariatesCardsList component', () => { let wrapper; const mockDeleteCovariate = jest.fn(); + const outcomeText = ValidState.outcome.concept_name; + const lastCovariateObj = ValidState.covariates.at(-1); + const lastContinousCovariateText = lastCovariateObj.concept_name; + const dichotomousObj = ValidState.covariates.filter( + (obj) => obj.variable_type === 'custom_dichotomous' + )[0]; + const dichotomousText = dichotomousObj.provided_name; + beforeEach(() => { const mockProps = { outcome: ValidState.outcome, @@ -20,11 +28,11 @@ describe('CovariatesCardsList component', () => { it('should render an outcome card', () => { expect(wrapper.find('.outcome-card').exists()).toBe(true); expect(wrapper.find('.outcome-card .ant-card-meta-title').text()).toBe( - 'Outcome Phenotype', + 'Outcome Phenotype' ); expect( - wrapper.find('.outcome-card .ant-card-meta-description').text(), - ).toBe('Attribute8'); + wrapper.find('.outcome-card .ant-card-meta-description').text() + ).toBe(outcomeText); }); it('should render covariate cards', () => { @@ -33,28 +41,28 @@ describe('CovariatesCardsList component', () => { wrapper .find('.dichotomous-card .ant-card-meta-title') .last() - .text(), + .text() ).toBe('Dichotomous Covariate'); expect( wrapper .find('.dichotomous-card .ant-card-meta-description') .last() - .text(), - ).toBe('test dichotomous covariate'); + .text() + ).toBe(dichotomousText); expect(wrapper.find('.continuous-card').exists()).toBe(true); expect( wrapper .find('.continuous-card .ant-card-meta-title') .last() - .text(), + .text() ).toBe('Continuous Covariate'); expect( wrapper .find('.continuous-card .ant-card-meta-description') .last() - .text(), - ).toBe('Attribute83'); + .text() + ).toBe(lastContinousCovariateText); }); it('should call deleteCovariate when the delete icon is clicked', () => { @@ -62,19 +70,11 @@ describe('CovariatesCardsList component', () => { .find(DeleteOutlined) .first() .simulate('click'); - expect(mockDeleteCovariate).toHaveBeenCalledWith({ - variable_type: 'custom_dichotomous', - provided_name: 'test dichotomous covariate', - concept_id: 2000000123, - }); + expect(mockDeleteCovariate).toHaveBeenCalledWith(dichotomousObj); wrapper .find(DeleteOutlined) .last() .simulate('click'); - expect(mockDeleteCovariate).toHaveBeenCalledWith({ - variable_type: 'concept', - concept_name: 'Attribute83', - concept_id: 2000000873, - }); + expect(mockDeleteCovariate).toHaveBeenCalledWith(lastCovariateObj); }); }); diff --git a/src/Analysis/GWASV2/Components/JobInputModal/JobInputModal.stories.jsx b/src/Analysis/GWASV2/Components/JobInputModal/JobInputModal.stories.jsx index 344e74d794..8fef897745 100644 --- a/src/Analysis/GWASV2/Components/JobInputModal/JobInputModal.stories.jsx +++ b/src/Analysis/GWASV2/Components/JobInputModal/JobInputModal.stories.jsx @@ -1,5 +1,5 @@ import React, { useState } from 'react'; -import ValidState from '../../TestData/InitialStates/ValidState'; +import ValidState from '../../TestData/States/ValidState'; import JobInputModal from './JobInputModal'; export default { diff --git a/src/Analysis/GWASV2/TestData/States/ValidState.js b/src/Analysis/GWASV2/TestData/States/ValidState.js index 7b7ada2731..9b24ca4001 100644 --- a/src/Analysis/GWASV2/TestData/States/ValidState.js +++ b/src/Analysis/GWASV2/TestData/States/ValidState.js @@ -12,8 +12,8 @@ const ValidState = { covariates: [ { variable_type: 'custom_dichotomous', - provided_name: 'test dichotomous covariate', - concept_id: 2000000123, + provided_name: 'providednamebyuser', + cohort_ids: [12, 32], }, { variable_type: 'concept', From 4ce9501e7eea052451f113b9e8274d1938470f48 Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Tue, 17 Jan 2023 10:29:49 -0600 Subject: [PATCH 9/9] feat(gwasUnifiedFlowOutcomeCard): Ran ESLINT-new --- .../Covariates/CovariatesCardList.test.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx index 83023cc0fe..e15be3c56d 100644 --- a/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx +++ b/src/Analysis/GWASV2/Components/Covariates/CovariatesCardList.test.jsx @@ -12,7 +12,7 @@ describe('CovariatesCardsList component', () => { const lastCovariateObj = ValidState.covariates.at(-1); const lastContinousCovariateText = lastCovariateObj.concept_name; const dichotomousObj = ValidState.covariates.filter( - (obj) => obj.variable_type === 'custom_dichotomous' + (obj) => obj.variable_type === 'custom_dichotomous', )[0]; const dichotomousText = dichotomousObj.provided_name; @@ -28,10 +28,10 @@ describe('CovariatesCardsList component', () => { it('should render an outcome card', () => { expect(wrapper.find('.outcome-card').exists()).toBe(true); expect(wrapper.find('.outcome-card .ant-card-meta-title').text()).toBe( - 'Outcome Phenotype' + 'Outcome Phenotype', ); expect( - wrapper.find('.outcome-card .ant-card-meta-description').text() + wrapper.find('.outcome-card .ant-card-meta-description').text(), ).toBe(outcomeText); }); @@ -41,13 +41,13 @@ describe('CovariatesCardsList component', () => { wrapper .find('.dichotomous-card .ant-card-meta-title') .last() - .text() + .text(), ).toBe('Dichotomous Covariate'); expect( wrapper .find('.dichotomous-card .ant-card-meta-description') .last() - .text() + .text(), ).toBe(dichotomousText); expect(wrapper.find('.continuous-card').exists()).toBe(true); @@ -55,13 +55,13 @@ describe('CovariatesCardsList component', () => { wrapper .find('.continuous-card .ant-card-meta-title') .last() - .text() + .text(), ).toBe('Continuous Covariate'); expect( wrapper .find('.continuous-card .ant-card-meta-description') .last() - .text() + .text(), ).toBe(lastContinousCovariateText); });