Skip to content

Commit

Permalink
make filter interoperability with inputs better
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Aug 8, 2018
1 parent c951479 commit e7502d3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
6 changes: 3 additions & 3 deletions addon/components/yeti-table/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ export default class YetiTable extends Component {

/**
* The global filter. If passed in, Yeti Table will search all the rows that contain this
* string and show them.
* string and show them. Defaults to `''`.
*/
@argument
@argument({ defaultIfUndefined: true })
@type(optional('string'))
filter;
filter = '';
/**
* An optional function to customize the filtering logic. This function should return true
Expand Down
45 changes: 44 additions & 1 deletion tests/integration/components/yeti-table/async-data-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ module('Integration | Component | yeti-table (async)', function(hooks) {
await clearRender();

assert.ok(this.loadData.calledTwice, 'loadData was called twice');
assert.ok(this.loadData.firstCall.calledWithMatch({ filterData: { filter: undefined }}));
assert.ok(this.loadData.firstCall.calledWithMatch({ filterData: { filter: '' }}));
assert.ok(this.loadData.secondCall.calledWithMatch({ filterData: { filter: 'Baderous' }}));
});

Expand Down Expand Up @@ -527,4 +527,47 @@ module('Integration | Component | yeti-table (async)', function(hooks) {
assert.ok(this.loadData.calledOnce, 'loadData was called once');
});

test('loadData is called once if we change @filter from undefined to ""', async function(assert) {
this.loadData = sinon.spy(() => {
return new RSVP.Promise((resolve) => {
later(() => {
resolve(this.data);
}, 150);
});
});

await render(hbs`
<YetiTable @loadData={{loadData}} @filter={{filterText}} as |table|>
<table.header as |header|>
<header.column @prop="firstName">
First name
</header.column>
<header.column @prop="lastName" @sort="desc">
Last name
</header.column>
<header.column @prop="points">
Points
</header.column>
</table.header>
<table.body/>
</YetiTable>
`);

await settled();

assert.dom('tbody tr').exists({ count: 5 }, 'is not filtered');
assert.dom('tbody tr:nth-child(5) td:nth-child(1)').hasText('Tom', 'column 1 is not sorted');
assert.dom('tbody tr:nth-child(5) td:nth-child(2)').hasText('Dale', 'column 2 is not sorted');
assert.dom('tbody tr:nth-child(5) td:nth-child(3)').hasText('5', 'column 3 is not sorted');

this.set('filterText', '');

await clearRender();

assert.ok(this.loadData.calledOnce, 'loadData was called once');
});

});

0 comments on commit e7502d3

Please sign in to comment.