|
| 1 | +import {HarnessLoader} from '@angular/cdk/testing'; |
| 2 | +import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; |
| 3 | +import {Component} from '@angular/core'; |
| 4 | +import {ComponentFixture, TestBed} from '@angular/core/testing'; |
| 5 | +import {MatDividerModule} from '@angular/material/divider'; |
| 6 | +import {MatDividerHarness} from './divider-harness'; |
| 7 | + |
| 8 | +/** Shared tests to run on both the original and MDC-based dividers. */ |
| 9 | +export function runHarnessTests( |
| 10 | + dividerModule: typeof MatDividerModule, dividerHarness: typeof MatDividerHarness) { |
| 11 | + let fixture: ComponentFixture<DividerHarnessTest>; |
| 12 | + let loader: HarnessLoader; |
| 13 | + |
| 14 | + beforeEach(async () => { |
| 15 | + await TestBed.configureTestingModule({ |
| 16 | + imports: [dividerModule], |
| 17 | + declarations: [DividerHarnessTest], |
| 18 | + }).compileComponents(); |
| 19 | + |
| 20 | + fixture = TestBed.createComponent(DividerHarnessTest); |
| 21 | + fixture.detectChanges(); |
| 22 | + loader = TestbedHarnessEnvironment.loader(fixture); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should load all divider harnesses', async () => { |
| 26 | + const dividers = await loader.getAllHarnesses(dividerHarness); |
| 27 | + expect(dividers.length).toBe(2); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should check if divider is inset', async () => { |
| 31 | + const dividers = await loader.getAllHarnesses(dividerHarness); |
| 32 | + expect(await dividers[0].isInset()).toBe(false); |
| 33 | + expect(await dividers[1].isInset()).toBe(true); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should get divider orientation', async () => { |
| 37 | + const dividers = await loader.getAllHarnesses(dividerHarness); |
| 38 | + expect(await dividers[0].getOrientation()).toBe('horizontal'); |
| 39 | + expect(await dividers[1].getOrientation()).toBe('vertical'); |
| 40 | + }); |
| 41 | +} |
| 42 | + |
| 43 | +@Component({ |
| 44 | + template: ` |
| 45 | + <mat-divider></mat-divider> |
| 46 | + <mat-divider inset vertical></mat-divider> |
| 47 | + ` |
| 48 | +}) |
| 49 | +class DividerHarnessTest {} |
0 commit comments