-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update preprint-doi component to handle versions
- Loading branch information
1 parent
500e4bd
commit 738dd01
Showing
7 changed files
with
146 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
<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 | ||
@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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters