Skip to content
Snippets Groups Projects
Commit 75c1a98b authored by Chris Beer's avatar Chris Beer
Browse files

Improve UX for the new resources panel

parent 2a95bf73
No related branches found
No related tags found
No related merge requests found
...@@ -11,7 +11,6 @@ describe('Basic end to end Mirador', () => { ...@@ -11,7 +11,6 @@ describe('Basic end to end Mirador', () => {
await expect(page).toClick('.mirador-add-resource-button'); await expect(page).toClick('.mirador-add-resource-button');
await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/sn904cj3439'); await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/sn904cj3439');
await expect(page).toClick('#fetchBtn'); 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).toMatchElement('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button');
await expect(page).toClick('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button'); await expect(page).toClick('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button');
await expect(page).toMatchElement( await expect(page).toMatchElement(
......
...@@ -8,7 +8,6 @@ describe('Window actions', () => { ...@@ -8,7 +8,6 @@ describe('Window actions', () => {
await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/sn904cj3439'); await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/sn904cj3439');
await expect(page).toClick('#fetchBtn'); 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).toMatchElement('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button');
await expect(page).toClick('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button'); await expect(page).toClick('[data-manifestid="http://localhost:5000/api/sn904cj3439"] button');
......
...@@ -9,7 +9,6 @@ describe('Window Sidebars', () => { ...@@ -9,7 +9,6 @@ describe('Window Sidebars', () => {
await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/001'); await expect(page).toFill('#manifestURL', 'http://localhost:5000/api/001');
await expect(page).toClick('#fetchBtn'); 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).toMatchElement('[data-manifestid="http://localhost:5000/api/001"] button');
await expect(page).toClick('[data-manifestid="http://localhost:5000/api/001"] button'); await expect(page).toClick('[data-manifestid="http://localhost:5000/api/001"] button');
}); });
......
...@@ -23,21 +23,27 @@ describe('ManifestForm', () => { ...@@ -23,21 +23,27 @@ describe('ManifestForm', () => {
it('has a cancel button when a cancel action is provided', () => { it('has a cancel button when a cancel action is provided', () => {
const onCancel = jest.fn(); const onCancel = jest.fn();
const wrapper = createWrapper({ onCancel }); const wrapper = createWrapper({ onCancel });
wrapper.setState({ formValue: 'asdf' });
expect(wrapper.find('WithStyles(Button)[onClick]').length).toBe(1); expect(wrapper.find('WithStyles(Button)[onClick]').length).toBe(1);
wrapper.find('WithStyles(Button)[onClick]').simulate('click'); wrapper.find('WithStyles(Button)[onClick]').simulate('click');
expect(onCancel).toHaveBeenCalled(); expect(onCancel).toHaveBeenCalled();
expect(wrapper.state().formValue).toBe('');
}); });
it('triggers an action when the form is submitted', () => { it('triggers an action when the form is submitted', () => {
const fetchManifest = jest.fn(); 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.setState({ formValue: 'http://example.com/iiif' });
wrapper.find('form').simulate('submit', { preventDefault: () => {} }); wrapper.find('form').simulate('submit', { preventDefault: () => {} });
expect(fetchManifest).toHaveBeenCalledWith('http://example.com/iiif'); expect(fetchManifest).toHaveBeenCalledWith('http://example.com/iiif');
expect(onSubmit).toHaveBeenCalled();
expect(wrapper.state().formValue).toBe('');
}); });
}); });
...@@ -52,6 +52,15 @@ describe('WorkspaceAdd', () => { ...@@ -52,6 +52,15 @@ describe('WorkspaceAdd', () => {
expect(wrapper.find('WithStyles(Drawer)').props().open).toBe(false); 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', () => { it('passes a cancel action through to the form', () => {
const wrapper = createWrapper(); const wrapper = createWrapper();
wrapper.setState({ addResourcesOpen: true }); wrapper.setState({ addResourcesOpen: true });
......
...@@ -19,6 +19,7 @@ export class ManifestForm extends Component { ...@@ -19,6 +19,7 @@ export class ManifestForm extends Component {
}; };
this.formSubmit = this.formSubmit.bind(this); this.formSubmit = this.formSubmit.bind(this);
this.handleCancel = this.handleCancel.bind(this);
this.handleInputChange = this.handleInputChange.bind(this); this.handleInputChange = this.handleInputChange.bind(this);
} }
...@@ -28,10 +29,22 @@ export class ManifestForm extends Component { ...@@ -28,10 +29,22 @@ export class ManifestForm extends Component {
* @private * @private
*/ */
formSubmit(event) { formSubmit(event) {
const { fetchManifest } = this.props; const { fetchManifest, onSubmit } = this.props;
const { formValue } = this.state; const { formValue } = this.state;
event.preventDefault(); event.preventDefault();
onSubmit();
fetchManifest(formValue); 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 { ...@@ -71,7 +84,7 @@ export class ManifestForm extends Component {
</Grid> </Grid>
<Grid item sm={3}> <Grid item sm={3}>
{ onCancel && ( { onCancel && (
<Button onClick={onCancel}> <Button onClick={this.handleCancel}>
{t('cancel')} {t('cancel')}
</Button> </Button>
)} )}
...@@ -88,10 +101,12 @@ export class ManifestForm extends Component { ...@@ -88,10 +101,12 @@ export class ManifestForm extends Component {
ManifestForm.propTypes = { ManifestForm.propTypes = {
fetchManifest: PropTypes.func.isRequired, fetchManifest: PropTypes.func.isRequired,
onCancel: PropTypes.func, onCancel: PropTypes.func,
onSubmit: PropTypes.func,
t: PropTypes.func, t: PropTypes.func,
}; };
ManifestForm.defaultProps = { ManifestForm.defaultProps = {
t: key => key, t: key => key,
onCancel: null, onCancel: null,
onSubmit: () => {},
}; };
...@@ -99,7 +99,10 @@ export class WorkspaceAdd extends React.Component { ...@@ -99,7 +99,10 @@ export class WorkspaceAdd extends React.Component {
</Typography> </Typography>
</Toolbar> </Toolbar>
</AppBar> </AppBar>
<ManifestForm onCancel={() => (this.setAddResourcesVisibility(false))} /> <ManifestForm
onSubmit={() => (this.setAddResourcesVisibility(false))}
onCancel={() => (this.setAddResourcesVisibility(false))}
/>
</Paper> </Paper>
</Drawer> </Drawer>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment