diff --git a/app/components/metadata-form/index.hbs b/app/components/metadata-form/index.hbs index b2726357..a6506de7 100644 --- a/app/components/metadata-form/index.hbs +++ b/app/components/metadata-form/index.hbs @@ -1 +1,8 @@ -
\ No newline at end of file +
+
\ No newline at end of file diff --git a/app/components/metadata-form/index.js b/app/components/metadata-form/index.js index a9293602..e6929c3b 100644 --- a/app/components/metadata-form/index.js +++ b/app/components/metadata-form/index.js @@ -1,13 +1,12 @@ -/* eslint-disable ember/no-classic-components, ember/no-classic-classes, ember/require-tagless-components, ember/no-component-lifecycle-hooks, ember/no-get */ -import Component from '@ember/component'; -import _ from 'lodash'; -import { get } from '@ember/object'; +import Component from '@glimmer/component'; +import stripEmptyArrays from 'pass-ui/util/strip-empty-arrays'; +import { action } from '@ember/object'; -export default Component.extend({ - didRender() { - this._super(...arguments); - const that = this; - const originalForm = get(this, 'schema'); +export default class MetadataForm extends Component { + @action + setupMetadataForm() { + const componentContext = this; + const originalForm = this.args.schema; const newForm = JSON.parse(JSON.stringify(originalForm)); if (!originalForm.options) { newForm.options = {}; @@ -20,21 +19,21 @@ export default Component.extend({ title: 'Back', styles: 'pull-left btn btn-outline-primary', click() { - that.previousForm(that.stripEmptyArrays(this.getValue())); + componentContext.args.previousForm(stripEmptyArrays(this.getValue())); }, }, Abort: { label: 'Cancel', styles: 'pull-left btn btn-outline-danger ml-2', click() { - that.cancel(); + componentContext.args.cancel(); }, }, Next: { label: 'Next', styles: 'pull-right btn btn-primary next', click() { - that.nextForm(that.stripEmptyArrays(this.getValue())); + componentContext.args.nextForm(stripEmptyArrays(this.getValue())); }, }, }, @@ -44,20 +43,5 @@ export default Component.extend({ $('#schemaForm').empty(); $('#schemaForm').alpaca(newForm); - }, - - /** - * Remove empty array values from a JSON object. Keys that have a value of an empty - * array will be removed. Does not dive into object values. - * - * @param {JSONObject} object - */ - stripEmptyArrays(object) { - Object.keys(object) - .filter((key) => Array.isArray(object[key]) && object[key].length === 0) - .forEach((key) => { - delete object[key]; - }); - return object; - }, -}); + } +} diff --git a/app/util/strip-empty-arrays.js b/app/util/strip-empty-arrays.js new file mode 100644 index 00000000..a1d85825 --- /dev/null +++ b/app/util/strip-empty-arrays.js @@ -0,0 +1,14 @@ +/** + * Remove empty array values from a JSON object. Keys that have a value of an empty + * array will be removed. Does not dive into object values. + * + * @param {JSONObject} object + */ +export default function (object) { + Object.keys(object) + .filter((key) => Array.isArray(object[key]) && object[key].length === 0) + .forEach((key) => { + delete object[key]; + }); + return object; +} diff --git a/tests/integration/components/external-repo-review-test.js b/tests/integration/components/external-repo-review-test.js index 0e4e804a..484d195e 100644 --- a/tests/integration/components/external-repo-review-test.js +++ b/tests/integration/components/external-repo-review-test.js @@ -40,8 +40,8 @@ module('Integration | Component | external-repo-review', (hooks) => { await click(btn[0]); - await waitFor(document.querySelector('button.swal2-confirm')); - await click(document.querySelector('button.swal2-confirm')); + await waitFor('button.swal2-confirm'); + await click('button.swal2-confirm'); assert.dom(btn[0]).doesNotHaveClass('font-weight-bold'); }); @@ -55,13 +55,13 @@ module('Integration | Component | external-repo-review', (hooks) => { assert.equal(btn.length, 2, 'Should have 2 list elements for repos'); await click(btn[0]); - await waitFor(document.querySelector('button.swal2-confirm')); - await click(document.querySelector('button.swal2-confirm')); + await waitFor('button.swal2-confirm'); + await click('button.swal2-confirm'); await click(btn[1]); - await waitFor(document.querySelector('button.swal2-confirm')); - await click(document.querySelector('button.swal2-confirm')); + await waitFor('button.swal2-confirm'); + await click('button.swal2-confirm'); assert.dom('i.fa-exclamation-triangle').doesNotExist(); assert.dom('button.font-weight-bold').doesNotExist('There should be no bolded repo links'); diff --git a/tests/integration/components/metadata-form-test.js b/tests/integration/components/metadata-form-test.js index bc5496a3..9da36a15 100644 --- a/tests/integration/components/metadata-form-test.js +++ b/tests/integration/components/metadata-form-test.js @@ -2,6 +2,7 @@ import { setupRenderingTest } from 'ember-qunit'; import hbs from 'htmlbars-inline-precompile'; import { module, test } from 'qunit'; import { render } from '@ember/test-helpers'; +import stripEmptyArrays from 'pass-ui/util/strip-empty-arrays'; module('Integration | Component | metadata-form', (hooks) => { setupRenderingTest(hooks); @@ -43,8 +44,6 @@ module('Integration | Component | metadata-form', (hooks) => { }); test('Test "stripEmptyArrays"', function (assert) { - const component = this.owner.lookup('component:metadata-form'); - const obj = { one: [], two: ['moo'], @@ -54,7 +53,7 @@ module('Integration | Component | metadata-form', (hooks) => { six: {}, seven: { moo: [] }, }; - const result = component.stripEmptyArrays(obj); + const result = stripEmptyArrays(obj); assert.notOk('one' in result); assert.ok('two' in result); diff --git a/tests/integration/components/workflow-files-test.js b/tests/integration/components/workflow-files-test.js index 89ed1193..34359d2e 100644 --- a/tests/integration/components/workflow-files-test.js +++ b/tests/integration/components/workflow-files-test.js @@ -1,6 +1,6 @@ /* eslint-disable ember/no-classic-classes */ import { selectFiles } from 'ember-file-upload/test-support'; -import EmberObject, { set } from '@ember/object'; +import { set } from '@ember/object'; import { setupRenderingTest } from 'ember-qunit'; import hbs from 'htmlbars-inline-precompile'; import { module, test } from 'qunit'; diff --git a/tests/integration/components/workflow-metadata-test.js b/tests/integration/components/workflow-metadata-test.js index 993e196d..662e3d21 100644 --- a/tests/integration/components/workflow-metadata-test.js +++ b/tests/integration/components/workflow-metadata-test.js @@ -6,7 +6,7 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import hbs from 'htmlbars-inline-precompile'; import { run } from '@ember/runloop'; -import { getContext, click, render, fillIn, waitFor, waitUntil, find } from '@ember/test-helpers'; +import { getContext, click, render, fillIn, waitFor, waitUntil, find, settled } from '@ember/test-helpers'; import { setupMirage } from 'ember-cli-mirage/test-support'; let submission; @@ -198,6 +198,7 @@ module('Integration | Component | workflow-metadata', (hooks) => { assert.dom(this.element).includesText('Common schema title moo'); await click('[data-key="Next"]'); await waitFor('input[name="journal-NLMTA-ID"]'); + await settled(); assert.dom(this.element).doesNotIncludeText('Common schema title moo'); assert.dom(this.element).includesText('NIH Manuscript Submission System'); assert.dom('input[name="journal-NLMTA-ID"]').exists(); @@ -239,6 +240,7 @@ module('Integration | Component | workflow-metadata', (hooks) => { await render(hbs``); await waitFor('[data-key="Next"]'); + await settled(); await click('[data-key="Next"]'); // Need to fill out ISSN field @@ -247,11 +249,11 @@ module('Integration | Component | workflow-metadata', (hooks) => { await click('button[data-key="Next"]'); - await waitFor(document.querySelector('.swal2-confirm')); + await waitFor('.swal2-confirm'); - assert.dom(document.querySelector('.swal2-title')).includesText('Form Validation Error'); - assert.dom(document.querySelector('.swal2-content')).includesText('should be string'); - await click(document.querySelector('.swal2-confirm')); + assert.dom('.swal2-title').includesText('Form Validation Error'); + assert.dom('.swal2-content').includesText('should be string'); + await click('.swal2-confirm'); }); test('Back button on J10P form takes you back to NIH form', async function (assert) { @@ -325,8 +327,8 @@ module('Integration | Component | workflow-metadata', (hooks) => { await waitFor('[data-key="Back"]'); await waitFor('[data-key="Abort"]'); await click('button[data-key="Next"]'); - await waitFor(document.querySelector('.swal2-confirm')); - await click(document.querySelector('.swal2-confirm')); + await waitFor('.swal2-confirm'); + await click('.swal2-confirm'); assert.dom(this.element).includesText('NIHMS'); }); @@ -420,42 +422,6 @@ module('Integration | Component | workflow-metadata', (hooks) => { assert.ok(issnInput.value, '123Moo', 'Unexpected ISSN value found'); }); - /** - * DOI data should have invalid keys removed when translated to the 'workflow-metadata' - * metadata property. The mock Schema Service defined in #beforeEach above will define - * a set of valid fields that does NOT include the property 'badMoo'. This property - * then should not exist in the component's metadata blob. - */ - test('DOI data should be trimmed', async function (assert) { - const mockWorkflow = Service.extend({ - getDoiInfo() { - return { - ISSN: '1234-4321', - 'journal-NLMTA-ID': 'MOO JOURNAL', - mooName: 'This is a moo', - badMoo: 'Sad moo', - }; - }, - isDataFromCrossref: () => false, - }); - - this.owner.unregister('service:workflow'); - this.owner.register('service:workflow', mockWorkflow); - - await render(hbs``); - - assert.ok(true, 'Failed to render'); - - let { owner } = getContext(); - let component = owner.lookup('component:metadata-form'); - - assert.notOk(component.metadata, 'No component metadata found'); - assert.notOk( - get(component, 'metadata.badMoo'), - 'metadata.badMoo property should not be found on the metadata object', - ); - }); - test('Metadata merges should be able to remove fields', async function (assert) { await render(hbs``); diff --git a/tests/integration/components/workflow-review-test.js b/tests/integration/components/workflow-review-test.js index 2c90f461..72fc0fd1 100644 --- a/tests/integration/components/workflow-review-test.js +++ b/tests/integration/components/workflow-review-test.js @@ -163,13 +163,13 @@ module('Integration | Component | workflow review', (hooks) => { // Click on submit await click('.submit'); - await click(document.querySelector('.swal2-confirm')); + await click('.swal2-confirm'); - await waitFor(document.querySelector('.swal2-validationerror')); - assert.dom(document.querySelector('.swal2-validationerror')).containsText('You need to choose something!'); + await waitFor('.swal2-validationerror'); + assert.dom('.swal2-validationerror').containsText('You need to choose something!'); - await waitFor(document.querySelector('.swal2-container')); - await click(document.querySelector('.swal2-container')); + await waitFor('.swal2-container'); + await click('.swal2-container'); }); test('submission success: web-link and agreement', async function (assert) { @@ -227,7 +227,7 @@ module('Integration | Component | workflow review', (hooks) => { // Click on web-link repository and then confirm await click('[data-test-repo-link-button]'); - await click(document.querySelector('.swal2-confirm')); + await click('.swal2-confirm'); assert.dom('[data-test-workflow-review-submit]').isNotDisabled(); @@ -235,12 +235,12 @@ module('Integration | Component | workflow review', (hooks) => { await click('.submit'); // Click on deposit agreement checkbox and then next - await waitFor(document.querySelector('.swal2-radio label:nth-child(1) input[type="radio"]')); - await click(document.querySelector('.swal2-radio label:nth-child(1) input[type="radio"]')); - await click(document.querySelector('.swal2-confirm')); + await waitFor('.swal2-radio label:nth-child(1) input[type="radio"]'); + await click('.swal2-radio label:nth-child(1) input[type="radio"]'); + await click('.swal2-confirm'); // Click on confirm submission - await click(document.querySelector('.swal2-confirm')); + await click('.swal2-confirm'); assert.true(submitted); @@ -364,17 +364,17 @@ module('Integration | Component | workflow review', (hooks) => { await click('.submit'); // Click the second radio indicating submit without agreeing to deposit agreement - await waitFor(document.querySelector('.swal2-radio label:nth-child(2) input[type="radio"]')); - await click(document.querySelector('.swal2-radio label:nth-child(2) input[type="radio"]')); + await waitFor('.swal2-radio label:nth-child(2) input[type="radio"]'); + await click('.swal2-radio label:nth-child(2) input[type="radio"]'); // Click Next without agreeing - await click(document.querySelector('.swal2-confirm')); + await click('.swal2-confirm'); // Should be warning about no deposit agreement - assert.strictEqual(document.querySelector('.swal2-title').textContent, 'Your submission cannot be submitted.'); - assert.true(document.querySelector('.swal2-content').textContent.includes(repo1.get('name'))); + assert.dom('.swal2-title').includesText('Your submission cannot be submitted.'); + assert.dom('.swal2-content').includesText(repo1.name); - await click(document.querySelector('.swal2-confirm')); + await click('.swal2-confirm'); assert.false(submitted); }); diff --git a/tests/unit/services/doi-test.js b/tests/unit/services/doi-test.js index d8666e3f..e6f83e46 100644 --- a/tests/unit/services/doi-test.js +++ b/tests/unit/services/doi-test.js @@ -58,12 +58,6 @@ module('Unit | Service | doi', (hooks) => { }); }); - // Replace this with your real tests. - test('it exists', function (assert) { - let service = this.owner.lookup('service:doi'); - assert.ok(service); - }); - // Test DOI object here based on CrossRef data test('check doi data processing', function (assert) { const service = this.owner.lookup('service:doi'); diff --git a/tests/unit/services/metadata-schema-test.js b/tests/unit/services/metadata-schema-test.js index d9f499c9..edd8e35a 100644 --- a/tests/unit/services/metadata-schema-test.js +++ b/tests/unit/services/metadata-schema-test.js @@ -76,8 +76,8 @@ module('Unit | Service | metadata-schema', (hooks) => { test('Should retry request without merge query param on failure', async function (assert) { this.server.get('/schema', (_schema, request) => { - if (request.queryParams.merge) { - return Response(500); + if (request.queryParams.merge === 'true') { + return new Response(500); } return [this.mockSchema]; });