Skip to content

docs(material/grid-list): add harness example for grid-list #21470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components-examples/material/grid-list/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ ng_module(
]),
module_name = "@angular/components-examples/material/grid-list",
deps = [
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/grid-list",
"//src/material/grid-list/testing",
"@npm//@angular/platform-browser",
"@npm//@angular/platform-browser-dynamic",
"@npm//@types/jasmine",
],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<mat-grid-list cols="2" rowHeight="100px">
<mat-grid-tile>Tile 1 (no header, no footer)</mat-grid-tile>
<mat-grid-tile>
<mat-grid-tile-header>Tile 2</mat-grid-tile-header>
</mat-grid-tile>
<mat-grid-tile colspan="2">
<mat-grid-tile-header>Tile 3</mat-grid-tile-header>
<mat-grid-tile-footer>Tile 3 footer</mat-grid-tile-footer>
</mat-grid-tile>
<mat-grid-tile>
<mat-grid-tile-header>Tile 4</mat-grid-tile-header>
</mat-grid-tile>
</mat-grid-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatGridListHarness, MatGridTileHarness} from '@angular/material/grid-list/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting}
from '@angular/platform-browser-dynamic/testing';
import {MatGridListModule} from '@angular/material/grid-list';
import {GridListHarnessExample} from './grid-list-harness-example';

describe('GridListHarnessExample', () => {
let fixture: ComponentFixture<GridListHarnessExample>;
let loader: HarnessLoader;

beforeAll(() => {
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
});

beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [MatGridListModule],
declarations: [GridListHarnessExample]
}).compileComponents();
fixture = TestBed.createComponent(GridListHarnessExample);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
})
);

it('should be able to load grid-list harnesses', async () => {
const harnesses = await loader.getAllHarnesses(MatGridListHarness);
expect(harnesses.length).toBe(1);
});

it('should be able to load grid-tile harnesses', async () => {
const harnesses = await loader.getAllHarnesses(MatGridTileHarness);
expect(harnesses.length).toBe(4);
});

it('should be able to get tiles of grid-list with filters', async () => {
const gridList = await loader.getHarness(MatGridListHarness);
const tiles = await gridList.getTiles({headerText: /Tile [34]/});
expect(tiles.length).toBe(2);
});

it('should be able to check whether tile has header', async () => {
const tiles = await loader.getAllHarnesses(MatGridTileHarness);
expect(await tiles[0].hasHeader()).toBe(false);
expect(await (await tiles[0].host()).text()).toBe('Tile 1 (no header, no footer)');
});

it('should be able to check whether tile has footer', async () => {
const tiles = await loader.getAllHarnesses(MatGridTileHarness);
expect(await tiles[2].hasFooter()).toBe(true);
expect(await tiles[2].getFooterText()).toBe('Tile 3 footer');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Component} from '@angular/core';

/**
* @title Testing with MatGridListHarness
*/
@Component({
selector: 'grid-list-harness-example',
templateUrl: 'grid-list-harness-example.html',
})
export class GridListHarnessExample {}
3 changes: 3 additions & 0 deletions src/components-examples/material/grid-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import {NgModule} from '@angular/core';
import {MatGridListModule} from '@angular/material/grid-list';
import {GridListDynamicExample} from './grid-list-dynamic/grid-list-dynamic-example';
import {GridListOverviewExample} from './grid-list-overview/grid-list-overview-example';
import {GridListHarnessExample} from './grid-list-harness/grid-list-harness-example';

export {
GridListDynamicExample,
GridListHarnessExample,
GridListOverviewExample,
};

const EXAMPLES = [
GridListDynamicExample,
GridListHarnessExample,
GridListOverviewExample,
];

Expand Down