diff --git a/__tests__/integration/mirador/basic.test.js b/__tests__/integration/mirador/basic.test.js index e562897324e3df1d3b75f7ed6d38e89077df2d00..f15f5d5ec1a6cdd2f1aa5178583c85143e720928 100644 --- a/__tests__/integration/mirador/basic.test.js +++ b/__tests__/integration/mirador/basic.test.js @@ -11,7 +11,6 @@ describe('Basic end to end Mirador', () => { await expect(page).toClick('.mirador-add-resource-button'); await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/sn904cj3439'); await expect(page).toClick('#fetchBtn'); - await expect(page).toClick('button[aria-label="Close add resource panel"]'); // Close menu so new item is visible await expect(page).toMatchElement('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button'); await expect(page).toClick('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button'); await expect(page).toMatchElement( diff --git a/__tests__/integration/mirador/window_actions.test.js b/__tests__/integration/mirador/window_actions.test.js index 359b67ea30fb27de5acb4bb94671647f7a0598f7..d7c892b22f6853cebdedf616975ae43c1d903772 100644 --- a/__tests__/integration/mirador/window_actions.test.js +++ b/__tests__/integration/mirador/window_actions.test.js @@ -8,7 +8,6 @@ describe('Window actions', () => { await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/sn904cj3439'); await expect(page).toClick('#fetchBtn'); - await expect(page).toClick('button[aria-label="Close add resource panel"]'); // Close menu so new item is visible await expect(page).toMatchElement('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button'); await expect(page).toClick('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button'); diff --git a/__tests__/integration/mirador/window_sidebar.test.js b/__tests__/integration/mirador/window_sidebar.test.js index b48ffd86416366de621ba3091edfd708ed45fb28..45a9ffd917ba2da908dc024354210f7dc6ade361 100644 --- a/__tests__/integration/mirador/window_sidebar.test.js +++ b/__tests__/integration/mirador/window_sidebar.test.js @@ -9,7 +9,6 @@ describe('Window Sidebars', () => { await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/001'); await expect(page).toClick('#fetchBtn'); - await expect(page).toClick('button[aria-label="Close add resource panel"]'); // Close menu so new item is visible await expect(page).toMatchElement('[data-manifestid="http://localhost:5000/api/001"] button'); await expect(page).toClick('[data-manifestid="http://localhost:5000/api/001"] button'); }); diff --git a/__tests__/src/components/ManifestForm.test.js b/__tests__/src/components/ManifestForm.test.js index 9808c4ebff3f67975764527a134639d479e3ff1f..68811a920b391bee5fb478f448da644eab0e4f3c 100644 --- a/__tests__/src/components/ManifestForm.test.js +++ b/__tests__/src/components/ManifestForm.test.js @@ -23,21 +23,27 @@ describe('ManifestForm', () => { it('has a cancel button when a cancel action is provided', () => { const onCancel = jest.fn(); const wrapper = createWrapper({ onCancel }); + wrapper.setState({ formValue: 'asdf' }); expect(wrapper.find('WithStyles(Button)[onClick]').length).toBe(1); wrapper.find('WithStyles(Button)[onClick]').simulate('click'); expect(onCancel).toHaveBeenCalled(); + expect(wrapper.state().formValue).toBe(''); }); it('triggers an action when the form is submitted', () => { const fetchManifest = jest.fn(); - const wrapper = createWrapper({ fetchManifest }); + const onSubmit = jest.fn(); + const wrapper = createWrapper({ fetchManifest, onSubmit }); + wrapper.setState({ formValue: 'asdf' }); wrapper.setState({ formValue: 'http://example.com/iiif' }); wrapper.find('form').simulate('submit', { preventDefault: () => {} }); expect(fetchManifest).toHaveBeenCalledWith('http://example.com/iiif'); + expect(onSubmit).toHaveBeenCalled(); + expect(wrapper.state().formValue).toBe(''); }); }); diff --git a/__tests__/src/components/WorkspaceAdd.test.js b/__tests__/src/components/WorkspaceAdd.test.js index 12e873a13935d6067ca6300a6312af775945dcde..925a0bbb0ce98834bd13ec877bff1d3a6157adc5 100644 --- a/__tests__/src/components/WorkspaceAdd.test.js +++ b/__tests__/src/components/WorkspaceAdd.test.js @@ -52,6 +52,15 @@ describe('WorkspaceAdd', () => { expect(wrapper.find('WithStyles(Drawer)').props().open).toBe(false); }); + it('passes a submit action through to the form', () => { + const wrapper = createWrapper(); + wrapper.setState({ addResourcesOpen: true }); + + expect(wrapper.find('WithStyles(Drawer)').find(ManifestForm).length).toBe(1); + wrapper.find('WithStyles(Drawer)').find(ManifestForm).props().onSubmit(); + expect(wrapper.find('WithStyles(Drawer)').props().open).toBe(false); + }); + it('passes a cancel action through to the form', () => { const wrapper = createWrapper(); wrapper.setState({ addResourcesOpen: true }); diff --git a/src/components/ManifestForm.js b/src/components/ManifestForm.js index 4eb2c0eb39c34c6ad54e83de44ecdd50fef2f366..7955b73bb8af749052f6dad6b255eb2b57de1ad3 100644 --- a/src/components/ManifestForm.js +++ b/src/components/ManifestForm.js @@ -19,6 +19,7 @@ export class ManifestForm extends Component { }; this.formSubmit = this.formSubmit.bind(this); + this.handleCancel = this.handleCancel.bind(this); this.handleInputChange = this.handleInputChange.bind(this); } @@ -28,10 +29,22 @@ export class ManifestForm extends Component { * @private */ formSubmit(event) { - const { fetchManifest } = this.props; + const { fetchManifest, onSubmit } = this.props; const { formValue } = this.state; event.preventDefault(); + onSubmit(); fetchManifest(formValue); + this.setState({ formValue: '' }); + } + + /** + * Reset the form state + */ + handleCancel() { + const { onCancel } = this.props; + + onCancel(); + this.setState({ formValue: '' }); } /** @@ -71,7 +84,7 @@ export class ManifestForm extends Component { </Grid> <Grid item sm={3}> { onCancel && ( - <Button onClick={onCancel}> + <Button onClick={this.handleCancel}> {t('cancel')} </Button> )} @@ -88,10 +101,12 @@ export class ManifestForm extends Component { ManifestForm.propTypes = { fetchManifest: PropTypes.func.isRequired, onCancel: PropTypes.func, + onSubmit: PropTypes.func, t: PropTypes.func, }; ManifestForm.defaultProps = { t: key => key, onCancel: null, + onSubmit: () => {}, }; diff --git a/src/components/WorkspaceAdd.js b/src/components/WorkspaceAdd.js index 69e132233c147be02f337d4877ae692b252a1b9b..f2c8634e318b6b210d70d5db80633536768f4b39 100644 --- a/src/components/WorkspaceAdd.js +++ b/src/components/WorkspaceAdd.js @@ -99,7 +99,10 @@ export class WorkspaceAdd extends React.Component { </Typography> </Toolbar> </AppBar> - <ManifestForm onCancel={() => (this.setAddResourcesVisibility(false))} /> + <ManifestForm + onSubmit={() => (this.setAddResourcesVisibility(false))} + onCancel={() => (this.setAddResourcesVisibility(false))} + /> </Paper> </Drawer> </div> diff --git a/src/containers/WorkspaceAddButton.js b/src/containers/WorkspaceAddButton.js index 1cb25a49065cc3458d993cadf05e0579f79b1058..255d696e5602e1b7efabf306bf9f9dac3d918d92 100644 --- a/src/containers/WorkspaceAddButton.js +++ b/src/containers/WorkspaceAddButton.js @@ -13,7 +13,6 @@ import { WorkspaceAddButton } from '../components/WorkspaceAddButton'; */ const mapStateToProps = state => ( { - manifests: state.manifests, isWorkspaceAddVisible: state.workspace.isWorkspaceAddVisible, } ); diff --git a/src/state/reducers/manifests.js b/src/state/reducers/manifests.js index c3f52fdd6a57b5f98cb58884a12b6e39ea710df0..c8110e573438cf4f411cc059fdb1429050e36a5b 100644 --- a/src/state/reducers/manifests.js +++ b/src/state/reducers/manifests.js @@ -1,4 +1,5 @@ import manifesto from 'manifesto.js'; +import omit from 'lodash/omit'; import ActionTypes from '../actions/action-types'; /** @@ -8,12 +9,12 @@ export const manifestsReducer = (state = {}, action) => { switch (action.type) { case ActionTypes.REQUEST_MANIFEST: return { - ...state, [action.manifestId]: { ...state[action.manifestId], ...action.properties, id: action.manifestId, }, + ...omit(state, action.manifestId), }; case ActionTypes.RECEIVE_MANIFEST: return {