Skip to content

Commit

Permalink
OCLOMRS-348: Change dictionary version release behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Tittoh committed Dec 11, 2018
1 parent dcee939 commit 97a1db4
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const DictionaryDetailCard = (props) => {
diagnosisConcepts,
procedureConcepts,
otherConcepts,
headVersion,
handleRelease,
hideSubModal,
showSubModal,
subModal,
Expand Down Expand Up @@ -203,14 +201,12 @@ Browse in traditional OCL
<li>
<button
type="button"
onClick={!headVersion.released ? handleRelease : showVersionModal}
onClick={showVersionModal}
className="fas fa-cloud-upload-alt head"
id="releaseVersion"
>
<span id="release-head">
&nbsp;Release&nbsp;
{!headVersion.released ? 'latest ' : null}
version
&nbsp;Release&nbsp;latest&nbsp;version
</span>
</button>
</li>
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DictionaryVersionsTable = (version) => {
};
return (
<tr id="versiontable">
<td>{id === 'HEAD' ? 'Latest' : id}</td>
<td>{id}</td>
<td>{ (new Date(updated_on)).toLocaleDateString('en-US', DATE_OPTIONS)}</td>
<td>
<a className="btn btn-sm" href={version_url}>Browse in OCL</a>
Expand Down
1 change: 1 addition & 0 deletions src/redux/actions/dictionaries/dictionaryActionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
10 changes: 5 additions & 5 deletions src/tests/Dashboard/action/dictionaryAction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand All @@ -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);
});
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down
49 changes: 47 additions & 2 deletions src/tests/Dictionary/DictionaryContainer.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('DictionaryOverview', () => {
<DictionaryOverview {...props} />
</MemoryRouter>
</Provider>);
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);
Expand Down Expand Up @@ -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 }],
Expand Down Expand Up @@ -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(<Provider store={store}>
<MemoryRouter><DictionaryOverview {...props} /></MemoryRouter>
</Provider>);
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,
Expand Down
4 changes: 2 additions & 2 deletions src/tests/__mocks__/versions.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down

0 comments on commit 97a1db4

Please sign in to comment.