diff --git a/__tests__/actionCreators/resources.test.js b/__tests__/actionCreators/resources.test.js index 84e2beb68..a1ee6a1c7 100644 --- a/__tests__/actionCreators/resources.test.js +++ b/__tests__/actionCreators/resources.test.js @@ -87,9 +87,10 @@ describe('newResource', () => { await store.dispatch(newResource(resourceTemplateId)) const actions = store.getActions() expect(actions[0]).toEqual({ type: 'CLEAR_RESOURCE_TEMPLATES' }) - expect(actions[1]).toEqual({ type: 'SET_RESOURCE', payload: { [resourceTemplateId]: {} } }) - expect(actions[2]).toEqual({ type: 'RETRIEVE_RESOURCE_TEMPLATE_STARTED', payload: resourceTemplateId }) - expect(actions[3]).toEqual({ type: 'SET_RESOURCE_TEMPLATE', payload: resourceTemplateResponse.response.body }) + expect(actions[1]).toEqual({ type: 'CLEAR_RESOURCE_URI_MESSAGE' }) + expect(actions[2]).toEqual({ type: 'SET_RESOURCE', payload: { [resourceTemplateId]: {} } }) + expect(actions[3]).toEqual({ type: 'RETRIEVE_RESOURCE_TEMPLATE_STARTED', payload: resourceTemplateId }) + expect(actions[4]).toEqual({ type: 'SET_RESOURCE_TEMPLATE', payload: resourceTemplateResponse.response.body }) }) }) @@ -116,10 +117,11 @@ describe('existingResource', () => { await store.dispatch(existingResource(resource, 'http://localhost:8080/repository/stanford/888ea64d-f471-41bf-9d33-c9426ab83b5c')) const actions = store.getActions() - expect(actions[0]).toEqual({ type: 'SET_RESOURCE', payload: { [resourceTemplateId]: {} } }) - expect(actions[1]).toEqual({ type: 'SET_BASE_URL', payload: 'http://localhost:8080/repository/stanford/888ea64d-f471-41bf-9d33-c9426ab83b5c' }) - expect(actions[2]).toEqual({ type: 'RETRIEVE_RESOURCE_TEMPLATE_STARTED', payload: undefined }) - expect(actions[3]).toEqual({ type: 'SET_RESOURCE_TEMPLATE', payload: resourceTemplateResponse.response.body }) + expect(actions[0]).toEqual({ type: 'CLEAR_RESOURCE_URI_MESSAGE' }) + expect(actions[1]).toEqual({ type: 'SET_RESOURCE', payload: { [resourceTemplateId]: {} } }) + expect(actions[2]).toEqual({ type: 'SET_BASE_URL', payload: 'http://localhost:8080/repository/stanford/888ea64d-f471-41bf-9d33-c9426ab83b5c' }) + expect(actions[3]).toEqual({ type: 'RETRIEVE_RESOURCE_TEMPLATE_STARTED', payload: undefined }) + expect(actions[4]).toEqual({ type: 'SET_RESOURCE_TEMPLATE', payload: resourceTemplateResponse.response.body }) }) }) diff --git a/__tests__/reducers/inputs.test.js b/__tests__/reducers/inputs.test.js index 45387373b..da0282b2f 100644 --- a/__tests__/reducers/inputs.test.js +++ b/__tests__/reducers/inputs.test.js @@ -3,7 +3,7 @@ import { removeMyItem, setItemsOrSelections, setBaseURL, validate, showGroupChooser, closeGroupChooser, showRdfPreview, - showResourceURIMessage, + showResourceURIMessage, clearResourceURIMessage, } from 'reducers/inputs' import { findNode, @@ -377,6 +377,22 @@ describe('showResourceURIMessage', () => { }) }) +describe('clearResourceURIMessage', () => { + it('turns off the Resource URI message display', () => { + initialState.editor.resourceURIMessage = { + show: true, + uri: 'this message will disapear', + } + + const result = clearResourceURIMessage(initialState, { + type: 'CLEAR_RESOURCE_URI_MESSAGE', + }) + + expect(result.editor.resourceURIMessage.show).toBe(false) + expect(result.editor.resourceURIMessage.uri).toEqual('') + }) +}) + describe('removeMyItem', () => { it('removes an item from state', () => { initialState.resource = { diff --git a/src/actionCreators/resources.js b/src/actionCreators/resources.js index 9ba9052fb..1792026ef 100644 --- a/src/actionCreators/resources.js +++ b/src/actionCreators/resources.js @@ -5,6 +5,7 @@ import { assignBaseURL, updateStarted, updateFinished, retrieveResourceStarted, setResource, updateProperty, toggleCollapse, appendResource, clearResourceTemplates, + clearResourceURIMessage, } from 'actions/index' import { fetchResourceTemplate } from 'actionCreators/resourceTemplates' import { updateRDFResource, loadRDFResource } from 'sinopiaServer' @@ -47,12 +48,14 @@ export const newResource = resourceTemplateId => (dispatch) => { const resource = {} resource[resourceTemplateId] = {} dispatch(clearResourceTemplates()) + dispatch(clearResourceURIMessage()) dispatch(setResource(resource)) dispatch(stubResource(true)) } // A thunk that stubs out an existing new resource export const existingResource = (resource, uri) => (dispatch) => { + dispatch(clearResourceURIMessage()) dispatch(setResource(resource)) dispatch(assignBaseURL(uri)) dispatch(stubResource(false)) diff --git a/src/actions/index.js b/src/actions/index.js index 4c0196de6..6f24887ea 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -72,6 +72,10 @@ export const showResourceURIMessage = resourceUri => ({ payload: resourceUri, }) +export const clearResourceURIMessage = () => ({ + type: 'CLEAR_RESOURCE_URI_MESSAGE', +}) + export const updateStarted = () => ({ type: 'UPDATE_STARTED', }) diff --git a/src/reducers/index.js b/src/reducers/index.js index 1be63af22..077a9e4fe 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -3,8 +3,8 @@ import { combineReducers } from 'redux' import authenticate from './authenticate' import { - removeMyItem, setItemsOrSelections, setBaseURL, showResourceURIMessage, setMyItemsLang, - showGroupChooser, closeGroupChooser, showRdfPreview, + removeMyItem, setItemsOrSelections, setBaseURL, showResourceURIMessage, clearResourceURIMessage, + setMyItemsLang, showGroupChooser, closeGroupChooser, showRdfPreview, } from './inputs' import { setResourceTemplate, clearResourceTemplates, setResourceTemplateSummary, @@ -111,6 +111,7 @@ const handlers = { RETRIEVE_RESOURCE_TEMPLATE_STARTED: clearRetrieveError, SET_BASE_URL: setBaseURL, SHOW_RESOURCE_URI_MESSAGE: showResourceURIMessage, + CLEAR_RESOURCE_URI_MESSAGE: clearResourceURIMessage, SHOW_SEARCH_RESULTS: showSearchResults, SHOW_GROUP_CHOOSER: showGroupChooser, CLOSE_GROUP_CHOOSER: closeGroupChooser, diff --git a/src/reducers/inputs.js b/src/reducers/inputs.js index 6dea5667d..c105c76d1 100644 --- a/src/reducers/inputs.js +++ b/src/reducers/inputs.js @@ -154,6 +154,19 @@ export const showResourceURIMessage = (state, action) => { return newState } +/** + * @param {Object} state the previous redux state + * @param {Object} action the payload of the action is the URI returned from saving the resource + * @return {Object} the next redux state + */ +export const clearResourceURIMessage = (state) => { + const newState = { ...state } + + newState.editor.resourceURIMessage.show = false + newState.editor.resourceURIMessage.uri = '' + return newState +} + export const removeMyItem = (state, action) => { const newState = { ...state } const reduxPath = action.payload.reduxPath