Skip to content
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
32 changes: 0 additions & 32 deletions src/material-experimental/mdc-tabs/harness/BUILD.bazel

This file was deleted.

47 changes: 47 additions & 0 deletions src/material/tabs/testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")

ng_module(
name = "testing",
srcs = glob(
["**/*.ts"],
exclude = ["**/*.spec.ts"],
),
module_name = "@angular/material/tabs/testing",
deps = [
"//src/cdk/coercion",
"//src/cdk/testing",
],
)

ng_test_library(
name = "harness_tests_lib",
srcs = ["shared.spec.ts"],
deps = [
":testing",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/tabs",
"@npm//@angular/forms",
"@npm//@angular/platform-browser",
],
)

ng_test_library(
name = "unit_tests_lib",
srcs = glob(
["**/*.spec.ts"],
exclude = ["shared.spec.ts"],
),
deps = [
":harness_tests_lib",
":testing",
"//src/material/tabs",
],
)

ng_web_test_suite(
name = "unit_tests",
deps = [":unit_tests_lib"],
)
9 changes: 9 additions & 0 deletions src/material/tabs/testing/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

export * from './public-api';
11 changes: 11 additions & 0 deletions src/material/tabs/testing/public-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

export * from './tab-group-harness';
export * from './tab-harness';
export * from './tab-harness-filters';
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,26 @@ import {MatTabsModule} from '@angular/material/tabs';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {MatTabGroupHarness} from './tab-group-harness';

let fixture: ComponentFixture<TabGroupHarnessTest>;
let loader: HarnessLoader;
let tabGroupHarness: typeof MatTabGroupHarness;

describe('MatTabGroupHarness', () => {
describe('non-MDC-based', () => {
beforeEach(async () => {
await TestBed
.configureTestingModule({
imports: [MatTabsModule, NoopAnimationsModule],
declarations: [TabGroupHarnessTest],
})
.compileComponents();

fixture = TestBed.createComponent(TabGroupHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
tabGroupHarness = MatTabGroupHarness;
});

runTests();
/** Shared tests to run on both the original and MDC-based tab-group's. */
export function runHarnessTests(
tabsModule: typeof MatTabsModule,
tabGroupHarness: typeof MatTabGroupHarness) {
let fixture: ComponentFixture<TabGroupHarnessTest>;
let loader: HarnessLoader;

beforeEach(async () => {
await TestBed
.configureTestingModule({
imports: [tabsModule, NoopAnimationsModule],
declarations: [TabGroupHarnessTest],
})
.compileComponents();

fixture = TestBed.createComponent(TabGroupHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
});

describe(
'MDC-based',
() => {
// TODO: run tests for MDC based tab-group once implemented.
});
});

/** Shared tests to run on both the original and MDC-based tab-group's. */
function runTests() {
it('should load harness for tab-group', async () => {
const tabGroups = await loader.getAllHarnesses(tabGroupHarness);
expect(tabGroups.length).toBe(1);
Expand Down
7 changes: 7 additions & 0 deletions src/material/tabs/testing/tab-group-harness.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {MatTabsModule} from '@angular/material/tabs';
import {runHarnessTests} from '@angular/material/tabs/testing/shared.spec';
import {MatTabGroupHarness} from './tab-group-harness';

describe('Non-MDC-based MatTabGroupHarness', () => {
runHarnessTests(MatTabsModule, MatTabGroupHarness);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import {ComponentHarness, HarnessPredicate} from '@angular/cdk/testing';
import {TabGroupHarnessFilters} from './tab-group-harness-filters';
import {TabGroupHarnessFilters} from './tab-harness-filters';
import {MatTabHarness} from './tab-harness';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
import {BaseHarnessFilters} from '@angular/cdk/testing';

export interface TabHarnessFilters extends BaseHarnessFilters {}

export interface TabGroupHarnessFilters extends BaseHarnessFilters {
selectedTabLabel?: string | RegExp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ComponentHarness, TestElement} from '@angular/cdk/testing';
import {ComponentHarness, HarnessPredicate, TestElement} from '@angular/cdk/testing';
import {TabHarnessFilters} from './tab-harness-filters';

/**
* Harness for interacting with a standard Angular Material tab-label in tests.
Expand All @@ -15,6 +16,13 @@ import {ComponentHarness, TestElement} from '@angular/cdk/testing';
export class MatTabHarness extends ComponentHarness {
static hostSelector = '.mat-tab-label';

/**
* Gets a `HarnessPredicate` that can be used to search for a tab with specific attributes.
*/
static with(options: TabHarnessFilters = {}): HarnessPredicate<MatTabHarness> {
return new HarnessPredicate(MatTabHarness, options);
}

private _rootLocatorFactory = this.documentRootLocatorFactory();

/** Gets the label of the tab. */
Expand Down
2 changes: 2 additions & 0 deletions test/karma-system-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ System.config({
'@angular/material/stepper': 'dist/packages/material/stepper/index.js',
'@angular/material/table': 'dist/packages/material/table/index.js',
'@angular/material/tabs': 'dist/packages/material/tabs/index.js',
'@angular/material/tabs/testing': 'dist/packages/material/tabs/testing/index.js',
'@angular/material/tabs/testing/shared.spec': 'dist/packages/material/tabs/testing/shared.spec.js',
'@angular/material/testing': 'dist/packages/material/testing/index.js',
'@angular/material/toolbar': 'dist/packages/material/toolbar/index.js',
'@angular/material/tooltip': 'dist/packages/material/tooltip/index.js',
Expand Down