Skip to content

Commit

Permalink
jobSearchBox integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Apr 19, 2024
1 parent 07cb54e commit db5d382
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions ui/tests/integration/components/job-search-box-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,52 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { fillIn, find, triggerEvent } from '@ember/test-helpers';

const DEBOUNCE_MS = 500;

module('Integration | Component | job-search-box', function (hooks) {
setupRenderingTest(hooks);

test('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`<JobSearchBox />`);
test('debouncer debounces appropriately', async function (assert) {
assert.expect(4);

assert.dom(this.element).hasText('');
let message = '';

// Template block usage:
await render(hbs`
<JobSearchBox>
template block text
</JobSearchBox>
`);
this.set('externalAction', (value) => {
message = value;
});

assert.dom(this.element).hasText('template block text');
await render(hbs`<JobSearchBox @onFilterChange={{this.externalAction}} />`);
const element = find('input');
await fillIn('input', 'test1');
assert.equal(message, 'test1', 'Initial typing');
element.value += ' wont be ';
triggerEvent('input', 'input');
assert.equal(
message,
'test1',
'Typing has happened within debounce window'
);
element.value += 'seen ';
triggerEvent('input', 'input');
await delay(DEBOUNCE_MS - 100);
assert.equal(
message,
'test1',
'Typing has happened within debounce window, albeit a little slower'
);
element.value += 'until now.';
triggerEvent('input', 'input');
await delay(DEBOUNCE_MS + 100);
assert.equal(
message,
'test1 wont be seen until now.',
'debounce window has closed'
);
});
});

function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

0 comments on commit db5d382

Please sign in to comment.