Skip to content

Commit

Permalink
one test left
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredgalanis committed Jul 9, 2024
1 parent f141419 commit ad44ce7
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 107 deletions.
9 changes: 8 additions & 1 deletion app/components/metadata-form/index.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<div id="schemaForm" class="alpaca-form form-group" data-test-metadata-form></div>
<div
id="schemaForm"
class="alpaca-form form-group"
data-test-metadata-form
{{did-insert this.setupMetadataForm}}
{{did-update this.setupMetadataForm @schema}}
>
</div>
42 changes: 13 additions & 29 deletions app/components/metadata-form/index.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand All @@ -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()));
},
},
},
Expand All @@ -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;
},
});
}
}
14 changes: 14 additions & 0 deletions app/util/strip-empty-arrays.js
Original file line number Diff line number Diff line change
@@ -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;
}
12 changes: 6 additions & 6 deletions tests/integration/components/external-repo-review-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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');
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/components/metadata-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'],
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/workflow-files-test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
52 changes: 9 additions & 43 deletions tests/integration/components/workflow-metadata-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -239,6 +240,7 @@ module('Integration | Component | workflow-metadata', (hooks) => {

await render(hbs`<WorkflowMetadata @submission={{this.submission}} @publication={{this.publication}} />`);
await waitFor('[data-key="Next"]');
await settled();
await click('[data-key="Next"]');

// Need to fill out ISSN field
Expand All @@ -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) {
Expand Down Expand Up @@ -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');
});
Expand Down Expand Up @@ -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`<WorkflowMetadata @submission={{this.submission}} @publication={{this.publication}} />`);

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`<WorkflowMetadata @submission={{this.submission}} @publication={{this.publication}} />`);

Expand Down
32 changes: 16 additions & 16 deletions tests/integration/components/workflow-review-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -227,20 +227,20 @@ 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();

// Click on submit
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);

Expand Down Expand Up @@ -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);
});
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/services/doi-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/services/metadata-schema-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
});
Expand Down

0 comments on commit ad44ce7

Please sign in to comment.