Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 19 additions & 1 deletion src/utilities/selection/Selection.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let { expect } = chai;

import { Selection } from './index';
import { Selection, IObjectWithKey } from './index';

let setA = [ { key: 'a' }, { key: 'b' }, { key: 'c' } ];
let setB = [ { key: 'a' }, { key: 'd' }, { key: 'b' } ];
Expand Down Expand Up @@ -52,4 +52,22 @@ describe('Selection', () => {
expect(changeCount).equals(10, 'after range selecting from 0 to 2');
});

it('returns false on isAllSelected when no items are selectable', () => {
let changeEvents = 0;
let selection = new Selection({
canSelectItem: (item: IObjectWithKey) => false,
onSelectionChanged: () => changeEvents++
});

selection.setItems(setA);

expect(selection.isAllSelected()).to.equal(false, 'isAllSelected was not false after initialization');

selection.setAllSelected(true);

expect(selection.isAllSelected()).to.equal(false, 'isAllSelected was not false after trying to select all the unselectables');

expect(changeEvents).to.equal(0, 'changeEvents were not 0');
});

});
8 changes: 6 additions & 2 deletions src/utilities/selection/Selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ export class Selection implements ISelection {
}

public isAllSelected(): boolean {
let selectableCount = this._items.length - this._unselectableCount;

return (
(this.count > 0) &&
(this._isAllSelected && this._exemptedCount === 0) ||
(!this._isAllSelected && (this._exemptedCount === this._items.length - this._unselectableCount) && this._items.length > 0));
(!this._isAllSelected && (this._exemptedCount === selectableCount) && selectableCount > 0));
}

public isKeySelected(key: string): boolean {
Expand All @@ -176,7 +178,9 @@ export class Selection implements ISelection {
}

public setAllSelected(isAllSelected: boolean) {
if (this._exemptedCount > 0 || isAllSelected !== this._isAllSelected) {
let selectableCount = this._items ? (this._items.length - this._unselectableCount) : 0;

if (selectableCount > 0 && (this._exemptedCount > 0 || isAllSelected !== this._isAllSelected)) {
this._exemptedIndices = {};
this._exemptedCount = 0;
this._isAllSelected = isAllSelected;
Expand Down