From 9ac55044eea80e461b640c0512619edf8c54dc65 Mon Sep 17 00:00:00 2001 From: takshch Date: Sun, 13 Jun 2021 03:29:31 +0530 Subject: [PATCH 1/2] Adds test for sign-up/button component --- .../components/sign-up/button-test.js | 124 ++++++++++++++++++ .../components/sign-up/form-test.js | 26 ++++ .../components/sign-up/get-started-test.js | 26 ++++ 3 files changed, 176 insertions(+) create mode 100644 tests/integration/components/sign-up/button-test.js create mode 100644 tests/integration/components/sign-up/form-test.js create mode 100644 tests/integration/components/sign-up/get-started-test.js diff --git a/tests/integration/components/sign-up/button-test.js b/tests/integration/components/sign-up/button-test.js new file mode 100644 index 00000000..34073b20 --- /dev/null +++ b/tests/integration/components/sign-up/button-test.js @@ -0,0 +1,124 @@ +import { module, skip } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render, click } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +module('Integration | Component | sign-up/button', function (hooks) { + setupRenderingTest(hooks); + + skip('Button should not render if its content is not present', async function (assert) { + assert.expect(1); + + await render(hbs` + + `); + + assert.dom('[data-test-signup-button]').doesNotExist(); + }); + + skip('Button should be disabled if @disabled is true', async function (assert) { + assert.expect(1); + this.set('inputValue', 'Get Started'); + + await render(hbs` + {{inputValue}} + `); + + assert.dom('[data-test-signup-button]').isDisabled(); + }); + + skip('Button should not be disabled if @disabled is undefined', async function (assert) { + assert.expect(1); + this.set('inputValue', 'Get Started'); + + await render(hbs` + {{inputValue}} + `); + + assert.dom('[data-test-signup-button]').isNotDisabled(); + }); + + skip('Button should not be disabled if @disabled is not true', async function (assert) { + assert.expect(1); + this.set('inputValue', 'Get Started'); + + await render(hbs` + {{inputValue}} + `); + + assert.dom('[data-test-signup-button]').isNotDisabled(); + }); + + skip('Button should be of type button', async function (assert) { + assert.expect(1); + this.set('inputValue', 'Get Started'); + + await render(hbs` + {{inputValue}} + `); + + assert.dom('[data-test-signup-button]').hasAttribute('type', 'button'); + }); + + skip('Button should have spinner if @isSubmitClick is true', async function (assert) { + assert.expect(1); + this.set('inputValue', 'Get Started'); + + await render(hbs` + {{inputValue}} + `); + + assert.dom('[data-test-signup-button-spinner]').exists(); + }); + + skip('Button should not have spinner if @isSubmitClick is not true', async function (assert) { + assert.expect(1); + this.set('inputValue', 'Get Started'); + + await render(hbs` + {{inputValue}} + `); + + assert.dom('[data-test-signup-button-spinner]').doesNotExist(); + }); + + skip('Click event should not execute if button is disabled', async function (assert) { + assert.expect(1); + this.set('inputValue', 'Get Started'); + this.set('clickFnc', () => { + this.set('isClicked', true); + }); + + await render(hbs` + {{inputValue}} + `); + + const button = this.element.querySelector( + '[data-test-signup-button-spinner]' + ); + button.addEventListener('click', this.clickFn); + + await click(button); + assert.notStrictEqual(this.isClicked, true); + }); + + skip('Click event should execute if button is not disabled', async function (assert) { + assert.expect(1); + this.set('inputValue', 'Get Started'); + this.set('clickFnc', () => { + this.set('isClicked', true); + }); + + await render(hbs` + {{inputValue}} + `); + + const button = this.element.querySelector( + '[data-test-signup-button-spinner]' + ); + button.addEventListener('click', this.clickFn); + + await click(button); + assert.strictEqual(this.isClicked, true); + }); +}); diff --git a/tests/integration/components/sign-up/form-test.js b/tests/integration/components/sign-up/form-test.js new file mode 100644 index 00000000..b6b7440e --- /dev/null +++ b/tests/integration/components/sign-up/form-test.js @@ -0,0 +1,26 @@ +import { module, skip } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +module('Integration | Component | sign-up/form', function (hooks) { + setupRenderingTest(hooks); + + skip('it renders', async function (assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.set('myAction', function(val) { ... }); + + await render(hbs``); + + assert.equal(this.element.textContent.trim(), ''); + + // Template block usage: + await render(hbs` + + template block text + + `); + + assert.equal(this.element.textContent.trim(), 'template block text'); + }); +}); diff --git a/tests/integration/components/sign-up/get-started-test.js b/tests/integration/components/sign-up/get-started-test.js new file mode 100644 index 00000000..27736855 --- /dev/null +++ b/tests/integration/components/sign-up/get-started-test.js @@ -0,0 +1,26 @@ +import { module, skip } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +module('Integration | Component | sign-up/get-started', function (hooks) { + setupRenderingTest(hooks); + + skip('it renders', async function (assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.set('myAction', function(val) { ... }); + + await render(hbs``); + + assert.equal(this.element.textContent.trim(), ''); + + // Template block usage: + await render(hbs` + + template block text + + `); + + assert.equal(this.element.textContent.trim(), 'template block text'); + }); +}); From 218d2adcc4b12569f486ad5988be0b4d557c3f17 Mon Sep 17 00:00:00 2001 From: takshch Date: Thu, 24 Jun 2021 10:53:48 +0530 Subject: [PATCH 2/2] Adds test for sign-up/form component --- .../components/sign-up/form-test.js | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/tests/integration/components/sign-up/form-test.js b/tests/integration/components/sign-up/form-test.js index b6b7440e..5bca4803 100644 --- a/tests/integration/components/sign-up/form-test.js +++ b/tests/integration/components/sign-up/form-test.js @@ -6,21 +6,37 @@ import { hbs } from 'ember-cli-htmlbars'; module('Integration | Component | sign-up/form', function (hooks) { setupRenderingTest(hooks); - skip('it renders', async function (assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.set('myAction', function(val) { ... }); + skip('It should have label', async function (assert) { + assert.expect(1); - await render(hbs``); - - assert.equal(this.element.textContent.trim(), ''); - - // Template block usage: + this.set('label', 'Form Label'); await render(hbs` - - template block text - + `); - assert.equal(this.element.textContent.trim(), 'template block text'); + assert.dom('[data-test-signup-form-label]').hasText(this.label); + }); + + skip('It should have button with text', async function (assert) { + assert.expect(2); + + await render(hbs` `); + + assert.dom('[data-test-signup-button]').exists(); + assert.dom('[data-test-signup-button]').hasAnyText(); + }); + + skip('It should have input field', async function (assert) { + assert.expect(3); + + await render(hbs` `); + + assert.dom('[data-test-signup-form-input]').exists(); + assert + .dom('[data-test-signup-form-input]') + .hasProperty('type', 'text') + .hasAttribute('placeholder'); }); });