Skip to content

Commit

Permalink
#233 filterWithSelect doesn't work on boolean fields
Browse files Browse the repository at this point in the history
  • Loading branch information
onechiporenko committed Jul 20, 2017
1 parent 7e8d567 commit 192b57d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 3 deletions.
6 changes: 5 additions & 1 deletion addon/-private/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export default O.extend({
if (!filterWithSelect || isEmpty(filterOptions)) {
return;
}
if (!A(filterOptions).findBy('value', filterString)) {
const filterOptionExists = A(filterOptions).find(option => {
const value = get(option, 'value');
return [value, '' + value].indexOf(filterString) !== -1;
});
if (!filterOptionExists) {
set(this, 'filterString', '');
}
})
Expand Down
33 changes: 33 additions & 0 deletions tests/dummy/app/controllers/examples/filtering-select-box-bool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Ember from 'ember';
import generateContent from '../../utils/c';

const {A} = Ember;

export default Ember.Controller.extend({

title: 'Filtering with select-box (by boolean values)',
model: generateContent(10),
columns: A([
{
propertyName: 'id',
title: 'ID'
},
{
propertyName: 'firstName',
title: 'First Name'
},
{
propertyName: 'lastName',
title: 'Last Name'
},
{
propertyName: 'city',
title: 'City'
},
{
propertyName: 'rand',
filterWithSelect: true
}
])

});
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Router.map(function() {
this.route('custom-column-classes');
this.route('filtering-ignore-case');
this.route('filtering-select-box');
this.route('filtering-select-box-bool');
this.route('add-remove-column');
this.route('grouped-headers');
this.route('server-table');
Expand Down
17 changes: 17 additions & 0 deletions tests/dummy/app/templates/examples/filtering-select-box-bool.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="row">
<div class="col-md-12">
<h4>{{title}}</h4>
</div>
<div class="col-md-8">
{{models-table data=model columns=columns}}
</div>
<div class="col-md-4">
<p>Component usage:</p>
<pre><code class="handlebars">&lbrace;&lbrace;models-table
data=model
columns=columns&rbrace;&rbrace;</code></pre>

<p><code>columns</code>:</p>
<pre><code class="javascript">{{to-string this 'columns'}}</code></pre>
</div>
</div>
3 changes: 2 additions & 1 deletion tests/dummy/app/utils/c.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export default function generateContent (recordsCount) {
lastName: surnames[indx],
age: Math.floor(Math.random() * (50 - 18)) + 18,
city: cities[indx],
cityWithHtml: `<i>${cities[indx]}</i>`
cityWithHtml: `<i>${cities[indx]}</i>`,
rand: !!(i % 2)
}));
}
return ret;
Expand Down
3 changes: 2 additions & 1 deletion tests/helpers/f.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function generateContent(length) {
reversedIndex: startFrom + length - i,
indexWithHtml: `<i>${i}</i>`,
someWord: numberToWord(i),
id: i
id: i,
rand: !!(i % 2)
}));
}
return ret;
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/components/models-table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,29 @@ test('filtering with filterWithSelect (without predefinedFilterOptions), `sortFi

});

test('filtering with filterWithSelect (without predefinedFilterOptions), sort by property with boolean values', function (assert) {

var columns = generateColumns(['index', 'rand']);
columns[1].filterWithSelect = true;
var data = generateContent(10, 1);
this.setProperties({
columns: columns,
data: data
});
this.render(hbs`{{models-table columns=columns data=data}}`);

assert.equal(this.getCount(selectors.allRows), 10, '10 rows exist before filtering');

this.filterWithSelectSecondColumn('true');
assert.equal(this.getCount(selectors.allRows), 5, '5 rows exist after filtering');
assert.equal(this.getEachAsString(selectors.secondColumn, '|'), 'true|true|true|true|true', 'valid rows are shown');

this.filterWithSelectSecondColumn('false');
assert.equal(this.getCount(selectors.allRows), 5, '5 rows exist after filtering (2)');
assert.equal(this.getEachAsString(selectors.secondColumn, '|'), 'false|false|false|false|false', 'valid rows are shown (2)');

});

test('filtering with filterWithSelect (with predefinedFilterOptions as primitives)', function (assert) {

var selectSelector = `${selectors.theadSecondRowCells}:eq(1) select`;
Expand Down

0 comments on commit 192b57d

Please sign in to comment.