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

[ENG-6448] Update preprint-doi component to handle versions #2420

Merged
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
82 changes: 82 additions & 0 deletions app/preprints/-components/preprint-doi/component-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { click } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { ModelInstance } from 'ember-cli-mirage';

import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';
import PreprintModel from 'ember-osf-web/models/preprint';

module('Integration | Component | preprint-doi', function(hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);

test('it renders', async function(assert) {
this.store = this.owner.lookup('service:store');
server.loadFixtures('preprint-providers');
const mirageProvider = server.schema.preprintProviders.find('osf') as ModelInstance<PreprintProviderModel>;
const miragePreprint = server.create('preprint', {
id: 'doied',
provider: mirageProvider,
}, 'withVersions');
// Version 1 has a DOI and has a preprintDoiCreated date
const version1 = server.schema.preprints.find('doied_v1') as ModelInstance<PreprintModel>;
version1.update({ preprintDoiCreated: new Date('2020-02-02') });
// Version 2 has a DOI but no preprintDoiCreated date
const version2 = server.schema.preprints.find('doied_v2') as ModelInstance<PreprintModel>;
version2.update({ preprintDoiCreated: null });
// Version 3 is pending moderator approval and is not published, therefore has no DOI
const version3 = server.schema.preprints.find('doied_v3') as ModelInstance<PreprintModel>;
version3.update({
preprintDoiCreated: null,
isPublished: false,
isPreprintDoi: false, // Mirage flag used to determine if a DOI should be created
});

const preprint = await this.store.findRecord('preprint', miragePreprint.id);
const versions = await preprint.queryHasMany('versions');

const provider = await this.store.findRecord('preprint-provider', mirageProvider.id);
this.set('versions', versions);
this.set('provider', provider);

await render(hbs`
<Preprints::-Components::PreprintDoi
@versions={{this.versions}}
@provider={{this.provider}}
/>
`);

// check headings exist
assert.dom('[data-test-preprint-doi-heading]').exists('Preprint DOI heading exists');
assert.dom('[data-test-preprint-doi-heading]').hasText('Preprint DOI', 'Preprint DOI heading has correct text');

// check dropdown exists
assert.dom('[data-test-version-select-dropdown]').exists('Version select dropdown exists');
assert.dom('[data-test-version-select-dropdown]')
.hasText('Version 3', 'Dropdown has latest version selected by default');

// check version3 has no DOI
assert.dom('[data-test-no-doi-text]').exists('No DOI text exists');
assert.dom('[data-test-no-doi-text]').hasText('DOI created after moderator approval', 'No DOI text is correct');

// check version2 has DOI, but no preprintDoiCreated date
await click('[data-test-version-select-dropdown]');
await click('[data-test-preprint-version="2"]');
assert.dom('[data-test-no-doi-text]').doesNotExist('No DOI text does not exist');
assert.dom('[data-test-unlinked-doi-url]').exists('Preprint DOI URL exists');
assert.dom('[data-test-unlinked-doi-description]').exists('Preprint DOI description exists');
assert.dom('[data-test-unlinked-doi-description]')
// eslint-disable-next-line max-len
.hasText('DOIs are minted by a third party, and may take up to 24 hours to be registered.', 'Description is correct');

// check version1 has DOI and preprintDoiCreated date
await click('[data-test-version-select-dropdown]');
await click('[data-test-preprint-version="1"]');
assert.dom('[data-test-unlinked-doi-url]').doesNotExist('Unlinked preprint DOI URL does not exist');
assert.dom('[data-test-unlinked-doi-description]').doesNotExist('Unlinked description does not exist');
assert.dom('[data-test-linked-doi-url]').exists('Preprint DOI URL exists');
});
});
12 changes: 10 additions & 2 deletions app/preprints/-components/preprint-doi/component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import PreprintModel from 'ember-osf-web/models/preprint';
import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';

interface InputArgs {
preprint: PreprintModel;
versions: PreprintModel[];
provider: PreprintProviderModel;
}

