diff --git a/ui/app/components/two-step-button.js b/ui/app/components/two-step-button.js index 7016e96ec..431526841 100644 --- a/ui/app/components/two-step-button.js +++ b/ui/app/components/two-step-button.js @@ -8,6 +8,7 @@ export default Component.extend({ cancelText: '', confirmText: '', confirmationMessage: '', + awaitingConfirmation: false, onConfirm() {}, onCancel() {}, diff --git a/ui/app/templates/components/freestyle/sg-two-step-button.hbs b/ui/app/templates/components/freestyle/sg-two-step-button.hbs index f39096b0e..74f43919f 100644 --- a/ui/app/templates/components/freestyle/sg-two-step-button.hbs +++ b/ui/app/templates/components/freestyle/sg-two-step-button.hbs @@ -20,3 +20,21 @@ {{/freestyle-usage}} + +{{#freestyle-usage "two-step-button-loading" title="Two Step Button Loading State"}} +
+

+ This is a page title + {{two-step-button + idleText="Scary Action" + cancelText="Nvm" + confirmText="Yep" + confirmationMessage="Wait, really? Like...seriously?" + awaitingConfirmation=true + state="prompt"}} +

+
+{{/freestyle-usage}} +{{#freestyle-annotation}} + Note: the state property is internal state and only used here to bypass the idle state for demonstration purposes. +{{/freestyle-annotation}} diff --git a/ui/app/templates/components/two-step-button.hbs b/ui/app/templates/components/two-step-button.hbs index e9fe906b5..cffa9dd7b 100644 --- a/ui/app/templates/components/two-step-button.hbs +++ b/ui/app/templates/components/two-step-button.hbs @@ -4,16 +4,25 @@ {{else if isPendingConfirmation}} {{confirmationMessage}} - - {{/if}} diff --git a/ui/tests/integration/two-step-button-test.js b/ui/tests/integration/two-step-button-test.js index 41eff1e6e..12d23c1d7 100644 --- a/ui/tests/integration/two-step-button-test.js +++ b/ui/tests/integration/two-step-button-test.js @@ -13,6 +13,7 @@ const commonProperties = () => ({ cancelText: 'Cancel Action', confirmText: 'Confirm Action', confirmationMessage: 'Are you certain', + awaitingConfirmation: false, onConfirm: sinon.spy(), onCancel: sinon.spy(), }); @@ -23,6 +24,7 @@ const commonTemplate = hbs` cancelText=cancelText confirmText=confirmText confirmationMessage=confirmationMessage + awaitingConfirmation=awaitingConfirmation onConfirm=onConfirm onCancel=onCancel}} `; @@ -109,3 +111,27 @@ test('confirming the promptForConfirmation state calls the onConfirm hook and re }); }); }); + +test('when awaitingConfirmation is true, the cancel and submit buttons are disabled and the submit button is loading', function(assert) { + const props = commonProperties(); + props.awaitingConfirmation = true; + this.setProperties(props); + this.render(commonTemplate); + + click('[data-test-idle-button]'); + + return wait().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' + ); + }); +});