Skip to content

Commit

Permalink
fix(platform): fix unit tests fater refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
N1XUS committed Jun 13, 2023
1 parent 90d9759 commit 0ae7728
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class TableSelectionChangeEvent<T> {
/** Indexes location of additions or removals */
index: number[];
/** Whether `Check/Uncheck` all checkbox was pressed. */
all: boolean;
all?: boolean;
}

export class TableRowSelectionChangeEvent<T> extends TableSelectionChangeEvent<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<th
*ngIf="isShownSelectionColumn"
fd-table-cell
[focusable]="true"
[class.fd-table__cell--fixed]="fixed"
class="fd-table__cell--checkbox"
[style]="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
providers: [
{
provide: FDK_FOCUSABLE_LIST_DIRECTIVE,
useExisting: TableRowDirective
useExisting: TablePoppingRowComponent
},
DestroyedService
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
[class.fd-table__cell--fixed]="fixed"
role="cell"
fd-table-cell
[focusable]="true"
[style]="
_contentDensityObserver
| async
Expand Down
48 changes: 28 additions & 20 deletions libs/platform/src/lib/table/table.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ describe('TableComponent internal', () => {
added: [tableComponent._tableRowsVisible[0].value],
removed: [],
selection: [tableComponent._tableRowsVisible[0].value],
index: [0]
index: [0],
all: false
};

expect(emitSpy).toHaveBeenCalledWith(event1);
Expand All @@ -396,7 +397,8 @@ describe('TableComponent internal', () => {
added: [tableComponent._tableRowsVisible[1].value],
removed: event1.added,
selection: [tableComponent._tableRowsVisible[1].value],
index: [1, 0]
index: [1, 0],
all: false
};

expect(emitSpy).toHaveBeenCalledWith(event2);
Expand Down Expand Up @@ -468,7 +470,8 @@ describe('TableComponent internal', () => {
selection: [tableComponent._tableRowsVisible[0].value],
added: [tableComponent._tableRowsVisible[0].value],
removed: [],
index: [0]
index: [0],
all: false
};

expect(emitSpy).toHaveBeenCalledWith(event1);
Expand All @@ -484,7 +487,8 @@ describe('TableComponent internal', () => {
],
added: [tableComponent._tableRowsVisible[1].value],
removed: [],
index: [1]
index: [1],
all: false
};

expect(emitSpy).toHaveBeenCalledWith(event2);
Expand All @@ -497,7 +501,8 @@ describe('TableComponent internal', () => {
selection: [tableComponent._tableRowsVisible[1].value],
added: [],
removed: [tableComponent._tableRowsVisible[0].value],
index: [0]
index: [0],
all: false
};

expect(emitSpy).toHaveBeenCalledWith(event3);
Expand Down Expand Up @@ -1030,11 +1035,16 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {
let tableBodyRows: DebugElement[] = [];
let tableRowTogglerCellsArray: DebugElement[] = [];

let firstRowToggler: DebugElement;
let secondRowToggler: DebugElement;

const calculateTableElementsMetaData = (): void => {
tableBodyRows = fixture.debugElement.queryAll(By.css('.fdp-table__body tbody .fd-table__row'));
tableRowTogglerCellsArray = fixture.debugElement.queryAll(
By.css('.fdp-table__body tbody .fd-table__row .fd-table__cell--expand')
);
firstRowToggler = tableRowTogglerCellsArray[0];
secondRowToggler = tableRowTogglerCellsArray[1];
};

beforeEach(waitForAsync(() => {
Expand Down Expand Up @@ -1067,14 +1077,8 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {
});

describe('Collapsing/Expanding', () => {
let firstRowToggler: DebugElement;
let secondRowToggler: DebugElement;

beforeEach(() => {
calculateTableElementsMetaData();

firstRowToggler = tableRowTogglerCellsArray[0];
secondRowToggler = tableRowTogglerCellsArray[1];
});

it('should emit event when parent item collapsed/expanded', () => {
Expand All @@ -1090,6 +1094,8 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {

expect(emitSpy).toHaveBeenCalledWith(event1);

calculateTableElementsMetaData();

secondRowToggler.nativeElement.dispatchEvent(new MouseEvent('click'));

const secondRowIndex = 1 + treeItemsChildrenPerParentCount;
Expand All @@ -1103,11 +1109,15 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {
expect(emitSpy.calls.argsFor(1)).toEqual([event2]);
});

it('should react to toggling/collapsing with changing rows count', () => {
it('should react to toggling/collapsing with changing rows count', async () => {
firstRowToggler.nativeElement.dispatchEvent(new MouseEvent('click'));

// debugger;

fixture.detectChanges();

await fixture.whenStable();

calculateTableElementsMetaData();

expect(tableBodyRows.length).toEqual(treeItemParentsCount + treeItemsChildrenPerParentCount);
Expand All @@ -1116,6 +1126,8 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {

fixture.detectChanges();

await fixture.whenStable();

calculateTableElementsMetaData();

expect(tableBodyRows.length).toEqual(treeItemParentsCount + treeItemsChildrenPerParentCount * 2);
Expand All @@ -1124,6 +1136,8 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {

fixture.detectChanges();

await fixture.whenStable();

calculateTableElementsMetaData();

expect(tableBodyRows.length).toEqual(treeItemParentsCount + treeItemsChildrenPerParentCount);
Expand All @@ -1132,15 +1146,15 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {

fixture.detectChanges();

await fixture.whenStable();

calculateTableElementsMetaData();

expect(tableBodyRows.length).toEqual(treeItemParentsCount);
});
});

describe('Drag & Drop', () => {
let firstRowToggler: DebugElement;

beforeEach(() => {
calculateTableElementsMetaData();

Expand Down Expand Up @@ -1424,9 +1438,6 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {
hostComponent.table.selectionMode = SelectionMode.MULTIPLE;
hostComponent.table.ngAfterViewInit();

console.log('XXX', hostComponent.table._tableRows[0].checked);
console.log('XXX', hostComponent.table._tableRows[0].children[0].checked);

const emitChangeSpy = spyOn(hostComponent.table.rowSelectionChange, 'emit').and.stub();
hostComponent.table._toggleMultiSelectRow(hostComponent.table._tableRows[0].children[0]);

Expand All @@ -1442,9 +1453,6 @@ class TreeTableDataProviderMock extends TableDataProvider<SourceTreeItem> {
hostComponent.table.selectionMode = SelectionMode.MULTIPLE;
hostComponent.table.ngAfterViewInit();

console.log('XXX', hostComponent.table._tableRows[0].checked);
console.log('XXX', hostComponent.table._tableRows[0].children[0].checked);

const emitChangeSpy = spyOn(hostComponent.table.rowSelectionChange, 'emit').and.stub();
hostComponent.table._toggleMultiSelectRow(hostComponent.table._tableRows[0].children[0]);
expect(emitChangeSpy).toHaveBeenCalled();
Expand Down
4 changes: 2 additions & 2 deletions libs/platform/src/lib/table/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ export class TableComponent<T = any>
@Input()
trackBy: TrackByFunction<T>;
/**
* An optional function, that identifies uniqueness of a particular row.
* Table component uses it to be able to preserve selection when data list is changed.
* An optional function that identifies uniqueness of a particular row.
* Table component uses it to be able to preserve selection when a data list is changed.
*/
@Input()
rowComparator: RowComparator<T>;
Expand Down

0 comments on commit 0ae7728

Please sign in to comment.