Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First cut at saving between metadata forms #974

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions app/components/workflow-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ export default Component.extend({
swal({
type: 'error',
title: 'Form Validation Error',
text: this.validationErrorMsg(schemaService.getErrors())
html: this.validationErrorMsg(schemaService.getErrors())
});
return;
}

this.saveMetadata();

if (step >= this.get('schemas').length - 1) {
this.finalizeMetadata(metadata);
this.sendAction('next');
Expand Down Expand Up @@ -207,8 +209,24 @@ export default Component.extend({
agent_information: this.getBrowserInfo()
});

const finalMetadata = this.get('metadata');
this.set('submission.metadata', JSON.stringify(finalMetadata));
this.saveMetadata();
},

saveMetadata() {
let shouldPersist = true;
const md = this.get('metadata');
try {
const subMD = JSON.parse(this.get('submission.metadata'));

shouldPersist = !_.isEqual(md, subMD);
} catch (e) {
shouldPersist = true;
}
// console.log(`Saving metadata. Should persist? ${shouldPersist}`);
this.set('submission.metadata', JSON.stringify(this.get('metadata')));
if (shouldPersist) {
this.get('submission').save();
}
},

/**
Expand Down
26 changes: 24 additions & 2 deletions tests/integration/components/workflow-metadata-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { run } from '@ember/runloop';
import { click, render } from '@ember/test-helpers';
import { click, render, fillIn } from '@ember/test-helpers';

module('Integration | Component | workflow-metadata', (hooks) => {
setupRenderingTest(hooks);
Expand All @@ -17,7 +17,8 @@ module('Integration | Component | workflow-metadata', (hooks) => {
});
const submission = Ember.Object.create({
repositories,
publication
publication,
save: () => Promise.resolve()
});

this.set('submission', submission);
Expand Down Expand Up @@ -363,4 +364,25 @@ module('Integration | Component | workflow-metadata', (hooks) => {
assert.notOk(metadata.badMoo, 'metadata.badMoo property should not be found on the metadata object');
});
});

test('Should persist changes on Next Form', async function (assert) {
assert.expect(1); // The assertion in save() should run once

const submission = Ember.Object.create({
publication: this.get('publication'),
repositories: this.get('repositories'),
save: () => {
assert.ok(true);
return Promise.resolve();
}
});
this.set('submission', submission);

run(async () => {
await render(hbs`{{workflow-metadata submission=submission publication=publication}}`);

await fillIn('input[name="journal-NLMTA-ID"]', 'MOO ID');
await click('button[data-key="Next"]');
});
});
});