Skip to content

Commit

Permalink
ACS-6323 Unit tests and function renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderSklorz committed Dec 8, 2023
1 parent 4691ae7 commit 4464b85
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<adf-datatable-row
cdkDropList
cdkDropListOrientation="horizontal"
[cdkDropListSortPredicate]="sortPredicate"
[cdkDropListSortPredicate]="filterDisabledColumns"
data-automation-id="datatable-row-header"
[disabled]="!isHeaderVisible()"
class="adf-datatable-row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { DataColumnComponent } from '../../data-column/data-column.component';
import { TranslateModule } from '@ngx-translate/core';
import { domSanitizerMock } from '../../../mock/dom-sanitizer-mock';
import { matIconRegistryMock } from '../../../mock/mat-icon-registry-mock';
import { CdkDragDrop } from '@angular/cdk/drag-drop';
import { CdkDrag, CdkDragDrop, CdkDropList } from '@angular/cdk/drag-drop';
import { take } from 'rxjs/operators';
import { By } from '@angular/platform-browser';
import { mockCarsData, mockCarsSchemaDefinition } from '../mocks/datatable.mock';
Expand Down Expand Up @@ -213,6 +213,13 @@ describe('DataTable', () => {
describe('Header modes', () => {
const newData = new ObjectDataTableAdapter([{ name: '1' }, { name: '2' }], [new ObjectDataColumn({ key: 'name' })]);
const emptyData = new ObjectDataTableAdapter();
const getDropList = (): CdkDropList => {
dataTable.showHeader = ShowHeaderMode.Data;
dataTable.loading = false;
dataTable.data = newData;
fixture.detectChanges();
return fixture.debugElement.query(By.directive(CdkDropList)).injector.get(CdkDropList);
};

it('should show the header if showHeader is `Data` and there is data', () => {
dataTable.showHeader = ShowHeaderMode.Data;
Expand Down Expand Up @@ -285,6 +292,32 @@ describe('DataTable', () => {
dataTable.loading = true;
testNotShownHeader(emptyData);
});

it('should have assigned filterDisabledColumns to sortPredicate of CdkDropList', () => {
expect(getDropList().sortPredicate).toBeDefined();
});

it('should sortPredicate from CdkDropList return true if column is enabled', () => {
const dropList = getDropList();
spyOn(dropList, 'getSortedItems').and.returnValue([{
disabled: true
}, {
disabled: false
}] as CdkDrag[]);

expect(dropList.sortPredicate(1, undefined, dropList)).toBeTrue();
});

it('should sortPredicate from CdkDropList return false if column is disabled', () => {
const dropList = getDropList();
spyOn(dropList, 'getSortedItems').and.returnValue([{
disabled: true
}, {
disabled: true
}] as CdkDrag[]);

expect(dropList.sortPredicate(1, undefined, dropList)).toBeFalse();
});
});

it('should emit "sorting-changed" DOM event', (done) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ export class DataTableComponent implements OnInit, AfterContentInit, OnChanges,
return `0 1 ${width < DataTableComponent.MINIMUM_COLUMN_SIZE ? DataTableComponent.MINIMUM_COLUMN_SIZE : width}px`;
}

sortPredicate(index: number, _drag: CdkDrag, drop: CdkDropList): boolean {
filterDisabledColumns(index: number, _drag: CdkDrag, drop: CdkDropList): boolean {
return !drop.getSortedItems()[index].disabled;
}

Expand Down

0 comments on commit 4464b85

Please sign in to comment.