Skip to content

Commit

Permalink
Use the TwoStepButton page object for integration testing too
Browse files Browse the repository at this point in the history
  • Loading branch information
DingoEatingFuzz committed May 21, 2019
1 parent d33f4bf commit 2002836
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 43 deletions.
64 changes: 22 additions & 42 deletions ui/tests/integration/two-step-button-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';
import { create } from 'ember-cli-page-object';
import twoStepButton from 'nomad-ui/tests/pages/components/two-step-button';

const TwoStepButton = create(twoStepButton());

module('Integration | Component | two step button', function(hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -37,11 +41,7 @@ module('Integration | Component | two step button', function(hooks) {
await render(commonTemplate);

assert.ok(find('[data-test-idle-button]'), 'Idle button is rendered');
assert.equal(
find('[data-test-idle-button]').textContent.trim(),
props.idleText,
'Button is labeled correctly'
);
assert.equal(TwoStepButton.idleText, props.idleText, 'Button is labeled correctly');

assert.notOk(find('[data-test-cancel-button]'), 'No cancel button yet');
assert.notOk(find('[data-test-confirm-button]'), 'No confirm button yet');
Expand All @@ -53,25 +53,17 @@ module('Integration | Component | two step button', function(hooks) {
this.setProperties(props);
await render(commonTemplate);

click('[data-test-idle-button]');
TwoStepButton.idle();

return settled().then(() => {
assert.ok(find('[data-test-cancel-button]'), 'Cancel button is rendered');
assert.equal(
find('[data-test-cancel-button]').textContent.trim(),
props.cancelText,
'Button is labeled correctly'
);
assert.equal(TwoStepButton.cancelText, props.cancelText, 'Button is labeled correctly');

assert.ok(find('[data-test-confirm-button]'), 'Confirm button is rendered');
assert.equal(
find('[data-test-confirm-button]').textContent.trim(),
props.confirmText,
'Button is labeled correctly'
);
assert.equal(TwoStepButton.confirmText, props.confirmText, 'Button is labeled correctly');

assert.equal(
find('[data-test-confirmation-message]').textContent.trim(),
TwoStepButton.confirmationMessage,
props.confirmationMessage,
'Confirmation message is shown'
);
Expand All @@ -85,10 +77,10 @@ module('Integration | Component | two step button', function(hooks) {
this.setProperties(props);
await render(commonTemplate);

click('[data-test-idle-button]');
TwoStepButton.idle();

return settled().then(() => {
click('[data-test-cancel-button]');
TwoStepButton.cancel();

return settled().then(() => {
assert.ok(props.onCancel.calledOnce, 'The onCancel hook fired');
Expand All @@ -102,10 +94,10 @@ module('Integration | Component | two step button', function(hooks) {
this.setProperties(props);
await render(commonTemplate);

click('[data-test-idle-button]');
TwoStepButton.idle();

return settled().then(() => {
click('[data-test-confirm-button]');
TwoStepButton.confirm();

return settled().then(() => {
assert.ok(props.onConfirm.calledOnce, 'The onConfirm hook fired');
Expand All @@ -120,21 +112,12 @@ module('Integration | Component | two step button', function(hooks) {
this.setProperties(props);
await render(commonTemplate);

click('[data-test-idle-button]');
TwoStepButton.idle();

return settled().then(() => {
assert.ok(
find('[data-test-cancel-button]').hasAttribute('disabled'),
'The cancel button is disabled'
);
assert.ok(
find('[data-test-confirm-button]').hasAttribute('disabled'),
'The confirm button is disabled'
);
assert.ok(
find('[data-test-confirm-button]').classList.contains('is-loading'),
'The confirm button is in a loading state'
);
assert.ok(TwoStepButton.cancelIsDisabled, 'The cancel button is disabled');
assert.ok(TwoStepButton.confirmIsDisabled, 'The confirm button is disabled');
assert.ok(TwoStepButton.isRunning, 'The confirm button is in a loading state');
});
});

Expand All @@ -143,7 +126,7 @@ module('Integration | Component | two step button', function(hooks) {
this.setProperties(props);
await render(commonTemplate);

click('[data-test-idle-button]');
TwoStepButton.idle();
await settled();

assert.ok(find('[data-test-cancel-button]'), 'In the prompt state');
Expand All @@ -159,7 +142,7 @@ module('Integration | Component | two step button', function(hooks) {
this.setProperties(props);
await render(commonTemplate);

click('[data-test-idle-button]');
TwoStepButton.idle();
await settled();

assert.ok(find('[data-test-cancel-button]'), 'In the prompt state');
Expand All @@ -176,7 +159,7 @@ module('Integration | Component | two step button', function(hooks) {
this.setProperties(props);
await render(commonTemplate);

click('[data-test-idle-button]');
TwoStepButton.idle();
await settled();

assert.ok(find('[data-test-cancel-button]'), 'In the prompt state');
Expand All @@ -193,12 +176,9 @@ module('Integration | Component | two step button', function(hooks) {
this.setProperties(props);
await render(commonTemplate);

assert.ok(
find('[data-test-idle-button]').hasAttribute('disabled'),
'The idle button is disabled'
);
assert.ok(TwoStepButton.isDisabled, 'The idle button is disabled');

click('[data-test-idle-button]');
TwoStepButton.idle();
assert.ok(find('[data-test-idle-button]'), 'Still in the idle state after clicking');
});
});
10 changes: 9 additions & 1 deletion ui/tests/pages/components/two-step-button.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { attribute, clickable, hasClass, isPresent } from 'ember-cli-page-object';
import { attribute, clickable, hasClass, isPresent, text } from 'ember-cli-page-object';

export default scope => ({
scope,
Expand All @@ -11,4 +11,12 @@ export default scope => ({

isRunning: hasClass('is-loading', '[data-test-confirm-button]'),
isDisabled: attribute('disabled', '[data-test-idle-button]'),

cancelIsDisabled: attribute('disabled', '[data-test-cancel-button]'),
confirmIsDisabled: attribute('disabled', '[data-test-confirm-button]'),

idleText: text('[data-test-idle-button]'),
cancelText: text('[data-test-cancel-button]'),
confirmText: text('[data-test-confirm-button]'),
confirmationMessage: text('[data-test-confirmation-message]'),
});

0 comments on commit 2002836

Please sign in to comment.