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

Refactor helper function function to test the semi-automatic refactoring #991

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
32 changes: 17 additions & 15 deletions tests/integration/components/selection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@ import { registerTestWarnHandler } from '../../helpers/warn-handlers';
import { runInDebug } from '@ember/debug';

let table = new TablePage({
/**
* Validates that the given selected indexes correspond to selected rows.
* Throws an error if any index does not match the expected selection state.
*
* @param {...number} selectedIndexes The indexes that should be selected
* @returns {boolean} valid
*/
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 seenIndexes = new Set();

// Check if every selected index corresponds to a selected row
let valid = selectedIndexes.every((row, index) => {
seenIndexes.add(index);
return row.isSelected;
});

let unseenIndexes = selectedIndexes.filter(i => !indexesSeen.includes(i));
if (unseenIndexes.length) {
// Get any indexes we missed
let unseenIndexes = new Set(selectedIndexes.filter(i => !seenIndexes.has(i)));
if (unseenIndexes.size) {
throw new Error(
`could not validateSelected because these indexes were not checked: ${unseenIndexes.join(
','
)}`
`Could not validate selected indexes: ${[...unseenIndexes].join(',')} were not checked`
);
}

Expand Down