Skip to content

Commit

Permalink
Add/update tests (#2483)
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda authored Jan 21, 2025
1 parent df98061 commit c16996f
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 1 deletion.
102 changes: 102 additions & 0 deletions app/preprints/-components/withdrawal-preprint/component-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { click, fillIn, render, settled} from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { setupRenderingTest } from 'ember-qunit';
import {TestContext} from 'ember-intl/test-support';
import { module, test } from 'qunit';
import { setupIntl } from 'ember-intl/test-support';
import { PreprintProviderReviewsWorkFlow, ReviewsState } from 'ember-osf-web/models/provider';
import PreprintModel from 'ember-osf-web/models/preprint';
import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';
import { ModelInstance } from 'ember-cli-mirage';

interface ComopenntTestContext extends TestContext {
preprint: PreprintModel;
provider: PreprintProviderModel;
onWithdrawal: () => void;
}

module('Integration | Preprint | Component | withdrawal-preprint', hooks => {
setupRenderingTest(hooks);
setupMirage(hooks);
setupIntl(hooks);

test('it renders and shows appropriate text', async function(this: ComopenntTestContext, assert) {
this.store = this.owner.lookup('service:store');
this.intl = this.owner.lookup('service:intl');

server.loadFixtures('preprint-providers');
const mirageProvider = server.schema.preprintProviders.find('osf') as ModelInstance<PreprintProviderModel>;
const provider = await this.store.findRecord('preprint-provider', mirageProvider.id);

server.create('preprint', {
id: 'test',
reviewsState: ReviewsState.PENDING,
provider: mirageProvider,
});
const preprint = await this.store.findRecord('preprint', 'test');
const onWithdrawal = () => {/* noop */};
this.setProperties({
preprint,
provider,
onWithdrawal,
});
await render(hbs`
<Preprints::-Components::WithdrawalPreprint
@preprint={{this.preprint}}
@provider={{this.provider}}
@onWithdrawal={{this.onWithdrawal}}
/>
`);
assert.dom('[data-test-withdrawal-button]').exists('Withdrawal button exists');
assert.dom('[data-test-withdrawal-button]').hasText('Withdraw', 'Withdrawal button text is correct');
await click('[data-test-withdrawal-button]');
assert.dom('[data-test-dialog-heading').hasText('Withdraw Preprint', 'Withdrawal modal title is correct');
assert.dom('[data-test-dialog-body]').containsText('You are about to withdraw this version of your preprint',
'Withdrawal modal text contains versioning language');
assert.dom('[data-test-dialog-body]').containsText(
'Since this version is still pending approval and private, it can be withdrawn immediately',
'Withdrawal modal text contains pending language for pre-moderation providers',
);
this.preprint.reviewsState = ReviewsState.ACCEPTED;
await settled();

assert.dom('[data-test-dialog-body]').containsText('Preprints are a permanent part of the scholarly record',
'Withdrawal modal text contains language for published preprints');
assert.dom('[data-test-dialog-body]').containsText(
'This service uses pre-moderation. This request will be submitted to service moderators for review.',
'Withdrawal modal text contains moderation language for pre-moderation providers',
);
this.provider.reviewsWorkflow = PreprintProviderReviewsWorkFlow.POST_MODERATION;
await settled();

assert.dom('[data-test-dialog-body]').containsText(
'This service uses post-moderation. This request will be submitted to service moderators for review.',
'Withdrawal modal text contains moderation language for post-moderation providers',
);
this.provider.reviewsWorkflow = null;
await settled();

assert.dom('[data-test-dialog-body]').containsText(
'This request will be submitted to support@osf.io for review and removal.',
'Withdrawal modal text contains language for providers without moderation',
);

assert.dom('[data-test-comment-label]').hasText('Reason for withdrawal (required): *',
'Comment input label is correct');
assert.dom('[data-test-comment-input] textarea').exists('Comment input exists');
assert.dom('[data-test-comment-input] textarea').hasAttribute('placeholder', 'Comment',
'Comment input placeholder is correct');

assert.dom('[data-test-confirm-withdraw-button]')
.isDisabled('Withdrawal button is disabled when form is empty');

await fillIn('[data-test-comment-input] textarea', 'Short comment');
assert.dom('[data-test-confirm-withdraw-button]')
.isDisabled('Withdrawal button is disabled when comment is too short');

await fillIn('[data-test-comment-input] textarea', 'Longer test comment that should be long enough');
assert.dom('[data-test-confirm-withdraw-button]')
.isEnabled('Withdrawal button is enabled when comment is long enough');
});
});
2 changes: 1 addition & 1 deletion app/preprints/-components/withdrawal-preprint/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
{{t 'general.cancel'}}
</Button>
<Button
data-test-withdrawal-button
data-test-confirm-withdraw-button
disabled={{this.isInvalid}}
@type='destroy'
{{on 'click' (
Expand Down
11 changes: 11 additions & 0 deletions tests/acceptance/preprints/detail-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { currentRouteName, settled } from '@ember/test-helpers';
import { ModelInstance } from 'ember-cli-mirage';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { percySnapshot } from 'ember-percy';
import { TestContext } from 'ember-test-helpers';
import { module, test } from 'qunit';

Expand Down Expand Up @@ -59,6 +60,7 @@ module('Acceptance | preprints | detail', hooks => {
assert.dom('[data-test-edit-preprint-button]').exists('Edit button is displayed');
assert.dom('[data-test-edit-preprint-button]').containsText('Edit', 'Edit button text is correct');
assert.dom('[data-test-create-new-version-button]').exists('New version button is displayed');
assert.dom('[data-test-withdrawal-button]').exists('Withdraw button is displayed');

// Check preprint authors
assert.dom('[data-test-contributor-name]').exists('Authors are displayed');
Expand All @@ -68,6 +70,7 @@ module('Acceptance | preprints | detail', hooks => {
// Check preprint status banner
assert.dom('[data-test-status]').exists('Status banner is displayed');
assert.dom('[data-test-status]').containsText('accepted', 'Status is correct');
await percySnapshot(assert);
});

test('Accepted preprint, prior version detail page', async function(this: PreprintDetailTestContext, assert) {
Expand All @@ -81,10 +84,12 @@ module('Acceptance | preprints | detail', hooks => {
assert.dom('[data-test-edit-preprint-button]').doesNotExist('Edit button is not displayed for prior versions');
assert.dom('[data-test-create-new-version-button]')
.doesNotExist('New version button is not displayed for prior versions');
assert.dom('[data-test-withdrawal-button]').exists('Withdraw button is displayed for prior versions');

// Check preprint status banner
assert.dom('[data-test-status]').exists('Status banner is displayed');
assert.dom('[data-test-status]').containsText('accepted', 'Status is correct');
await percySnapshot(assert);
});

test('Pre-mod: Rejected preprint detail page', async function(this: PreprintDetailTestContext, assert) {
Expand All @@ -111,13 +116,15 @@ module('Acceptance | preprints | detail', hooks => {
assert.dom('[data-test-edit-preprint-button]')
.hasText('Edit and resubmit', 'Edit button text indicates resubmission');
assert.dom('[data-test-create-new-version-button]').doesNotExist('New version button is not displayed');
assert.dom('[data-test-withdrawal-button]').doesNotExist('Withdraw button is not displayed');

// Check preprint authors
assert.dom('[data-test-contributor-name]').exists('Authors are displayed');

// Check preprint status banner
assert.dom('[data-test-status]').exists('Status banner is displayed');
assert.dom('[data-test-status]').containsText('rejected', 'Status is correct');
await percySnapshot(assert);
});


Expand All @@ -135,10 +142,12 @@ module('Acceptance | preprints | detail', hooks => {
assert.dom('[data-test-edit-preprint-button]').doesNotExist('Edit button is not displayed');
assert.dom('[data-test-create-new-version-button]')
.exists('New version button is displayed for latest withdrawn preprint version');
assert.dom('[data-test-withdrawal-button]').doesNotExist('Withdraw button is not displayed');
assert.dom('[data-test-previous-versions-button]').exists('Previous versions button is displayed');
await click('[data-test-previous-versions-button]');
assert.dom('[data-test-no-other-versions]').exists({ count: 1 }, 'No other versions message is displayed');
assert.dom('[data-test-version-link]').doesNotExist('No links to previous versions are displayed');
await percySnapshot(assert);
});

test('Withdrawn preprint, prior version detail page', async function(this: PreprintDetailTestContext, assert) {
Expand All @@ -161,10 +170,12 @@ module('Acceptance | preprints | detail', hooks => {
assert.dom('[data-test-edit-preprint-button]').doesNotExist('Edit button is not displayed');
assert.dom('[data-test-create-new-version-button]')
.doesNotExist('New version button is not displayed for prior withdrawn preprint version');
assert.dom('[data-test-withdrawal-button]').doesNotExist('Withdraw button is not displayed');
assert.dom('[data-test-previous-versions-button]').exists('Previous versions button is displayed');
await click('[data-test-previous-versions-button]');
assert.dom('[data-test-version-link]').exists({ count: 3 }, 'Link to previous version is displayed');
assert.dom('[data-test-no-other-versions]').doesNotExist('No other versions message is not displayed');
await percySnapshot(assert);
});

test('Edit button visibility', async function(this: PreprintDetailTestContext, assert) {
Expand Down

0 comments on commit c16996f

Please sign in to comment.