Skip to content

Commit

Permalink
fix: add better policy step tests (#1224)
Browse files Browse the repository at this point in the history
* fix: add better policy step tests

* fix tests

- the factories are filling in data where the fixtures are silent, so the pmcParticipation field on journal was being filled in as A by default.
- we should be explicit when creating the journal via the type in method in the journal field in the acceptance tests to pass in pmcPartificpation method

* lol name the test file correctly

* make the journal test real
  • Loading branch information
jaredgalanis authored Oct 13, 2023
1 parent 5dea5f9 commit 86f3fc3
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 89 deletions.
27 changes: 11 additions & 16 deletions app/components/policy-card/index.hbs
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
{{! template-lint-disable link-rel-noopener no-action no-triple-curlies require-input-label }}
<div class="card w-100 my-2" {{did-insert this.setup}}>
<div class="card-body">
<h4 class="card-title" data-test-policy-title>
<a href="#">
{{@policy.title}}
</a>
</h4>
{{#if this.policyIsJHU}}
<h4 class="card-title">
<a href="#">
{{@policy.title}}
</a>
</h4>
<h6 class="card-subtitle mb-2">
<h6 class="card-subtitle mb-2" data-test-jhu-policy-deposit-expectation>
Expects deposit into an open access repository
</h6>
{{else}}
<h4 class="card-title">
<a href="#">
{{@policy.title}}
</a>
</h4>
<h6 class="card-subtitle mb-2">
<h6 class="card-subtitle mb-2" data-test-policy-deposit-expectation>
Requires deposit into
{{#each @policy.repositories as |repo index|}}
{{if index ", "}}{{repo.name}}
{{/each}}
</h6>
{{/if}}
<p class="card-text mt-2">
<p class="card-text mt-2" data-test-policy-description>
{{{@policy.description}}}
{{#if @policy.policyUrl}}
<br />
<br />
For more information, see their official policy below.
<br />
<a href={{@policy.policyUrl}} target="_blank">
<a href={{@policy.policyUrl}} target="_blank" data-test-policy-url>
{{@policy.policyUrl}}
</a>
{{/if}}
<br />
<br />
{{#if this.usesPmcRepository}}
{{#if this.methodAJournal}}
<div class="alert alert-success">
<div class="alert alert-success" data-test-method-a-journal-pmc-intro>
The journal you published in participates in the PMC Method A program, and will submit the published article
to PMC on your behalf.
<em>
Expand All @@ -47,7 +42,7 @@
</em>
</div>
{{else}}
<div class="alert alert-info">
<div class="alert alert-info" data-test-non-method-a-journal-pmc-intro>
<p>
Some journals would submit your article to PMC on your behalf, for a fee. Specific arrangements would be
required. Please indicate below whether or not you have made an arrangement with the publisher to have
Expand Down
2 changes: 1 addition & 1 deletion app/components/workflow-policies/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<button class="btn btn-outline-primary" data-test-workflow-policies-back {{action @back}}>
Back
</button>
<button class="btn btn-outline-danger ml-2" {{action "cancel"}}>
<button class="btn btn-outline-danger ml-2" data-test-workflow-policies-cancel {{action "cancel"}}>
Cancel
</button>
<button class="btn btn-primary next pull-right" data-test-workflow-policies-next {{action @next}}>
Expand Down
6 changes: 1 addition & 5 deletions app/models/journal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/* eslint-disable ember/no-computed-properties-in-native-classes */
import Model, { attr } from '@ember-data/model';
import { computed } from '@ember/object';

/**
* Publisher participation in NIH Public Access Program by sending final published article to PMC.
*
* Possible values:
* - A (Route A: journal automatically post paper to PMC)
* - B (Route B: authors must make special arrangements for some journals and publishers to post the paper directly to PMC)
* - C (Route C: authors or deignee must submit manuscripts to NIHMS)
* - C (Route C: authors or designee must submit manuscripts to NIHMS)
* - D (Route D: some publishers will submit manuscripts to NIHMS)
*/
const PMCParticipation = {
Expand All @@ -27,12 +25,10 @@ export default class JournalModel extends Model {
@attr('string') pmcParticipation;
@attr('set') issns;

@computed('pmcParticipation')
get isMethodA() {
return this.pmcParticipation ? this.pmcParticipation === PMCParticipation.A : false;
}

@computed('pmcParticipation')
get isMethodB() {
return this.pmcParticipation ? this.pmcParticipation === PMCParticipation.B : false;
}
Expand Down
1 change: 0 additions & 1 deletion app/models/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default class PolicyModel extends Model {

@hasMany('repository') repositories;
@attr('string') institution;
// funder: DS.hasMany('funder'),

@attr('string') _type;
}
3 changes: 3 additions & 0 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,10 @@ export default function (config) {
issns: ['Print:0003-2654', 'Online:1364-5528'],
journalName: 'The Analyst',
nlmta: 'Analyst',
pmcParticipation: 'B',
});

server.loadFixtures();

return server;
}
11 changes: 11 additions & 0 deletions mirage/factories/journal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Factory } from 'miragejs';
import { faker } from '@faker-js/faker';

const JournalFactory = Factory.extend({
journalName: `${faker.word.noun()} Journal`,
nlmta: faker.word.noun(),
pmcParticipation: 'A',
issns: `${faker.string.numeric(4)}-${faker.string.numeric(4)}`,
});

export default JournalFactory;
11 changes: 11 additions & 0 deletions mirage/factories/policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Factory } from 'miragejs';
import { faker } from '@faker-js/faker';

const PolicyFactory = Factory.extend({
title: `${faker.word.noun()} Policy`,
description: faker.lorem.sentences(),
policyUrl: faker.internet.url(),
institution: `${faker.word.noun()} Institution`,
});

export default PolicyFactory;
12 changes: 12 additions & 0 deletions mirage/factories/publication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Factory } from 'miragejs';
import { faker } from '@faker-js/faker';

const PublicationFactory = Factory.extend({
volume: faker.string.numeric(1),
issue: faker.string.numeric(2),
pmid: faker.string.numeric(8),
title: faker.lorem.sentences(),
doi: '10.1089/ars.2015.6327',
});

export default PublicationFactory;
13 changes: 13 additions & 0 deletions mirage/factories/repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Factory } from 'miragejs';
import { faker } from '@faker-js/faker';

const RepositoryFactory = Factory.extend({
name: `${faker.word.noun()} Repository`,
description: faker.lorem.sentences(),
url: faker.internet.url(),
formSchema: '',
integrationType: 'FULL',
repositoryKey: 'pmc',
});

export default RepositoryFactory;
14 changes: 14 additions & 0 deletions mirage/factories/submission.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Factory } from 'miragejs';
import { faker } from '@faker-js/faker';

const SubmissionFactory = Factory.extend({
aggregatedDepositStatus: 'not-started',
submittedDate: faker.date.anytime(),
source: 'pass',
metadata: '',
submitted: false,
submitterName: 'Nihu User',
submitterEmail: '[email protected]',
});

export default SubmissionFactory;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@ember/optional-features": "^2.0.0",
"@ember/render-modifiers": "^2.0.5",
"@ember/test-helpers": "^2.8.1",
"@faker-js/faker": "^8.1.0",
"@fortawesome/ember-fontawesome": "^0.4.3",
"@fortawesome/free-regular-svg-icons": "^6.4.0",
"@glimmer/component": "^1.1.2",
Expand Down Expand Up @@ -93,7 +94,6 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-qunit": "^7.3.1",
"faker": "^6.6.6",
"husky": "^8.0.0",
"jquery": "^3.6.4",
"lint-staged": "^13.2.3",
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/nih-submission-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module('Acceptance | submission', function (hooks) {

await waitFor('[data-test-metadata-form] textarea[name=title]');
assert.strictEqual(currentURL(), '/submissions/new/metadata');

assert
.dom('[data-test-metadata-form] textarea[name=title]')
.hasValue(
Expand Down
105 changes: 69 additions & 36 deletions tests/integration/components/policy-card-test.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
/* eslint-disable ember/no-get */
import { A } from '@ember/array';
import EmberObject, { get } from '@ember/object';
import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { module, test } from 'qunit';
import { render, click } from '@ember/test-helpers';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';

module('Integration | Component | policy card', (hooks) => {
setupRenderingTest(hooks);
setupMirage(hooks);

hooks.beforeEach(function () {
this.store = this.owner.lookup('service:store');
});

test('it renders when given expected data', async function (assert) {
const policy = EmberObject.create({
repositories: A(),
description: 'This is a moo-scription',
title: 'Moo title',
id: 1,
const submissionAttrs = this.server.create('submission').attrs;
const submission = this.store.createRecord('submission', submissionAttrs);
const repositoryFactory = this.server.create('repository');
const policyFactory = this.server.create('policy', {
repositories: [repositoryFactory],
});
const journalFactory = this.server.create('journal', { pmcParticipation: 'B' });

const journal = EmberObject.create({
isMethodA: false,
});
const submission = EmberObject.create({
effectivePolicies: A(),
const repository = this.store.createRecord('repository', repositoryFactory.attrs);
const policy = this.store.createRecord('policy', {
...policyFactory.attrs,
description: 'This is a moo-scription',
title: 'Moo title',
repositories: [repository],
});
const journal = this.store.createRecord('journal', journalFactory.attrs);

this.set('submission', submission);
this.set('policy', policy);
this.set('journal', journal);
this.set('submission', submission);
this.set('repository', repository);

await render(hbs`<PolicyCard @policy={{this.policy}} @journal={{this.journal}} @submission={{this.submission}} />`);

Expand All @@ -36,36 +43,39 @@ module('Integration | Component | policy card', (hooks) => {

module('PMC tests', (hooks) => {
hooks.beforeEach(function () {
const policy = EmberObject.create({
repositories: A([
EmberObject.create({
repositoryKey: 'pmc',
}),
]),
const submissionAttrs = this.server.create('submission').attrs;
const submission = this.store.createRecord('submission', submissionAttrs);
const repositoryFactory = this.server.create('repository', { repositoryKey: 'pmc' });
const policyFactory = this.server.create('policy', {
repositories: [repositoryFactory],
});
const journalFactory = this.server.create('journal', { pmcParticipation: 'B' });

const repository = this.store.createRecord('repository', repositoryFactory.attrs);
const policy = this.store.createRecord('policy', {
...policyFactory.attrs,
description: 'This is a moo-scription',
title: 'Moo title',
repositories: [repository],
});
const journal = EmberObject.create({
isMethodA: false,
});
const submission = EmberObject.create({
effectivePolicies: A(),
});
const journal = this.store.createRecord('journal', journalFactory.attrs);

this.set('submission', submission);
this.set('policy', policy);
this.set('journal', journal);
this.set('submission', submission);
this.set('repository', repository);
});

test('PMC journal displays user input', async function (assert) {
await render(
hbs`<PolicyCard @policy={{this.policy}} @journal={{this.journal}} @submission={{this.submission}} />`
);

const inputs = this.element.querySelectorAll('input');
assert.strictEqual(inputs.length, 2, `Found ${inputs.length} inputs, but was expecting 2`);
assert.dom('[data-test-workflow-policies-radio-no-direct-deposit]').exists();
assert.dom('[data-test-workflow-policies-radio-direct-deposit]').exists();

const effectivePolicies = this.submission.effectivePolicies;

const effectivePolicies = get(this, 'submission.effectivePolicies');
assert.strictEqual(effectivePolicies.length, 1, 'Should be ONE effective policy on submission');
assert.ok(effectivePolicies.isAny('title', 'Moo title'));
});
Expand All @@ -79,24 +89,47 @@ module('Integration | Component | policy card', (hooks) => {
assert.strictEqual(inputs.length, 2, `Found ${inputs.length} inputs, but was expecting 2`);

// Select option to remove this policy
await click(inputs[1]);
await click('[data-test-workflow-policies-radio-direct-deposit]');

const effectivePolicies = get(this, 'submission.effectivePolicies');
const effectivePolicies = this.submission.effectivePolicies;
assert.strictEqual(effectivePolicies.length, 0, 'Should be ZERO effective policies');
});

test('PMC type A journal as no inputs and is not added to submission', async function (assert) {
this.set('journal', EmberObject.create({ isMethodA: true }));
const repositoryFactory = this.server.create('repository', { repositoryKey: 'pmc' });
const policyFactory = this.server.create('policy', {
repositories: [repositoryFactory],
});
const journalFactory = this.server.create('journal', { pmcParticipation: 'A' });

const repository = this.store.createRecord('repository', repositoryFactory.attrs);
const policy = this.store.createRecord('policy', {
...policyFactory.attrs,
description: 'This is a moo-scription',
title: 'Moo title',
repositories: [repository],
});
const journal = this.store.createRecord('journal', journalFactory.attrs);

this.set('policy', policy);
this.set('journal', journal);
this.set('repository', repository);

await render(
hbs`<PolicyCard @policy={{this.policy}} @journal={{this.journal}} @submission={{this.submission}} />`
);
assert.ok(this.element, 'failed to render');

const inputs = this.element.querySelectorAll('input');
assert.strictEqual(inputs.length, 0, 'should be ZERO input options rendered');
assert
.dom('[data-test-method-a-journal-pmc-intro]')
.containsText(
'The journal you published in participates in the PMC Method A program, and will submit the published article to PMC on your behalf.'
);

assert.dom('[data-test-workflow-policies-radio-no-direct-deposit]').doesNotExist();
assert.dom('[data-test-workflow-policies-radio-direct-deposit]').doesNotExist();

assert.strictEqual(get(this, 'submission.effectivePolicies').length, 0, 'should be ZERO effective policies set');
assert.strictEqual(this.submission.effectivePolicies.length, 0, 'should be ZERO effective policies set');
});
});
});
Loading

0 comments on commit 86f3fc3

Please sign in to comment.