|
1 |
| -import {MatBottomSheetModule} from '@angular/material/bottom-sheet'; |
2 |
| -import {runHarnessTests} from '@angular/material/bottom-sheet/testing/shared.spec'; |
| 1 | +import {Component, TemplateRef, ViewChild} from '@angular/core'; |
| 2 | +import {ComponentFixture, TestBed} from '@angular/core/testing'; |
| 3 | +import {HarnessLoader} from '@angular/cdk/testing'; |
| 4 | +import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; |
| 5 | +import { |
| 6 | + MatBottomSheet, |
| 7 | + MatBottomSheetConfig, |
| 8 | + MatBottomSheetModule, |
| 9 | +} from '@angular/material/bottom-sheet'; |
| 10 | +import {NoopAnimationsModule} from '@angular/platform-browser/animations'; |
3 | 11 | import {MatBottomSheetHarness} from './bottom-sheet-harness';
|
4 | 12 |
|
5 |
| -describe('Non-MDC-based MatBottomSheetHarness', () => { |
6 |
| - runHarnessTests(MatBottomSheetModule, MatBottomSheetHarness); |
| 13 | +describe('MatBottomSheetHarness', () => { |
| 14 | + let fixture: ComponentFixture<BottomSheetHarnessTest>; |
| 15 | + let loader: HarnessLoader; |
| 16 | + |
| 17 | + beforeEach(async () => { |
| 18 | + await TestBed.configureTestingModule({ |
| 19 | + imports: [MatBottomSheetModule, NoopAnimationsModule], |
| 20 | + declarations: [BottomSheetHarnessTest], |
| 21 | + }).compileComponents(); |
| 22 | + |
| 23 | + fixture = TestBed.createComponent(BottomSheetHarnessTest); |
| 24 | + fixture.detectChanges(); |
| 25 | + loader = TestbedHarnessEnvironment.documentRootLoader(fixture); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should load harness for a bottom sheet', async () => { |
| 29 | + fixture.componentInstance.open(); |
| 30 | + const bottomSheets = await loader.getAllHarnesses(MatBottomSheetHarness); |
| 31 | + expect(bottomSheets.length).toBe(1); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should be able to get aria-label of the bottom sheet', async () => { |
| 35 | + fixture.componentInstance.open({ariaLabel: 'Confirm purchase.'}); |
| 36 | + const bottomSheet = await loader.getHarness(MatBottomSheetHarness); |
| 37 | + expect(await bottomSheet.getAriaLabel()).toBe('Confirm purchase.'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should be able to dismiss the bottom sheet', async () => { |
| 41 | + fixture.componentInstance.open(); |
| 42 | + let bottomSheets = await loader.getAllHarnesses(MatBottomSheetHarness); |
| 43 | + |
| 44 | + expect(bottomSheets.length).toBe(1); |
| 45 | + await bottomSheets[0].dismiss(); |
| 46 | + |
| 47 | + bottomSheets = await loader.getAllHarnesses(MatBottomSheetHarness); |
| 48 | + expect(bottomSheets.length).toBe(0); |
| 49 | + }); |
7 | 50 | });
|
| 51 | + |
| 52 | +@Component({ |
| 53 | + template: ` |
| 54 | + <ng-template> |
| 55 | + Hello from the bottom sheet! |
| 56 | + </ng-template> |
| 57 | + `, |
| 58 | +}) |
| 59 | +class BottomSheetHarnessTest { |
| 60 | + @ViewChild(TemplateRef) template: TemplateRef<any>; |
| 61 | + |
| 62 | + constructor(readonly bottomSheet: MatBottomSheet) {} |
| 63 | + |
| 64 | + open(config?: MatBottomSheetConfig) { |
| 65 | + return this.bottomSheet.open(this.template, config); |
| 66 | + } |
| 67 | +} |
0 commit comments