diff --git a/src/js/actions/concepts/delete.spec.js b/src/js/actions/concepts/delete.spec.js new file mode 100644 index 000000000..7ef99c027 --- /dev/null +++ b/src/js/actions/concepts/delete.spec.js @@ -0,0 +1,38 @@ +import remove from './delete'; +import * as A from 'js/actions/constants'; +import api from 'js/remote-api/concepts-api'; + +const dispatch = jest.fn(); +jest.mock('js/remote-api/concepts-api'); + +describe('Concepts actions', () => { + it('should call dispatch DELETE_CONCEPT_SUCCESS action with the sorted array', async () => { + api.deleteConcept = function() { + return Promise.resolve([{ label: 'bbb' }, { label: 'aaa' }]); + }; + await remove(1)(dispatch); + expect(dispatch).toHaveBeenCalledWith({ + type: A.DELETE_CONCEPT, + payload: { id: 1 }, + }); + expect(dispatch).toHaveBeenLastCalledWith({ + type: A.DELETE_CONCEPT_SUCCESS, + payload: { id: 1 }, + }); + }); + + it('should call dispatch DELETE_CONCEPT_FAILURE action with an error object', async () => { + api.deleteConcept = function() { + return Promise.reject('error'); + }; + await remove(1)(dispatch); + expect(dispatch).toHaveBeenCalledWith({ + type: A.DELETE_CONCEPT, + payload: { id: 1 }, + }); + expect(dispatch).toHaveBeenLastCalledWith({ + type: A.DELETE_CONCEPT_FAILURE, + payload: { err: 'error', id: 1 }, + }); + }); +}); diff --git a/src/js/actions/concepts/list.spec.js b/src/js/actions/concepts/list.spec.js new file mode 100644 index 000000000..a18fb8ec6 --- /dev/null +++ b/src/js/actions/concepts/list.spec.js @@ -0,0 +1,38 @@ +import get from './list'; +import * as A from 'js/actions/constants'; +import api from 'js/remote-api/concepts-api'; + +const dispatch = jest.fn(); +jest.mock('js/remote-api/concepts-api'); + +describe('Concepts actions', () => { + it('should call dispatch LOAD_CONCEPT_LIST_SUCCESS action with the sorted array', async () => { + api.getConceptList = function() { + return Promise.resolve([{ label: 'bbb' }, { label: 'aaa' }]); + }; + await get()(dispatch); + expect(dispatch).toHaveBeenCalledWith({ + type: A.LOAD_CONCEPT_LIST, + payload: {}, + }); + expect(dispatch).toHaveBeenLastCalledWith({ + type: A.LOAD_CONCEPT_LIST_SUCCESS, + payload: { results: [{ label: 'aaa' }, { label: 'bbb' }] }, + }); + }); + + it('should call dispatch LOAD_CONCEPT_LIST_FAILURE action with an error object', async () => { + api.getConceptList = function() { + return Promise.reject('error'); + }; + await get()(dispatch); + expect(dispatch).toHaveBeenCalledWith({ + type: A.LOAD_CONCEPT_LIST, + payload: {}, + }); + expect(dispatch).toHaveBeenLastCalledWith({ + type: A.LOAD_CONCEPT_LIST_FAILURE, + payload: { err: 'error' }, + }); + }); +}); diff --git a/src/js/components/concepts/visualization/home-container.js b/src/js/components/concepts/visualization/home-container.js index 406193b9b..c5851639a 100644 --- a/src/js/components/concepts/visualization/home-container.js +++ b/src/js/components/concepts/visualization/home-container.js @@ -73,8 +73,6 @@ class ConceptVisualizationContainer extends Component { deletionRequested: false, showModalError: true, }); - //we need to load the concept again - this.props.loadConcept(id); } } render() { diff --git a/src/js/components/operations/msd/documents/documents-bloc/index.js b/src/js/components/operations/msd/documents/documents-bloc/index.js index bd1cb8cd2..ba776f287 100644 --- a/src/js/components/operations/msd/documents/documents-bloc/index.js +++ b/src/js/components/operations/msd/documents/documents-bloc/index.js @@ -22,6 +22,7 @@ import spinner from 'img/spinner.svg'; * @property {(string) => void } addHandler * @property {import('js/types').SimsDocuments[]} documentStores * @property {String} documentStoresStatus + * @property {String} objectType */ /** @@ -38,6 +39,7 @@ export function DocumentsBloc({ addHandler, documentStores = [], documentStoresStatus, + objectType, }) { const [panelStatus, setPanelStatus] = useState(false); const [filter, setFilter] = useState(''); @@ -105,8 +107,11 @@ export function DocumentsBloc({ ); } + const addTitle = objectType === 'documents' ? D.addDocument : D.addLink; + const title = objectType === 'documents' ? D.titleDocument : D.titleLink; return ( <> +

{title}

{documents && documents.length > 0 && (