|
| 1 | +import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing'; |
| 2 | +import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; |
| 3 | +import {HarnessLoader, parallel} from '@angular/cdk/testing'; |
| 4 | +import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} |
| 5 | + from '@angular/platform-browser-dynamic/testing'; |
| 6 | +import {IconHarnessExample} from './icon-harness-example'; |
| 7 | +import {MatIconModule, MatIconRegistry} from '@angular/material/icon'; |
| 8 | +import {MatIconHarness} from '@angular/material/icon/testing'; |
| 9 | +import {DomSanitizer} from '@angular/platform-browser'; |
| 10 | + |
| 11 | + |
| 12 | +describe('IconHarnessExample', () => { |
| 13 | + let fixture: ComponentFixture<IconHarnessExample>; |
| 14 | + let loader: HarnessLoader; |
| 15 | + |
| 16 | + beforeAll(() => { |
| 17 | + TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); |
| 18 | + }); |
| 19 | + |
| 20 | + beforeEach( |
| 21 | + waitForAsync(() => { |
| 22 | + TestBed.configureTestingModule({ |
| 23 | + imports: [MatIconModule], |
| 24 | + declarations: [IconHarnessExample] |
| 25 | + }).compileComponents(); |
| 26 | + }) |
| 27 | + ); |
| 28 | + |
| 29 | + beforeEach(() => { |
| 30 | + const registry = TestBed.inject(MatIconRegistry); |
| 31 | + const sanitizer = TestBed.inject(DomSanitizer); |
| 32 | + |
| 33 | + // We use `bypassSecurityTrustHtml` exclusively for testing here. |
| 34 | + registry.addSvgIconLiteralInNamespace('svgIcons', 'svgIcon', |
| 35 | + sanitizer.bypassSecurityTrustHtml('<svg></svg>')); |
| 36 | + |
| 37 | + fixture = TestBed.createComponent(IconHarnessExample); |
| 38 | + fixture.detectChanges(); |
| 39 | + loader = TestbedHarnessEnvironment.loader(fixture); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should load all icon harnesses', async () => { |
| 43 | + const icons = await loader.getAllHarnesses(MatIconHarness); |
| 44 | + expect(icons.length).toBe(3); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should get the name of an icon', async () => { |
| 48 | + const icons = await loader.getAllHarnesses(MatIconHarness); |
| 49 | + const names = await parallel(() => icons.map(icon => icon.getName())); |
| 50 | + expect(names).toEqual(['fontIcon', 'svgIcon', 'ligature_icon']); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should get the namespace of an icon', async () => { |
| 54 | + const icons = await loader.getAllHarnesses(MatIconHarness); |
| 55 | + const namespaces = await parallel(() => icons.map(icon => icon.getNamespace())); |
| 56 | + expect(namespaces).toEqual(['fontIcons', 'svgIcons', null]); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should get whether an icon is inline', async () => { |
| 60 | + const icons = await loader.getAllHarnesses(MatIconHarness); |
| 61 | + const inlineStates = await parallel(() => icons.map(icon => icon.isInline())); |
| 62 | + expect(inlineStates).toEqual([false, false, true]); |
| 63 | + }); |
| 64 | +}); |
0 commit comments