Skip to content

docs(material/tabs): add harness example for tabs #21404

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/tabs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ ng_module(
]),
module_name = "@angular/components-examples/material/tabs",
deps = [
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/button",
"//src/material/button-toggle",
"//src/material/checkbox",
"//src/material/icon",
"//src/material/input",
"//src/material/tabs",
"//src/material/tabs/testing",
"@npm//@angular/forms",
"@npm//@angular/platform-browser",
"@npm//@angular/platform-browser-dynamic",
"@npm//@types/jasmine",
],
)

Expand Down
3 changes: 3 additions & 0 deletions src/components-examples/material/tabs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {TabGroupCustomLabelExample} from './tab-group-custom-label/tab-group-cus
import {
TabGroupDynamicHeightExample
} from './tab-group-dynamic-height/tab-group-dynamic-height-example';
import {TabGroupHarnessExample} from './tab-group-harness/tab-group-harness-example';
import {TabGroupDynamicExample} from './tab-group-dynamic/tab-group-dynamic-example';
import {TabGroupHeaderBelowExample} from './tab-group-header-below/tab-group-header-below-example';
import {TabGroupLazyLoadedExample} from './tab-group-lazy-loaded/tab-group-lazy-loaded-example';
Expand All @@ -30,6 +31,7 @@ export {
TabGroupCustomLabelExample,
TabGroupDynamicExample,
TabGroupDynamicHeightExample,
TabGroupHarnessExample,
TabGroupHeaderBelowExample,
TabGroupLazyLoadedExample,
TabGroupStretchedExample,
Expand All @@ -45,6 +47,7 @@ const EXAMPLES = [
TabGroupCustomLabelExample,
TabGroupDynamicExample,
TabGroupDynamicHeightExample,
TabGroupHarnessExample,
TabGroupHeaderBelowExample,
TabGroupLazyLoadedExample,
TabGroupStretchedExample,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<mat-tab-group>
<mat-tab label="Profile" aria-label="Profile tab">
<span class="test-tab-content">Your personal information</span>
</mat-tab>
<mat-tab label="Settings" aria-label="Settings tab">
<span class="test-tab-content">Privacy settings</span>
</mat-tab>
<mat-tab label="FAQ" aria-label="FAQ tab">
<span class="test-tab-content">How to update profile picture</span>
</mat-tab>
</mat-tab-group>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {TestBed, ComponentFixture, waitForAsync} from '@angular/core/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {MatTabGroupHarness} from '@angular/material/tabs/testing';
import {HarnessLoader} from '@angular/cdk/testing';
import {BrowserDynamicTestingModule, platformBrowserDynamicTesting}
from '@angular/platform-browser-dynamic/testing';
import {MatTabsModule} from '@angular/material/tabs';
import {TabGroupHarnessExample} from './tab-group-harness-example';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';

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

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

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

it('should load harness for tab-group', async () => {
const tabGroups = await loader.getAllHarnesses(MatTabGroupHarness);
expect(tabGroups.length).toBe(1);
});

it('should load harness for tab-group with selected tab label', async () => {
const tabGroups = await loader.getAllHarnesses(MatTabGroupHarness.with({
selectedTabLabel: 'Profile',
}));
expect(tabGroups.length).toBe(1);
});

it('should be able to get tabs of tab-group', async () => {
const tabGroup = await loader.getHarness(MatTabGroupHarness);
const tabs = await tabGroup.getTabs();
expect(tabs.length).toBe(3);
});

it('should be able to select tab from tab-group', async () => {
const tabGroup = await loader.getHarness(MatTabGroupHarness);
expect(await (await tabGroup.getSelectedTab()).getLabel()).toBe('Profile');
await tabGroup.selectTab({label: 'FAQ'});
expect(await (await tabGroup.getSelectedTab()).getLabel()).toBe('FAQ');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Component} from '@angular/core';

/**
* @title Testing with MatTabGroupHarness
*/
@Component({
selector: 'tab-group-harness-example',
templateUrl: 'tab-group-harness-example.html'
})
export class TabGroupHarnessExample {}