From 97a1db47f659dbb340a7fb8b5918bcf95504a20c Mon Sep 17 00:00:00 2001 From: Tittoh Date: Wed, 5 Dec 2018 15:58:46 +0300 Subject: [PATCH] OCLOMRS-348: Change dictionary version release behaviour --- .../dictionary/DictionaryContainer.jsx | 12 ----- .../dictionary/DictionaryDetailCard.jsx | 10 +--- .../dictionary/DictionaryVersionsTable.jsx | 2 +- .../dictionaries/dictionaryActionCreators.js | 1 + .../Dashboard/action/dictionaryAction.test.js | 10 ++-- .../Dictionary/DictionaryContainer.test.jsx | 49 ++++++++++++++++++- src/tests/__mocks__/versions.js | 4 +- 7 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/components/dashboard/components/dictionary/DictionaryContainer.jsx b/src/components/dashboard/components/dictionary/DictionaryContainer.jsx index 33bf7deef..b110f971d 100644 --- a/src/components/dashboard/components/dictionary/DictionaryContainer.jsx +++ b/src/components/dashboard/components/dictionary/DictionaryContainer.jsx @@ -24,7 +24,6 @@ export class DictionaryOverview extends Component { fetchVersions: propTypes.func.isRequired, createVersion: propTypes.func.isRequired, error: propTypes.array, - releaseHead: propTypes.func.isRequired, isReleased: propTypes.bool.isRequired, }; @@ -77,16 +76,6 @@ export class DictionaryOverview extends Component { } } - handleRelease = () => { - const headVersion = this.props.versions.filter(version => version.id === 'HEAD')[0]; - const headVersionObj = Object.assign({}, headVersion); - const data = { - released: true, - }; - const url = headVersionObj.version_url; - this.props.releaseHead(url, data); - } - handleHide = () => this.setState({ showEditModal: false }); handleShow = () => this.setState({ showEditModal: true }); @@ -217,7 +206,6 @@ export class DictionaryOverview extends Component { diagnosisConcepts={diagnosisConcepts} procedureConcepts={procedureConcepts} otherConcepts={otherConcepts} - handleRelease={this.handleRelease} headVersion={headVersionIdObj} showEditModal={this.handleShow} hideSubModal={this.handleHideSub} diff --git a/src/components/dashboard/components/dictionary/DictionaryDetailCard.jsx b/src/components/dashboard/components/dictionary/DictionaryDetailCard.jsx index 633b24cab..15d0230d6 100644 --- a/src/components/dashboard/components/dictionary/DictionaryDetailCard.jsx +++ b/src/components/dashboard/components/dictionary/DictionaryDetailCard.jsx @@ -28,8 +28,6 @@ const DictionaryDetailCard = (props) => { diagnosisConcepts, procedureConcepts, otherConcepts, - headVersion, - handleRelease, hideSubModal, showSubModal, subModal, @@ -203,14 +201,12 @@ Browse in traditional OCL
  • @@ -273,14 +269,12 @@ Browse in traditional OCL DictionaryDetailCard.propTypes = { dictionary: PropTypes.object.isRequired, versions: PropTypes.array.isRequired, - handleRelease: PropTypes.func.isRequired, showEditModal: PropTypes.func.isRequired, customConcepts: PropTypes.string.isRequired, cielConcepts: PropTypes.string.isRequired, diagnosisConcepts: PropTypes.string.isRequired, procedureConcepts: PropTypes.string.isRequired, otherConcepts: PropTypes.string.isRequired, - headVersion: PropTypes.object.isRequired, hideSubModal: PropTypes.func.isRequired, showSubModal: PropTypes.func.isRequired, subModal: PropTypes.bool.isRequired, diff --git a/src/components/dashboard/components/dictionary/DictionaryVersionsTable.jsx b/src/components/dashboard/components/dictionary/DictionaryVersionsTable.jsx index a5a07ede3..b2877c2c3 100644 --- a/src/components/dashboard/components/dictionary/DictionaryVersionsTable.jsx +++ b/src/components/dashboard/components/dictionary/DictionaryVersionsTable.jsx @@ -14,7 +14,7 @@ const DictionaryVersionsTable = (version) => { }; return ( - {id === 'HEAD' ? 'Latest' : id} + {id} { (new Date(updated_on)).toLocaleDateString('en-US', DATE_OPTIONS)} Browse in OCL diff --git a/src/redux/actions/dictionaries/dictionaryActionCreators.js b/src/redux/actions/dictionaries/dictionaryActionCreators.js index cbf0d3350..e945cbf34 100644 --- a/src/redux/actions/dictionaries/dictionaryActionCreators.js +++ b/src/redux/actions/dictionaries/dictionaryActionCreators.js @@ -227,6 +227,7 @@ export const createVersion = (url, data) => (dispatch) => { `${payload.id} has successfully been released`, 'success', 6000, ); + dispatch(fetchVersions(url)); }) .catch((error) => { if(error.response.data.detail){ diff --git a/src/tests/Dashboard/action/dictionaryAction.test.js b/src/tests/Dashboard/action/dictionaryAction.test.js index 2ad34a5b6..5bb703b1d 100644 --- a/src/tests/Dashboard/action/dictionaryAction.test.js +++ b/src/tests/Dashboard/action/dictionaryAction.test.js @@ -405,7 +405,7 @@ describe('Test for successful dictionaries fetch, failure and refresh', () => { }, ]; const store = mockStore({ payload: {} }); - return store.dispatch(releaseHead('/users/nesh/collections/test/HEAD/')).then(() => { + return store.dispatch(releaseHead('/users/nesh/collections/test/1.0/')).then(() => { expect(store.getActions()).toEqual(expectedActions); }); }); @@ -423,7 +423,7 @@ describe('Test for successful dictionaries fetch, failure and refresh', () => { }, ]; const store = mockStore({ payload: {} }); - return store.dispatch(releaseHead('/users/nesh/collections/test/HEAD/')).then(() => { + return store.dispatch(releaseHead('/users/nesh/collections/test/1.0/')).then(() => { expect(store.getActions()).toEqual(expectedActions); }); }); @@ -452,7 +452,7 @@ describe('Test for successful dictionaries fetch, failure and refresh', () => { released: true, description: 'Released', }; - const url = '/users/nesh/collections/test/HEAD/'; + const url = '/users/nesh/collections/test/1.0/'; return store.dispatch(createVersion(url, data)).then(() => { expect(store.getActions()).toEqual(expectedActions); }); @@ -481,7 +481,7 @@ describe('Test for successful dictionaries fetch, failure and refresh', () => { released: true, description: 'Released', }; - const url = '/users/nesh/collections/test/HEAD/'; + const url = '/users/nesh/collections/test/1.0/'; return store.dispatch(createVersion(url, data)).then(() => { expect(store.getActions()).toEqual(expectedActions); }); @@ -514,7 +514,7 @@ describe('Test for successful dictionaries fetch, failure and refresh', () => { released: true, description: 'Released', }; - const url = '/users/nesh/collections/test/HEAD/'; + const url = '/users/nesh/collections/test/1.0/'; return store.dispatch(createVersion(url, data)).then(() => { expect(store.getActions()).toEqual(expectedActions); }); diff --git a/src/tests/Dictionary/DictionaryContainer.test.jsx b/src/tests/Dictionary/DictionaryContainer.test.jsx index 4c7d3a7ac..bc9c94842 100644 --- a/src/tests/Dictionary/DictionaryContainer.test.jsx +++ b/src/tests/Dictionary/DictionaryContainer.test.jsx @@ -149,7 +149,7 @@ describe('DictionaryOverview', () => { ); - const spy = jest.spyOn(wrapper.find('DictionaryOverview').instance(), 'handleRelease'); + const spy = jest.spyOn(wrapper.find('DictionaryOverview').instance(), 'showVersionModal'); wrapper.instance().forceUpdate(); wrapper.find('.fas.fa-cloud-upload-alt.head').simulate('click'); expect(spy).toHaveBeenCalledTimes(1); @@ -365,7 +365,7 @@ describe('DictionaryOverview', () => { expect(spy).toHaveBeenCalledTimes(1); }); - it('should handle a new version release', async (done) => { + it('should handle a new version release without error', async (done) => { const props = { dictionary, versions: [{ released: true, ...versions, customVersion }], @@ -410,6 +410,51 @@ describe('DictionaryOverview', () => { done(); }); + it('should handle a new version release with error', async (done) => { + const props = { + dictionary, + versions: [{ released: true, ...versions, customVersion }], + dictionaryConcepts: [dictionary], + isReleased: true, + hideVersionModal: jest.fn(), + showVersionModal: jest.fn(), + error: ['Sorry'], + inputLength: 4, + match: { + params: { + ownerType: 'users', + owner: 'nesh', + type: 'collection', + name: 'test', + }, + }, + fetchDictionary: jest.fn(), + fetchVersions: jest.fn(), + fetchDictionaryConcepts: jest.fn(), + releaseHead: jest.fn(), + createVersion: jest.fn().mockImplementation(() => Promise.resolve()), + loader: false, + }; + const event = { + preventDefault: jest.fn(), + target: { + value: 'v2.0', + name: 'versionId', + }, + }; + localStorage.setItem('username', dictionary.owner); + const wrapper = mount( + + ); + const spy = jest.spyOn(wrapper.find('DictionaryOverview').instance(), 'handleCreateVersion'); + wrapper.find('#releaseVersion').simulate('click'); + wrapper.find('Input #versionId').simulate('change', event); + wrapper.find('Button #saveReleaseVersion').simulate('click'); + expect(spy).toHaveBeenCalledTimes(1); + await expect(props.createVersion).toHaveBeenCalled(); + done(); + }); + it('should handleChange', () => { const props = { dictionary, diff --git a/src/tests/__mocks__/versions.js b/src/tests/__mocks__/versions.js index 048dfc5fa..620ac08e0 100644 --- a/src/tests/__mocks__/versions.js +++ b/src/tests/__mocks__/versions.js @@ -1,12 +1,12 @@ export default { - id: 'HEAD', + id: '1.0', released: true, retired: false, owner: 'chriskala', version_external_id: '1.6', owner_type: 'User', owner_url: '/users/chriskala/', - version_url: '/users/chriskala/collections/over/HEAD/', + version_url: '/users/chriskala/collections/over/1.0/', url: '/users/chriskala/collections/over/', }; export const customVersion = {