Skip to content

Commit

Permalink
add tests for selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ksercs committed Oct 5, 2024
1 parent 519fcb9 commit 2cb9065
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,54 @@ QUnit.module('onSelectionChanging', {
assert.strictEqual(selectionChangingHandler.callCount, 2, 'selectionChanging is called once');
});

QUnit.test('isItemSelected should work correctly after selection change is cancelled', function(assert) {
let cancelSelectionChange = false;
const selectionChangingHandler = sinon.spy((args) => {
args.cancel = cancelSelectionChange;
});

const selection = new Selection({
...this.basicSelectionConfig,
onSelectionChanging: selectionChangingHandler
});

this.dataSource.load();

const firstItem = this.data[0];

cancelSelectionChange = false;
selection.select(firstItem);

cancelSelectionChange = true;
selection.deselect(firstItem);

const isFirstItemSelected = selection.isItemSelected(firstItem);
assert.strictEqual(isFirstItemSelected, true, 'item is still selected after canceled deselect');
});

QUnit.test('getSelectAllState should work correctly after selection change is cancelled', function(assert) {
let cancelSelectionChange = false;
const selectionChangingHandler = sinon.spy((args) => {
args.cancel = cancelSelectionChange;
});

const selection = new Selection({
...this.basicSelectionConfig,
onSelectionChanging: selectionChangingHandler
});

this.dataSource.load();

cancelSelectionChange = false;
selection.selectAll(true);

cancelSelectionChange = true;
selection.deselect(true);

const areAllItemsSelected = selection.getSelectAllState(true);
assert.strictEqual(areAllItemsSelected, true, 'items are still selected after canceled deselectAll');
});

QUnit.module('select all by one page', {
beforeEach: function() {
this.dataSource = createDataSource(this.data, {}, { paginate: true, pageSize: 3 });
Expand Down

0 comments on commit 2cb9065

Please sign in to comment.