Skip to content

Commit

Permalink
fix: clear client-side selection when changing selection mode (#6720) (
Browse files Browse the repository at this point in the history
…#6722)

* fix: clear client-side selection when changing selection mode

* replace IT with connector test

Co-authored-by: Sascha Ißbrücker <[email protected]>
  • Loading branch information
vaadin-bot and sissbruecker authored Oct 14, 2024
1 parent ee21626 commit 5a3b0a1
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { expect, fixtureSync, nextFrame } from '@open-wc/testing';
import { init, getBodyCellContent, setRootItems, initSelectionColumn } from './shared.js';
import type { FlowGrid } from './shared.js';

describe('grid connector - change selection mode', () => {
let grid: FlowGrid;

function clickSelectCheckbox(row: number) {
getBodyCellContent(grid, row, 0)!.querySelector('vaadin-checkbox')!.click();
}

beforeEach(async () => {
grid = fixtureSync(`
<vaadin-grid>
<vaadin-grid-flow-selection-column></vaadin-grid-flow-selection-column>
<vaadin-grid-column path="name"></vaadin-grid-column>
</vaadin-grid>
`);

init(grid);

const selectionColumn = grid.querySelector('vaadin-grid-flow-selection-column')!;
initSelectionColumn(grid, selectionColumn);

setRootItems(grid.$connector, [
{ key: '0', name: 'foo' },
{ key: '1', name: 'bar' }
]);
await nextFrame();
});

describe('clear selection', () => {
it('should clear selection when changing from single to none', () => {
grid.$connector.setSelectionMode('SINGLE');
getBodyCellContent(grid, 0, 0)!.click();
expect(grid.selectedItems.length).to.equal(1);

grid.$connector.setSelectionMode('NONE');

expect(grid.selectedItems).to.be.empty;
});

it('should clear selection when changing from single to multi ', () => {
grid.$connector.setSelectionMode('SINGLE');
getBodyCellContent(grid, 0, 0)!.click();
expect(grid.selectedItems.length).to.equal(1);

grid.$connector.setSelectionMode('MULTI');

expect(grid.selectedItems).to.be.empty;
});

it('should clear selection when changing from multi to none', () => {
grid.$connector.setSelectionMode('MULTI');
clickSelectCheckbox(0);
clickSelectCheckbox(1);
expect(grid.selectedItems.length).to.equal(2);

grid.$connector.setSelectionMode('NONE');

expect(grid.selectedItems).to.be.empty;
});

it('should clear selection when changing from multi to single', () => {
grid.$connector.setSelectionMode('MULTI');
clickSelectCheckbox(0);
clickSelectCheckbox(1);
expect(grid.selectedItems.length).to.equal(2);

grid.$connector.setSelectionMode('SINGLE');

expect(grid.selectedItems).to.be.empty;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,7 @@ import { GridFlowSelectionColumn } from "./vaadin-grid-flow-selection-column.js"
if ((typeof mode === 'string' || mode instanceof String) && validSelectionModes.indexOf(mode) >= 0) {
selectionMode = mode;
selectedKeys = {};
grid.selectedItems = [];
grid.$connector.updateMultiSelectable();
} else {
throw 'Attempted to set an invalid selection mode';
Expand Down

0 comments on commit 5a3b0a1

Please sign in to comment.