|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupRenderingTest } from 'ember-qunit'; |
| 3 | +import { render, click, typeIn } from '@ember/test-helpers'; |
| 4 | +import { hbs } from 'ember-cli-htmlbars'; |
| 5 | +import { setupIntl } from 'ember-intl/test-support'; |
| 6 | +import sinon from 'sinon'; |
| 7 | + |
| 8 | +module('Integration | Component | o-s-s/search-field', function (hooks) { |
| 9 | + setupRenderingTest(hooks); |
| 10 | + setupIntl(hooks); |
| 11 | + |
| 12 | + hooks.beforeEach(function () { |
| 13 | + this.onChange = (value: string) => { |
| 14 | + this.value = value; |
| 15 | + }; |
| 16 | + }); |
| 17 | + |
| 18 | + test('Search Field component is rendered with a placeholder', async function (assert) { |
| 19 | + this.placeholder = 'This is a placeholder'; |
| 20 | + this.value = ''; |
| 21 | + |
| 22 | + await render( |
| 23 | + hbs`<OSS::SearchField @value={{this.value}} @placeholder={{this.placeholder}} @onChange={{this.onChange}} />` |
| 24 | + ); |
| 25 | + |
| 26 | + assert.dom('input').hasAttribute('placeholder', 'This is a placeholder'); |
| 27 | + }); |
| 28 | + |
| 29 | + test('Input value is reset when the clear button is clicked', async function (assert) { |
| 30 | + this.value = 'Test'; |
| 31 | + |
| 32 | + await render(hbs`<OSS::SearchField @value={{this.value}} @onChange={{this.onChange}} />`); |
| 33 | + |
| 34 | + assert.dom('[role="button"]').exists(); |
| 35 | + |
| 36 | + await click('[role="button"]'); |
| 37 | + |
| 38 | + assert.strictEqual(this.value, ''); |
| 39 | + }); |
| 40 | + |
| 41 | + test('onChange function is triggered on input change', async function (assert) { |
| 42 | + this.value = ''; |
| 43 | + this.onChange = sinon.stub(); |
| 44 | + |
| 45 | + await render(hbs`<OSS::SearchField @value={{this.value}} @onChange={{this.onChange}} />`); |
| 46 | + await typeIn('input', 'Test', { delay: 0 }); |
| 47 | + |
| 48 | + assert.true(this.onChange.lastCall.calledWith('Test')); |
| 49 | + }); |
| 50 | + |
| 51 | + test('Clear button is not displayed when the input is empty', async function (assert) { |
| 52 | + this.value = ''; |
| 53 | + |
| 54 | + await render(hbs`<OSS::SearchField @value={{this.value}} @onChange={{this.onChange}} />`); |
| 55 | + |
| 56 | + assert.dom('[role="button"]').doesNotExist(); |
| 57 | + }); |
| 58 | +}); |
0 commit comments