2018-08-09 10:41:52 -07:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
2018-08-09 23:25:55 -07:00
|
|
|
import { render, findAll, triggerEvent } from '@ember/test-helpers';
|
2018-05-07 08:32:02 -07:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
module('Integration | Component | pwr user lookup', function(hooks) {
|
|
|
|
setupRenderingTest(hooks);
|
2018-05-07 08:32:02 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
const autosuggestionClass = '.pwr-user-lookup__auto-suggestion__input';
|
|
|
|
const typeaheadContainerClass = '.pwr-user-lookup__typeahead-container';
|
|
|
|
const typeaheadTriggerClass = `${typeaheadContainerClass} .ember-power-select-typeahead-trigger`;
|
|
|
|
const typeaheadInputClass = `${typeaheadTriggerClass} .ember-power-select-typeahead-input`;
|
2018-05-07 08:32:02 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('it renders', async function(assert) {
|
|
|
|
await render(hbs`{{pwr-user-lookup}}`);
|
2019-08-31 20:51:14 -07:00
|
|
|
assert.ok(this.element, 'Renders without errors');
|
2018-08-09 23:25:55 -07:00
|
|
|
assert.equal(findAll(autosuggestionClass).length, 1, 'Renders suggestion component');
|
2019-08-31 20:51:14 -07:00
|
|
|
assert.equal(this.element.querySelectorAll(typeaheadInputClass).length, 1, 'Renders typeahead input component');
|
2018-05-07 08:32:02 -07:00
|
|
|
});
|
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
test('it properly triggers the findUser action', async function(assert) {
|
|
|
|
let findUserActionCallCount = 0;
|
|
|
|
this.set('findUser', () => {
|
|
|
|
findUserActionCallCount++;
|
|
|
|
assert.equal(findUserActionCallCount, 1, 'findUser action is invoked when triggered');
|
|
|
|
});
|
2018-05-07 08:32:02 -07:00
|
|
|
|
2018-08-09 10:41:52 -07:00
|
|
|
await render(hbs`{{pwr-user-lookup didFindUser=findUser}}`);
|
|
|
|
|
|
|
|
assert.equal(findUserActionCallCount, 0, 'findUser action is not invoked on instantiation');
|
|
|
|
triggerEvent(typeaheadInputClass, 'Pikachu');
|
|
|
|
});
|
2018-05-07 08:32:02 -07:00
|
|
|
});
|