From e7502d3188c925e3bee593f65f56147f6883810b Mon Sep 17 00:00:00 2001 From: Miguel Andrade Date: Wed, 8 Aug 2018 17:50:55 +0100 Subject: [PATCH] make filter interoperability with inputs better --- addon/components/yeti-table/component.js | 6 +-- .../components/yeti-table/async-data-test.js | 45 ++++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/addon/components/yeti-table/component.js b/addon/components/yeti-table/component.js index f4c0c3f2..62ee32a0 100644 --- a/addon/components/yeti-table/component.js +++ b/addon/components/yeti-table/component.js @@ -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 diff --git a/tests/integration/components/yeti-table/async-data-test.js b/tests/integration/components/yeti-table/async-data-test.js index 253273b3..614a89e9 100644 --- a/tests/integration/components/yeti-table/async-data-test.js +++ b/tests/integration/components/yeti-table/async-data-test.js @@ -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' }})); }); @@ -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` + + + + + First name + + + Last name + + + Points + + + + + + + `); + + 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'); + }); + });