[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', () => {
beforeEach(() => {
spyOn(dataTable, 'resetSelection').and.callThrough();
spyOn(dataTable.selectedItemsCountChanged, 'emit');
dataTable.data = new ObjectDataTableAdapter([{ name: '1' }, { name: '2' }], [new ObjectDataColumn({ key: 'name' })]);
const rows = dataTable.data.getRows();
@@ -440,6 +441,9 @@ describe('DataTable', () => {
});
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', () => {
@@ -448,6 +452,9 @@ describe('DataTable', () => {
});
expect(dataTable.selection).toEqual([]);
expect(dataTable.selectedItemsCountChanged.emit).toHaveBeenCalledWith(0);
expect(dataTable.isSelectAllIndeterminate).toBe(false);
expect(dataTable.isSelectAllChecked).toBe(false);
});
});
@@ -930,7 +937,7 @@ describe('DataTable', () => {
);
const rows = dataTable.data.getRows();
const event = new MouseEvent('click');
Object.defineProperty(event, 'target', { value: { hasAttribute: () => null, closest: () => null} });
Object.defineProperty(event, 'target', { value: { hasAttribute: () => null, closest: () => null } });
spyOn(dataTable, 'onRowClick');
dataTable.onCheckboxLabelClick(rows[0], event);
@@ -943,7 +950,7 @@ describe('DataTable', () => {
const event = new MouseEvent('click');
Object.defineProperty(event, 'target', {
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',
closest: () => null
}
@@ -958,7 +965,7 @@ describe('DataTable', () => {
const data = new ObjectDataTableAdapter([{}, {}], []);
const rows = data.getRows();
const event = new MouseEvent('click');
Object.defineProperty(event, 'target', { value: { hasAttribute: () => null, closest: () => 'element'} });
Object.defineProperty(event, 'target', { value: { hasAttribute: () => null, closest: () => 'element' } });
spyOn(dataTable, 'onRowClick');
dataTable.onCheckboxLabelClick(rows[0], event);

View File

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