* Performs a sequence of sorting on a single column to see if the sort directions are * consistent with expectations. Detects any changes in the fixture to reflect any changes in * the inputs and resets the MatSort to remove any side effects from previous tests.
( fixture: ComponentFixture<SimpleMatSortApp | MatSortWithoutExplicitInputs>, expectedSequence: SortDirection[], id: SimpleMatSortAppColumnIds = 'defaultA', )
| 407 | * the inputs and resets the MatSort to remove any side effects from previous tests. |
| 408 | */ |
| 409 | function testSingleColumnSortDirectionSequence( |
| 410 | fixture: ComponentFixture<SimpleMatSortApp | MatSortWithoutExplicitInputs>, |
| 411 | expectedSequence: SortDirection[], |
| 412 | id: SimpleMatSortAppColumnIds = 'defaultA', |
| 413 | ) { |
| 414 | // Detect any changes that were made in preparation for this sort sequence |
| 415 | fixture.detectChanges(); |
| 416 | |
| 417 | // Reset the sort to make sure there are no side affects from previous tests |
| 418 | const component = fixture.componentInstance; |
| 419 | component.matSort.active = ''; |
| 420 | component.matSort.direction = ''; |
| 421 | |
| 422 | // Run through the sequence to confirm the order |
| 423 | const actualSequence = expectedSequence.map(() => { |
| 424 | component.sort(id); |
| 425 | |
| 426 | // Check that the sort event's active sort is consistent with the MatSort |
| 427 | expect(component.matSort.active).toBe(id); |
| 428 | expect(component.latestSortEvent.active).toBe(id); |
| 429 | |
| 430 | // Check that the sort event's direction is consistent with the MatSort |
| 431 | expect(component.matSort.direction).toBe(component.latestSortEvent.direction); |
| 432 | return component.matSort.direction; |
| 433 | }); |
| 434 | expect(actualSequence).toEqual(expectedSequence); |
| 435 | |
| 436 | // Expect that performing one more sort will loop it back to the beginning. |
| 437 | component.sort(id); |
| 438 | expect(component.matSort.direction).toBe(expectedSequence[0]); |
| 439 | } |
| 440 | |
| 441 | /** Column IDs of the SimpleMatSortApp for typing of function params in the component (e.g. sort) */ |
| 442 | type SimpleMatSortAppColumnIds = 'defaultA' | 'defaultB' | 'overrideStart' | 'overrideDisableClear'; |
no test coverage detected
searching dependent graphs…