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
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import * as React from 'react';
import { spy } from 'sinon';
import { RefObject } from '@mui/x-internals/types';
import { getCell, getColumnValues, getRows, includeRowSelection } from 'test/utils/helperFn';
import {
getCell,
getColumnValues,
getRows,
includeRowSelection,
excludeRowSelection,
} from 'test/utils/helperFn';
import { createRenderer, screen, act, fireEvent } from '@mui/internal-test-utils';
import {
GridApi,
Expand Down Expand Up @@ -1283,6 +1289,25 @@ describe('<DataGridPro /> - Row selection', () => {
});
});

describe('apiRef: getPropagatedRowSelectionModel', () => {
it('`getPropagatedRowSelectionModel` should return exclude models unchanged', () => {
render(<TreeDataGrid rowSelectionPropagation={{ descendants: true, parents: true }} />);

// Exclude models are not affected by propagation
const excludeModel = excludeRowSelection([1]);
const propagatedModel = apiRef.current?.getPropagatedRowSelectionModel(excludeModel);

expect(propagatedModel).to.equal(excludeModel); // same object

// Include models are affected by propagation
const includeModel = includeRowSelection([1]);
const propagatedIncludeModel = apiRef.current?.getPropagatedRowSelectionModel(includeModel);

expect(propagatedIncludeModel?.type).to.equal('include');
expect(propagatedIncludeModel?.ids).to.have.keys([1, 2, 3, 4, 5, 6, 7]);
});
});

it('should select only filtered rows after filter is applied', async () => {
const { user } = render(<TestDataGridSelection checkboxSelection />);
const selectAll = screen.getByRole('checkbox', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ export const useGridRowSelection = (
if (
!isNestedData ||
!applyAutoSelection ||
inputSelectionModel.type === 'exclude' ||
(inputSelectionModel.ids.size === 0 && inputSelectionModel.type === 'include')
) {
return inputSelectionModel;
Expand Down
4 changes: 4 additions & 0 deletions test/utils/helperFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,7 @@ export function getSelectByName(name: string) {
export const includeRowSelection = (ids: GridRowId[]) => {
return { type: 'include', ids: new Set(ids) } as const;
};

export const excludeRowSelection = (ids: GridRowId[]) => {
return { type: 'exclude', ids: new Set(ids) } as const;
};
Loading