export default class PreprintAbstract extends Component<InputArgs> {
provider = this.args.provider;
documentType = this.provider.documentType.singularCapitalized;

documentType = this.provider.documentType.singular;
@tracked selectedVersion = this.args.versions[0];

@action
selectVersion(version: PreprintModel) {
this.selectedVersion = version;
}
}
4 changes: 4 additions & 0 deletions app/preprints/-components/preprint-doi/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.version-dropdown {
margin-bottom: 12px;
width: 120px;
}
62 changes: 44 additions & 18 deletions app/preprints/-components/preprint-doi/template.hbs
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
<div>
<h4>{{t 'preprints.detail.preprint_doi' documentType=this.documentType}}</h4>
{{#if @preprint.preprintDoiUrl}}
{{#if @preprint.preprintDoiCreated}}
<OsfLink
data-test-article-doi
data-analytics-name='preprint doi'
@href={{@preprint.preprintDoiUrl}}
<h4 data-test-preprint-doi-heading>
{{t 'preprints.detail.preprint_doi' documentType=this.documentType}}
</h4>
{{#if @versions}}
<PowerSelect
data-test-version-select-dropdown
local-class='version-dropdown'
@options={{@versions}}
@selected={{this.selectedVersion}}
@onChange={{this.selectVersion}}
as |version|
>
<span
data-test-preprint-version={{version.preprintVersion}}
>
{{@preprint.preprintDoiUrl}}
</OsfLink>
{{else}}
<p> {{@preprint.preprintDoiUrl}} </p>
<p> {{t 'preprints.detail.preprint_pending_doi_minted'}} </p>
{{/if}}
{{t 'preprints.detail.version_doi_title' number=version.preprintVersion}}
</span>
</PowerSelect>
{{else}}
{{#if (not @preprint.public)}}
{{t 'preprints.detail.preprint_pending_doi' documentType=this.documentType}}
{{else if (and this.provider.reviewsWorkflow (not this.preprint.isPublished))}}
{{t 'preprints.detail.preprint_pending_doi_moderation'}}
<p>{{t 'preprints.detail.no_versions'}}</p>
{{/if}}
{{#if this.selectedVersion}}
{{#if this.selectedVersion.preprintDoiUrl}}
{{#if this.selectedVersion.preprintDoiCreated}}
<OsfLink
data-test-linked-doi-url
data-analytics-name='preprint doi'
@href={{this.selectedVersion.preprintDoiUrl}}
>
{{this.selectedVersion.preprintDoiUrl}}
</OsfLink>
{{else}}
<p data-test-unlinked-doi-url> {{this.selectedVersion.preprintDoiUrl}} </p>
<p data-test-unlinked-doi-description> {{t 'preprints.detail.preprint_pending_doi_minted'}} </p>
{{/if}}
{{else}}
<p data-test-no-doi-text>
{{#if (not this.selectedVersion.public)}}
{{t 'preprints.detail.preprint_pending_doi' documentType=this.documentType}}
{{else if (and this.provider.reviewsWorkflow (not this.preprint.isPublished))}}
{{t 'preprints.detail.preprint_pending_doi_moderation'}}
{{else}}
{{t 'preprints.detail.no_doi'}}
{{/if}}
</p>
{{/if}}
{{/if}}
</div>
</div>
5 changes: 4 additions & 1 deletion app/preprints/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@
</OsfLink>
</div>
{{/if}}
<Preprints::-Components::PreprintDoi @preprint={{this.model.preprint}} @provider={{this.model.provider}} />
<Preprints::-Components::PreprintDoi
@versions={{this.model.versions}}
@provider={{this.model.provider}}
/>
{{#if this.model.preprint.articleDoiUrl}}
<div>
<h4>{{t 'preprints.detail.article_doi'}}</h4>
Expand Down
4 changes: 3 additions & 1 deletion mirage/factories/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ export default Factory.extend<PreprintMirageModel & PreprintTraits>({
isLatestVersion: version === 3,
});
});
preprint.provider.update({ preprints: versionedPreprints });
if (preprint.provider) {
preprint.provider.update({ preprints: versionedPreprints });
}
},
}),

Expand Down
3 changes: 2 additions & 1 deletion mirage/views/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function getPreprintVersions(this: HandlerContext, schema: Schema) {
const baseId = preprintId.split('_v')[0]; // assumes preprint id is of the form <baseId>_v<versionNumber>
const preprints = schema.preprints.all().models
.filter((preprint: ModelInstance<PreprintModel>) => preprint.id !== baseId && preprint.id.includes(baseId));
const versions = preprints.sortBy('versionNumber').reverse();
return process(schema, this.request, this,
preprints.map((preprint: ModelInstance) => this.serialize(preprint).data));
versions.map((version: ModelInstance) => this.serialize(version).data));
}
2 changes: 2 additions & 0 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1431,8 +1431,10 @@ preprints:
original_publication_date: 'Original Publication Date'
orphan_preprint: 'The user has removed this file.'
preprint_doi: '{documentType} DOI'
version_doi_title: 'Version {number}'
preprint_pending_doi: 'DOI created after {documentType} is made public'
preprint_pending_doi_moderation: 'DOI created after moderator approval'
no_doi: 'No DOI'
preprint_pending_doi_minted: 'DOIs are minted by a third party, and may take up to 24 hours to be registered.'
private_preprint_warning: 'This {documentType} is private. Contact {supportEmail} if this is in error.'
project_button:
Expand Down
Loading