|
| 1 | +import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing'; |
| 2 | +import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; |
| 3 | +import {MatTooltipHarness} from '@angular/material/tooltip/testing'; |
| 4 | +import {HarnessLoader} from '@angular/cdk/testing'; |
| 5 | +import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} |
| 6 | + from '@angular/platform-browser-dynamic/testing'; |
| 7 | +import {MatTooltipModule} from '@angular/material/tooltip'; |
| 8 | +import {TooltipHarnessExample} from './tooltip-harness-example'; |
| 9 | +import {NoopAnimationsModule} from '@angular/platform-browser/animations'; |
| 10 | + |
| 11 | +describe('TooltipHarnessExample', () => { |
| 12 | + let fixture: ComponentFixture<TooltipHarnessExample>; |
| 13 | + let loader: HarnessLoader; |
| 14 | + |
| 15 | + beforeAll(() => { |
| 16 | + TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); |
| 17 | + }); |
| 18 | + |
| 19 | + beforeEach( |
| 20 | + waitForAsync(() => { |
| 21 | + TestBed.configureTestingModule({ |
| 22 | + imports: [MatTooltipModule, NoopAnimationsModule], |
| 23 | + declarations: [TooltipHarnessExample] |
| 24 | + }).compileComponents(); |
| 25 | + fixture = TestBed.createComponent(TooltipHarnessExample); |
| 26 | + fixture.detectChanges(); |
| 27 | + loader = TestbedHarnessEnvironment.loader(fixture); |
| 28 | + }) |
| 29 | + ); |
| 30 | + |
| 31 | + it('should load all tooltip harnesses', async () => { |
| 32 | + const tooltips = await loader.getAllHarnesses(MatTooltipHarness); |
| 33 | + expect(tooltips.length).toBe(2); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should be able to show a tooltip', async () => { |
| 37 | + const tooltip = await loader.getHarness(MatTooltipHarness.with({selector: '#one'})); |
| 38 | + expect(await tooltip.isOpen()).toBe(false); |
| 39 | + await tooltip.show(); |
| 40 | + expect(await tooltip.isOpen()).toBe(true); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should be able to hide a tooltip', async () => { |
| 44 | + const tooltip = await loader.getHarness(MatTooltipHarness.with({selector: '#one'})); |
| 45 | + expect(await tooltip.isOpen()).toBe(false); |
| 46 | + await tooltip.show(); |
| 47 | + expect(await tooltip.isOpen()).toBe(true); |
| 48 | + await tooltip.hide(); |
| 49 | + expect(await tooltip.isOpen()).toBe(false); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should be able to get the text of a tooltip', async () => { |
| 53 | + const tooltip = await loader.getHarness(MatTooltipHarness.with({selector: '#one'})); |
| 54 | + await tooltip.show(); |
| 55 | + expect(await tooltip.getTooltipText()).toBe('Tooltip message'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should return empty when getting the tooltip text while closed', async () => { |
| 59 | + const tooltip = await loader.getHarness(MatTooltipHarness.with({selector: '#one'})); |
| 60 | + expect(await tooltip.getTooltipText()).toBe(''); |
| 61 | + }); |
| 62 | +}); |
0 commit comments