forked from swimlane/ngx-datatable
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: apply even/odd classes correctly when rows are grouped
BREAKING CHANGE: The type of `CellContext.rowIndex` was changed from `number` to `{ index: number; indexInGroup?: number; }`. The type of `CellContext.rowIndex` was actually never just `number` (as it was typed), instead it was `number | string`. `string` was used if the row was wrapped in a group and followed this pattern `<indexOfTheGroup>-<indexInsideTheGroup>`. The new interface now allows easy access to both properties and does now longer require any typecasting.
- Loading branch information
1 parent
cf3e343
commit bd9a65b
Showing
8 changed files
with
93 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 41 additions & 9 deletions
50
projects/ngx-datatable/src/lib/components/body/body-row.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,60 @@ | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
import { DataTableBodyRowComponent } from './body-row.component'; | ||
import { DataTableBodyCellComponent } from './body-cell.component'; | ||
import { Component } from '@angular/core'; | ||
import { RowIndex } from '../../types/public.types'; | ||
import { ScrollbarHelper } from '../../services/scrollbar-helper.service'; | ||
import { TableColumn } from '../../types/table-column.type'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
describe('DataTableBodyRowComponent', () => { | ||
let fixture: ComponentFixture<DataTableBodyRowComponent>; | ||
let component: DataTableBodyRowComponent; | ||
@Component({ | ||
template: ` <datatable-body-row [rowIndex]="rowIndex" [row]="row" [columns]="columns" /> `, | ||
imports: [DataTableBodyRowComponent], | ||
standalone: true | ||
}) | ||
class TestHostComponent { | ||
rowIndex: RowIndex = { index: 0 }; | ||
row: any = { prop: 'value' }; | ||
columns: TableColumn[] = [{ prop: 'prop', $$valueGetter: () => 'value' }]; | ||
} | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let component: TestHostComponent; | ||
|
||
// provide our implementations or mocks to the dependency injector | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [DataTableBodyCellComponent, DataTableBodyRowComponent] | ||
imports: [TestHostComponent], | ||
providers: [ScrollbarHelper] | ||
}); | ||
}); | ||
|
||
beforeEach(waitForAsync(() => { | ||
TestBed.compileComponents().then(() => { | ||
fixture = TestBed.createComponent(DataTableBodyRowComponent); | ||
fixture = TestBed.createComponent(TestHostComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
})); | ||
|
||
describe('fixture', () => { | ||
it('should have a component instance', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
it('should apply odd/event without groups', () => { | ||
component.rowIndex = { index: 0 }; | ||
fixture.detectChanges(); | ||
const element = fixture.debugElement.query(By.directive(DataTableBodyRowComponent)) | ||
.nativeElement as HTMLElement; | ||
expect(element.classList).toContain('datatable-row-even'); | ||
component.rowIndex = { index: 3 }; | ||
fixture.detectChanges(); | ||
expect(element.classList).toContain('datatable-row-odd'); | ||
}); | ||
|
||
it('should apply event odd/even if row is grouped', () => { | ||
component.rowIndex = { index: 1, indexInGroup: 0 }; | ||
fixture.detectChanges(); | ||
const element = fixture.debugElement.query(By.directive(DataTableBodyRowComponent)) | ||
.nativeElement as HTMLElement; | ||
expect(element.classList).toContain('datatable-row-even'); | ||
component.rowIndex = { index: 666, indexInGroup: 3 }; | ||
fixture.detectChanges(); | ||
expect(element.classList).toContain('datatable-row-odd'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters