Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paper-chips: Support optional defaultHighlighted #954

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addon/templates/components/paper-chips.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
{{#paper-autocomplete
options=options
closeOnSelect=true
defaultHighlighted=defaultHighlighted
placeholder=placeholder
searchField=searchField
search=search
Expand Down
71 changes: 71 additions & 0 deletions tests/integration/components/paper-chips-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, triggerKeyEvent, fillIn } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | paper-chips', function(hooks) {
setupRenderingTest(hooks);

test('on input, opens dropdown with matched options', async function(assert) {
this.items = ['Two', 'Three', 'Ten', 'Thirtneen'];
this.selectedItems = [];
await render(hbs`
{{paper-chips
options=items
content=selectedItems}}`);

await fillIn('md-chips input', 'T');
assert.dom('.md-autocomplete-suggestions li').exists({ count: this.items.length });
});

test('without defaultHighlighted, none of the dropdown options are highlighted', async function(assert) {
this.items = ['Two', 'Three', 'Ten', 'Thirtneen'];
this.selectedItems = [];

await render(hbs`
{{paper-chips
options=items
content=selectedItems}}`);

await fillIn('md-chips input', 'T');
assert.dom('.md-autocomplete-suggestions li.selected').doesNotExist();
});

test('providing defaultHighlighted, opens dropdown where that option is highlighted', async function(assert) {
this.items = ['Two', 'Three', 'Ten', 'Thirtneen'];
this.selectedItems = [];
this.defaultHighlighted = (a) => a.results[0];

await render(hbs`
{{paper-chips
defaultHighlighted=defaultHighlighted
options=items
content=selectedItems}}`);

await fillIn('md-chips input', 'T');
assert.dom('.md-autocomplete-suggestions li.selected').exists({ count: 1 });
});

test('pressing ENTER key, sets defaultHighlighted item as selected', async function(assert) {
this.items = ['Two', 'Three', 'Ten', 'Thirtneen'];
this.selectedItems = [];
this.defaultHighlighted = (a) => a.results[0];
this.addItems = (item) => { this.set('selectedItems', [...this.selectedItems, item])};

await render(hbs`
{{paper-chips
addItem=(action addItems)
defaultHighlighted=defaultHighlighted
options=items
content=selectedItems}}`);

await fillIn('md-chips input', 'T');
assert.dom('.md-autocomplete-suggestions li.selected').exists({ count: 1 });

await triggerKeyEvent('md-chips input', 'keydown', 13);
assert.dom('md-chip').exists({ count: this.selectedItems.length });
assert.dom('md-chip .md-chip-content').hasText('Two');
assert.equal(this.selectedItems[0], this.items[0]);
});

});