Skip to content

[ENG-2391] Add tests for review-actions-list #1107

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency-decorators';
import Intl from 'ember-intl/services/intl';
import Toast from 'ember-toastr/services/toast';

import RegistrationModel from 'ember-osf-web/models/registration';
Expand All @@ -15,12 +16,14 @@ interface Args {

export default class ReviewActionsList extends Component<Args> {
@service toast!: Toast;
@service intl!: Intl;

@tracked showFullActionList: boolean = false;
@tracked reviewActions?: ReviewActionModel[];

get showOrHide() {
return this.showFullActionList ? 'Hide' : 'Show full history';
return this.showFullActionList ? this.intl.t('registries.reviewActionsList.hide')
: this.intl.t('registries.reviewActionsList.show');
}

get latestAction() {
Expand All @@ -36,6 +39,7 @@ export default class ReviewActionsList extends Component<Args> {
} catch (e) {
captureException(e);
this.toast.error(getApiErrorMessage(e));
throw e;
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div local-class='actionsWrapper'>
{{#if this.fetchActions.isRunning}}
<LoadingIndicator @dark={{true}} />
{{else if this.fetchActions.isError}}
{{else if this.fetchActions.last.isError}}
<p data-test-loading-actions-failed>
{{t 'registries.reviewActionsList.failedToLoadActions'}}
</p>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@types/ember-data": "^3.1.8",
"@types/ember-feature-flags": "^4.0.5",
"@types/ember-qunit": "^3.4.8",
"@types/ember__test-helpers": "^1.7.0",
"@types/ember__test-helpers": "^1.7.3",
"@types/faker": "^4.1.12",
"@types/js-md5": "^0.4.2",
"@types/qunit": "^2.9.0",
Expand Down
92 changes: 92 additions & 0 deletions tests/integration/components/review-actions-list/component-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { click, render, resetOnerror, setupOnerror } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { setupIntl, t } from 'ember-intl/test-support';

import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';

module('Integration | Component | review-actions-list', hooks => {
setupRenderingTest(hooks);
setupIntl(hooks);
setupMirage(hooks);

hooks.beforeEach(() => {
server.create('registration', {
id: 'single',
}, 'withSingleReviewAction');
server.create('registration', {
id: 'multi',
}, 'withReviewActions');
});

test('error fetching review-actions', async function(assert) {
setupOnerror((e: any) => assert.ok(e, 'Error is handled'));

server.namespace = '/v2';
server.get('/registrations/:parentID/actions', () => ({
errors: [{ detail: 'Ruh-oh Raggie' }],
}), 400);
this.store = this.owner.lookup('service:store');
const registrationModel = server.create('registration', 'withReviewActions');
const registration = await this.store.findRecord('registration', registrationModel.id);
this.set('registration', registration);

await render(hbs`<Registries::ReviewActionsList @registration={{this.registration}}/>`);
assert.dom('#toast-container', document as any).hasTextContaining('Ruh-oh Raggie',
'Toast error shown after failing to get review actions');
assert.dom('[data-test-no-actions-found]').doesNotExist('No actions message not shown');
assert.dom('[data-test-loading-actions-failed]').exists('Loading error shown');
assert.dom('[data-test-registration-list-card-latest-action]').doesNotExist('Latest action not shown');
assert.dom('[data-test-registration-card-toggle-actions]').doesNotExist('Toggle button not shown');
resetOnerror();
});

test('no review-actions', async function(assert) {
this.store = this.owner.lookup('service:store');
const noActionRegistrationModel = server.create('registration');
const noActionRegistration = await this.store.findRecord('registration', noActionRegistrationModel.id);
this.set('registration', noActionRegistration);

await render(hbs`<Registries::ReviewActionsList @registration={{this.registration}}/>`);
assert.dom('[data-test-no-actions-found]').exists('No actions message shown');
assert.dom('[data-test-loading-actions-failed]').doesNotExist('Loading error not shown');
assert.dom('[data-test-registration-list-card-latest-action]').doesNotExist('Latest action not shown');
assert.dom('[data-test-registration-card-toggle-actions]').doesNotExist('Toggle button not shown');
});

test('one review-action', async function(assert) {
this.store = this.owner.lookup('service:store');
const oneActionRegistrationModel = server.create('registration', 'withSingleReviewAction');
const oneActionRegistration = await this.store.findRecord('registration', oneActionRegistrationModel.id);
this.set('registration', oneActionRegistration);

await render(hbs`<Registries::ReviewActionsList @registration={{this.registration}}/>`);
assert.dom('[data-test-no-actions-found]').doesNotExist('No actions message not shown');
assert.dom('[data-test-loading-actions-failed]').doesNotExist('Loading error not shown');
assert.dom('[data-test-registration-list-card-latest-action]').exists('Latest action shown');
assert.dom('[data-test-registration-card-toggle-actions]').doesNotExist('Toggle button not shown');
});

test('multiple review-actions', async function(assert) {
this.store = this.owner.lookup('service:store');
const registrationModel = server.create('registration', 'withReviewActions');
const oneActionRegistration = await this.store.findRecord('registration', registrationModel.id);
this.set('registration', oneActionRegistration);

await render(hbs`<Registries::ReviewActionsList @registration={{this.registration}}/>`);
assert.dom('[data-test-no-actions-found]').doesNotExist('No actions message not shown');
assert.dom('[data-test-loading-actions-failed]').doesNotExist('Loading error not shown');
assert.dom('[data-test-registration-list-card-latest-action]').exists('Latest action shown');
assert.dom('[data-test-registration-card-toggle-actions]').exists('Toggle button shown');
assert.dom('[data-test-registration-card-toggle-actions]').hasText(`${t('registries.reviewActionsList.show')}`,
'Toggle button has correct text before showing all');
assert.dom('[data-test-registration-list-card-more-actions]').doesNotExist('More actions not shown');

await click('[data-test-registration-card-toggle-actions]');
assert.dom('[data-test-registration-list-card-more-actions]')
.exists({ count: 2 }, 'Two more actions are shown after clicking the toggler');
assert.dom('[data-test-registration-card-toggle-actions]').hasText(`${t('registries.reviewActionsList.hide')}`,
'Toggle button has correct text after showing all');
});
});
2 changes: 2 additions & 0 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,8 @@ registries:
reviewActionsList:
failedToLoadActions: 'Failed to load registration moderation history'
noActionsFound: 'No moderation history found for this registration'
hide: Hide
show: 'Show full history'
reviewAction:
acceptSubmission: 'Registration {action} {date} by {moderator} with no embargo'
acceptEmbargoSubmission: 'Registration {action} {date} by {moderator} with embargo ending {embargoEndDate}'
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2731,10 +2731,10 @@
resolved "https://registry.yarnpkg.com/@types/ember__template/-/ember__template-3.0.0.tgz#d499ebf000faa371c1c98124633b9864be69b968"
integrity sha512-aWNg/kL2QToE0fwI8MVgAr2upWyAUwqRv2sp3CpypsMTOC1lZizIehz8QI6w1m1+Eh1WYs/89gvuM3mTc4OyIw==

"@types/ember__test-helpers@^1.7.0":
version "1.7.0"
resolved "https://registry.yarnpkg.com/@types/ember__test-helpers/-/ember__test-helpers-1.7.0.tgz#d1f18c283744ca17b04dc185602f67a5fee77f7d"
integrity sha512-8pd+KNnus948oAQh0pdpP4SioaBTJDqn+H4FkBjphZf+VzFZMVbJoDtDqCcBH/d2Cr2gXPd4RDjZRprg/bRVLQ==
"@types/ember__test-helpers@^1.7.3":
version "1.7.3"
resolved "https://registry.yarnpkg.com/@types/ember__test-helpers/-/ember__test-helpers-1.7.3.tgz#a3553f5c3318032dcdf03b7b511254b9edf930eb"
integrity sha512-5LGWJHkdbKYrrA/l4QFeu2WNE0iaz5lBjc980VLzOqyfy2/r4CbZbuHtg+oL5jYQDnB2Udpz9b3EwwM3lg7hsA==
dependencies:
"@types/ember" "*"
"@types/ember__application" "*"
Expand Down