Skip to content

Commit

Permalink
fix: prevent double click on workflow basics next btn
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredgalanis committed Jan 30, 2024
1 parent b71c883 commit f4fcbe9
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 46 deletions.
17 changes: 8 additions & 9 deletions app/components/workflow-basics/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,14 @@
<button class="btn btn-outline-danger ml-2" {{action "cancel"}}>
Cancel
</button>
{{#if this.inFlight}}
<button class="btn btn-primary pull-right next" disabled>
Next
</button>
{{else}}
<button class="btn btn-primary pull-right next" data-test-workflow-basics-next {{action @next}}>
Next
</button>
{{/if}}
<button
class="btn btn-primary pull-right next"
data-test-workflow-basics-next
{{on "click" (perform this.loadNext)}}
disabled={{this.loadNext.isRunning}}
>
Next
</button>
{{#if this.isShowingUserSearchModal}}
<div class="user-search-modal">
<ModalDialog
Expand Down
9 changes: 7 additions & 2 deletions app/components/workflow-basics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { action, get, set } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';
import { task, timeout } from 'ember-concurrency';
import { scheduleOnce } from '@ember/runloop';
import { dropTask } from 'ember-concurrency-decorators';
import { timeout } from 'ember-concurrency';
import { run, scheduleOnce } from '@ember/runloop';

const DEBOUNCE_MS = 250;

Expand Down Expand Up @@ -76,6 +76,11 @@ export default class WorkflowBasics extends Component {
set(this.submission, 'preparers', []);
}

loadNext = task({ drop: true }, async () => {
await timeout(100);
await this.args.validateAndLoadTab('submissions.new.grants');
});

@action
setupSubmission() {
if (!this.isProxySubmission) {
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/submissions/new/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { action, computed, get, set } from '@ember/object';
import { A } from '@ember/array';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency-decorators';

export default class SubmissionsNewBasics extends Controller {
@service workflow;
Expand Down Expand Up @@ -58,11 +59,6 @@ export default class SubmissionsNewBasics extends Controller {
return !get(this, 'submission.submitter.id') && (!email || !emailPattern.test(email));
}

@action
loadNext() {
this.validateAndLoadTab('submissions.new.grants');
}

@action
async loadTab(gotoRoute) {
this.doiInfo.title = this.publication.title;
Expand Down
2 changes: 1 addition & 1 deletion app/templates/submissions/new/basics.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@validateSubmitterEmail={{action "validateSubmitterEmail"}}
@updatePublication={{action "updatePublication"}}
@updateDoiInfo={{action "updateDoiInfo"}}
@next={{action "loadNext"}}
@validateAndLoadTab={{this.validateAndLoadTab}}
@abort={{action "abort"}}
/>
</WorkflowWrapper>
31 changes: 30 additions & 1 deletion tests/integration/components/workflow-basics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import EmberObject, { get } from '@ember/object';
import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { module, test } from 'qunit';
import { fillIn, render, settled, triggerKeyEvent } from '@ember/test-helpers';
import { doubleClick, fillIn, render, settled, triggerKeyEvent } from '@ember/test-helpers';
import { run } from '@ember/runloop';
import { task } from 'ember-concurrency';
import sinon from 'sinon';

module('Integration | Component | workflow basics', (hooks) => {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -371,4 +372,32 @@ module('Integration | Component | workflow basics', (hooks) => {

assert.deepEqual(get(this, 'doiInfo'), {}, 'doiInfo should be empty');
});

test('loadNext is called once when next is clicked', async function (assert) {
this.publication.title = 'Moo title';
this.publication.journal = EmberObject.create({ journalName: 'Moo Journal' });

this.submission.publication = this.publication;

this.loadNext = sinon.stub();

await render(hbs`
<WorkflowBasics
@submission={{this.submission}}
@publication={{this.publication}}
@preLoadedGrant={{this.preLoadedGrant}}
@doiInfo={{this.doiInfo}}
@flaggedFields={{this.flaggedFields}}
@validateTitle={{this.validateTitle}}
@validateJournal={{this.validateJournal}}
@validateSubmitterEmail={{this.validateSubmitterEmail}}
@updatePublication={{this.updatePublication}}
@updateDoiInfo={{this.updateDoiInfo}}
@validateAndLoadTab={{this.loadNext}}
/>`);

await doubleClick('[data-test-workflow-basics-next]');

assert.ok(this.loadNext.calledOnce, 'loadNext called once');
});
});
28 changes: 0 additions & 28 deletions tests/unit/controllers/submissions/new/basics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,32 +208,4 @@ module('Unit | Controller | submissions/new/basics', (hooks) => {
assert.true(controller.get('model.newSubmission.isProxySubmission'));
controller.send('validateAndLoadTab', 'submissions.new.basics');
});

/**
* Mock the submission model object with a custom `#save()` function. This test makes
* sure that the custom save function is called exactly once when the 'loadNext'
* action is sent to the controller.
*/
test('make sure submission is saved', function (assert) {
assert.expect(2);

const controller = this.owner.lookup('controller:submissions/new/basics');
const model = {
publication: EmberObject.create({
title: 'This is the moo-iest',
journal: EmberObject.create({
id: 'journal:id',
}),
save: () => Promise.resolve(assert.ok(true)),
}),
newSubmission: EmberObject.create({
save: () => Promise.resolve(assert.ok(true)),
}),
};

controller.set('transitionToRoute', (route) => {});

controller.set('model', model);
controller.send('loadNext');
});
});

0 comments on commit f4fcbe9

Please sign in to comment.