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

Test that unrendered (occluded) row selection can be managed #731

Merged
merged 1 commit into from
Jul 19, 2019
Merged
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
69 changes: 68 additions & 1 deletion tests/integration/components/selection-test.js
Original file line number Diff line number Diff line change
@@ -4,25 +4,45 @@ import { componentModule } from '../../helpers/module';
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 { run } from '@ember/runloop';
import { scrollTo } from 'ember-native-dom-helpers';

let table = new TablePage({
validateSelected(...selectedIndexes) {
let valid = true;

let indexesSeen = [];
this.rows.forEach((row, index) => {
indexesSeen.push(index);
if (selectedIndexes.includes(index)) {
valid = valid && row.isSelected;
} else {
valid = valid && !row.isSelected;
}
});

let unseenIndexes = selectedIndexes.filter(i => !indexesSeen.includes(i));
if (unseenIndexes.length) {
throw new Error(
`could not validateSelected because these indexes were not checked: ${unseenIndexes.join(
','
)}`
);
}

return valid;
},
});

// Return an array filled with the indices for all the rendered rows of the table
function allRenderedRowIndexes(table) {
return Array(table.rows.length)
.fill()
.map((_, index) => index);
}

module('Integration | selection', () => {
module('rowSelectionMode', function() {
componentModule('multiple', function() {
@@ -403,7 +423,7 @@ module('Integration | selection', () => {
assert.expect(1);

this.on('onSelect', selection => {
assert.ok(Array.isArray(selection), 'selection is not an array');
assert.ok(Array.isArray(selection), 'selection is an array');
});

await generateTable(this, { checkboxSelectionMode: 'single' });
@@ -471,4 +491,51 @@ module('Integration | selection', () => {
assert.ok(table.validateSelected(1, 2, 3), 'only children are selected');
});
});

module('occluded selection', function() {
componentModule('basic', function() {
test('Issue 726: changing selection state of unrendered rows', async function(assert) {
// Generate a table with 1 parent row that has 500 child rows
let rows = generateRows(1, 1, (row, key) => `${row.id}${key}`);
let childRows = generateRows(500, 1, (row, key) => `child${row.id}${key}`);
rows[0].children = childRows;
await generateTable(this, { rows });

let renderedRowCount = table.rows.length;
assert.ok(renderedRowCount < 500, 'some rows are occluded');

// Selecting the parent row will cause all child rows (ie the entire table)
// to also be selected
await table.selectRow(0);

assert.ok(
table.validateSelected(...allRenderedRowIndexes(table)),
`All ${renderedRowCount} rendered rows are selected`
);

// Deselect the first child row
await table.rows.objectAt(1).checkbox.click();

let expectedIndexes = allRenderedRowIndexes(table).filter(i => ![0, 1].includes(i));
assert.ok(
table.validateSelected(...expectedIndexes),
'All rendered rows other than row 0 (parent) and 1 (1st child) are selected'
);

// Toggle the parent row's checkbox on (selecting all rows) and then off (deselecting all rows)
await table.rows.objectAt(0).checkbox.click();
await table.rows.objectAt(0).checkbox.click();

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

// scroll all the way down
await scrollTo('[data-test-ember-table]', 0, 10000);

assert.ok(
table.validateSelected(),
'After scrolling to bottom, there are still no rows selected'
);
});
});
});
});