-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #566 from codaco/release/4.1.0
bump version to 4.1.0
- Loading branch information
Showing
23 changed files
with
324 additions
and
42 deletions.
There are no files selected for viewing
Submodule network-canvas
updated
from a2db24 to 744275
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
src/components/sections/CategoricalBinPrompts/__tests__/PromptFields.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* eslint-env jest */ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { reduxForm, change } from 'redux-form'; | ||
import { mount } from 'enzyme'; | ||
import { getStore } from '../../../../ducks/store'; | ||
import Options, { Item } from '../../../Options'; | ||
import { actionCreators as codebookActions } from '../../../../ducks/modules/protocol/codebook'; | ||
import PromptFields from '../PromptFields'; | ||
|
||
const mockFormName = 'foo'; | ||
|
||
const initialState = { | ||
protocol: { | ||
timeline: [], | ||
present: { | ||
codebook: { | ||
node: { | ||
person: { | ||
variables: { | ||
bazz: { | ||
options: ['a', 'b', 'c', 'd'], | ||
}, | ||
buzz: { | ||
options: [1, 2], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const MockForm = reduxForm({ | ||
form: mockFormName, | ||
})( | ||
({ handleSubmit, children }) => ( | ||
<form onSubmit={handleSubmit}> | ||
{children} | ||
</form> | ||
), | ||
); | ||
|
||
|
||
const getSubject = (node, store, { form }) => | ||
mount(( | ||
<Provider store={store}> | ||
<MockForm {...form}> | ||
{node} | ||
</MockForm> | ||
</Provider> | ||
)); | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const testPromptFields = (PromptFieldsComponent) => { | ||
let mockStore; | ||
|
||
beforeEach(() => { | ||
mockStore = getStore(initialState); | ||
}); | ||
|
||
describe('PromptFields', () => { | ||
it('when variable is created, variable options are updated', () => { | ||
const formProps = { initialValues: { variable: 'bazz', variableOptions: ['a', 'b', 'c', 'd'] } }; | ||
const additionalProps = { form: formProps }; | ||
|
||
const subject = getSubject( | ||
( | ||
<PromptFieldsComponent | ||
form={mockFormName} | ||
entity="node" | ||
type="person" | ||
/> | ||
), | ||
mockStore, | ||
additionalProps, | ||
); | ||
|
||
expect(subject.find(Options).find(Item).length).toBe(4); | ||
|
||
mockStore.dispatch(codebookActions.createVariable( | ||
'node', | ||
'person', | ||
{ | ||
name: 'fizz', | ||
type: 'foo', | ||
options: [1, 2, 3], | ||
}, | ||
)); | ||
|
||
mockStore.dispatch(change( | ||
mockFormName, | ||
'variable', | ||
'809895df-bbd7-4c76-ac58-e6ada2625f9b', | ||
)); | ||
|
||
subject.update(); | ||
|
||
expect(subject.find(Options).find(Item).length).toBe(3); | ||
}); | ||
|
||
it('when variable is changed, variable options are updated', () => { | ||
const formProps = { initialValues: { variable: 'bazz', variableOptions: ['a', 'b', 'c', 'd'] } }; | ||
const additionalProps = { form: formProps }; | ||
|
||
const subject = getSubject( | ||
( | ||
<PromptFieldsComponent | ||
form={mockFormName} | ||
entity="node" | ||
type="person" | ||
/> | ||
), | ||
mockStore, | ||
additionalProps, | ||
); | ||
|
||
expect(subject.find(Options).find(Item).length).toBe(4); | ||
|
||
mockStore.dispatch(change( | ||
mockFormName, | ||
'variable', | ||
'buzz', | ||
)); | ||
|
||
subject.update(); | ||
|
||
expect(subject.find(Options).find(Item).length).toBe(2); | ||
}); | ||
}); | ||
}; | ||
|
||
testPromptFields(PromptFields); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/components/sections/OrdinalBinPrompts/__tests__/PromptFields.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* eslint-env jest */ | ||
import { testPromptFields } from '../../CategoricalBinPrompts/__tests__/PromptFields.test'; | ||
import PromptFields from '../PromptFields'; | ||
|
||
testPromptFields(PromptFields); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.