[ACS-8663] Fixed issue where datatable selection was not getting reset completely in some cases (#10136)

* [ACS-8663] Fixed issue where datatable selection was not getting reset completely in some cases

* [ACS-8663] Updated unit tests
This commit is contained in:
swapnil-verma-gl
2024-08-29 20:35:13 +05:30
committed by GitHub
parent ea2042e0ff
commit ac317f82d1
2 changed files with 12 additions and 3 deletions

View File

@@ -423,6 +423,7 @@ describe('DataTable', () => {
describe('Selection reset', () => { describe('Selection reset', () => {
beforeEach(() => { beforeEach(() => {
spyOn(dataTable, 'resetSelection').and.callThrough(); spyOn(dataTable, 'resetSelection').and.callThrough();
spyOn(dataTable.selectedItemsCountChanged, 'emit');
dataTable.data = new ObjectDataTableAdapter([{ name: '1' }, { name: '2' }], [new ObjectDataColumn({ key: 'name' })]); dataTable.data = new ObjectDataTableAdapter([{ name: '1' }, { name: '2' }], [new ObjectDataColumn({ key: 'name' })]);
const rows = dataTable.data.getRows(); const rows = dataTable.data.getRows();
@@ -440,6 +441,9 @@ describe('DataTable', () => {
}); });
expect(dataTable.selection).toEqual([]); expect(dataTable.selection).toEqual([]);
expect(dataTable.selectedItemsCountChanged.emit).toHaveBeenCalledWith(0);
expect(dataTable.isSelectAllIndeterminate).toBe(false);
expect(dataTable.isSelectAllChecked).toBe(false);
}); });
it('should reset selection on multiselect change', () => { it('should reset selection on multiselect change', () => {
@@ -448,6 +452,9 @@ describe('DataTable', () => {
}); });
expect(dataTable.selection).toEqual([]); expect(dataTable.selection).toEqual([]);
expect(dataTable.selectedItemsCountChanged.emit).toHaveBeenCalledWith(0);
expect(dataTable.isSelectAllIndeterminate).toBe(false);
expect(dataTable.isSelectAllChecked).toBe(false);
}); });
}); });
@@ -943,7 +950,7 @@ describe('DataTable', () => {
const event = new MouseEvent('click'); const event = new MouseEvent('click');
Object.defineProperty(event, 'target', { Object.defineProperty(event, 'target', {
value: { value: {
getAttribute: (attr: string) => attr === 'data-adf-datatable-row-checkbox' ? 'data-adf-datatable-row-checkbox' : null, getAttribute: (attr: string) => (attr === 'data-adf-datatable-row-checkbox' ? 'data-adf-datatable-row-checkbox' : null),
hasAttribute: (attr: string) => attr === 'data-adf-datatable-row-checkbox', hasAttribute: (attr: string) => attr === 'data-adf-datatable-row-checkbox',
closest: () => null closest: () => null
} }

View File

@@ -619,6 +619,8 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
this.selection = []; this.selection = [];
} }
this.isSelectAllChecked = false; this.isSelectAllChecked = false;
this.isSelectAllIndeterminate = false;
this.selectedItemsCountChanged.emit(0);
} }
onRowDblClick(row: DataRow, event?: Event) { onRowDblClick(row: DataRow, event?: Event) {