|
| 1 | +import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing'; |
| 2 | +import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed'; |
| 3 | +import {MatGridListHarness, MatGridTileHarness} from '@angular/material/grid-list/testing'; |
| 4 | +import {HarnessLoader} from '@angular/cdk/testing'; |
| 5 | +import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} |
| 6 | + from '@angular/platform-browser-dynamic/testing'; |
| 7 | +import {MatGridListModule} from '@angular/material/grid-list'; |
| 8 | +import {GridListHarnessExample} from './grid-list-harness-example'; |
| 9 | + |
| 10 | +describe('GridListHarnessExample', () => { |
| 11 | + let fixture: ComponentFixture<GridListHarnessExample>; |
| 12 | + let loader: HarnessLoader; |
| 13 | + |
| 14 | + beforeAll(() => { |
| 15 | + TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); |
| 16 | + }); |
| 17 | + |
| 18 | + beforeEach( |
| 19 | + waitForAsync(() => { |
| 20 | + TestBed.configureTestingModule({ |
| 21 | + imports: [MatGridListModule], |
| 22 | + declarations: [GridListHarnessExample] |
| 23 | + }).compileComponents(); |
| 24 | + fixture = TestBed.createComponent(GridListHarnessExample); |
| 25 | + fixture.detectChanges(); |
| 26 | + loader = TestbedHarnessEnvironment.loader(fixture); |
| 27 | + }) |
| 28 | + ); |
| 29 | + |
| 30 | + it('should be able to load grid-list harnesses', async () => { |
| 31 | + const harnesses = await loader.getAllHarnesses(MatGridListHarness); |
| 32 | + expect(harnesses.length).toBe(1); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should be able to load grid-tile harnesses', async () => { |
| 36 | + const harnesses = await loader.getAllHarnesses(MatGridTileHarness); |
| 37 | + expect(harnesses.length).toBe(4); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should be able to get tiles of grid-list with filters', async () => { |
| 41 | + const gridList = await loader.getHarness(MatGridListHarness); |
| 42 | + const tiles = await gridList.getTiles({headerText: /Tile [34]/}); |
| 43 | + expect(tiles.length).toBe(2); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should be able to check whether tile has header', async () => { |
| 47 | + const tiles = await loader.getAllHarnesses(MatGridTileHarness); |
| 48 | + expect(await tiles[0].hasHeader()).toBe(false); |
| 49 | + expect(await (await tiles[0].host()).text()).toBe('Tile 1 (no header, no footer)'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('should be able to check whether tile has footer', async () => { |
| 53 | + const tiles = await loader.getAllHarnesses(MatGridTileHarness); |
| 54 | + expect(await tiles[2].hasFooter()).toBe(true); |
| 55 | + expect(await tiles[2].getFooterText()).toBe('Tile 3 footer'); |
| 56 | + }); |
| 57 | +}); |
0 commit comments