Skip to content

Commit

Permalink
Test both multiple and single selection modes
Browse files Browse the repository at this point in the history
  • Loading branch information
kpfefferle committed Jan 20, 2021
1 parent 55c93c0 commit 78f58cd
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/integration/components/selection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TablePage from 'ember-table/test-support/pages/ember-table';
import { generateTable } from '../../helpers/generate-table';
import { generateRows } from 'dummy/utils/generators';
import { A as emberA } from '@ember/array';
import EmberObject from '@ember/object';
import { run } from '@ember/runloop';
import { scrollTo } from 'ember-native-dom-helpers';
import { registerTestWarnHandler } from '../../helpers/warn-handlers';
Expand Down Expand Up @@ -245,6 +246,29 @@ module('Integration | selection', () => {

assert.ok(table.validateSelected(0), 'Zoe is selected after external change');
});

test('Rows are selected when selection is changed externally with selectionMatchFunction', async function(assert) {
let selection = emberA();
let selectionMatchFunction = function(a, b) {
if (!a || !b) {
return false;
}
return a.id === b.id;
};
let rows = [
{ id: 1, name: 'Zoe', age: 34 },
{ id: 2, name: 'Alex', age: 43 },
{ id: 3, name: 'Liz', age: 25 },
];

await generateTable(this, { rows, selection, selectionMatchFunction });

assert.ok(table.validateSelected(), 'rows are not selected');

run(() => selection.pushObject({ id: rows[0].id }));

assert.ok(table.validateSelected(0), 'Zoe is selected after external change');
});
});

componentModule('single', function() {
Expand Down Expand Up @@ -314,6 +338,46 @@ module('Integration | selection', () => {

await table.selectRow(0);
});

test('Row is selected when selection is changed externally', async function(assert) {
this.set('selection', null);
let rows = [{ name: 'Zoe', age: 34 }, { name: 'Alex', age: 43 }, { name: 'Liz', age: 25 }];

await generateTable(this, { rows, rowSelectionMode: 'single' });

assert.ok(table.validateSelected(), 'rows are not selected');

this.set('selection', rows[0]);

assert.ok(table.validateSelected(0), 'Zoe is selected after external change');
});

test('Rows are selected when selection is changed externally with selectionMatchFunction', async function(assert) {
this.set('selection', null);
let selectionMatchFunction = function(a, b) {
if (!a || !b) {
return false;
}
return a.id === b.id;
};
let rows = [
{ id: 1, name: 'Zoe', age: 34 },
{ id: 2, name: 'Alex', age: 43 },
{ id: 3, name: 'Liz', age: 25 },
];

await generateTable(this, {
rows,
rowSelectionMode: 'single',
selectionMatchFunction,
});

assert.ok(table.validateSelected(), 'rows are not selected');

this.set('selection', { id: rows[0].id });

assert.ok(table.validateSelected(0), 'Zoe is selected after external change');
});
});

componentModule('none', function() {
Expand Down

0 comments on commit 78f58cd

Please sign in to comment.