Skip to content

Commit a2ccacd

Browse files
mmalerbajelbourn
authored andcommitted
feat(tabs): move harnesses out of experimental (#17137)
1 parent 8229353 commit a2ccacd

File tree

10 files changed

+106
-64
lines changed

10 files changed

+106
-64
lines changed

src/material-experimental/mdc-tabs/harness/BUILD.bazel

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ng_module", "ng_test_library", "ng_web_test_suite")
4+
5+
ng_module(
6+
name = "testing",
7+
srcs = glob(
8+
["**/*.ts"],
9+
exclude = ["**/*.spec.ts"],
10+
),
11+
module_name = "@angular/material/tabs/testing",
12+
deps = [
13+
"//src/cdk/coercion",
14+
"//src/cdk/testing",
15+
],
16+
)
17+
18+
ng_test_library(
19+
name = "harness_tests_lib",
20+
srcs = ["shared.spec.ts"],
21+
deps = [
22+
":testing",
23+
"//src/cdk/testing",
24+
"//src/cdk/testing/testbed",
25+
"//src/material/tabs",
26+
"@npm//@angular/forms",
27+
"@npm//@angular/platform-browser",
28+
],
29+
)
30+
31+
ng_test_library(
32+
name = "unit_tests_lib",
33+
srcs = glob(
34+
["**/*.spec.ts"],
35+
exclude = ["shared.spec.ts"],
36+
),
37+
deps = [
38+
":harness_tests_lib",
39+
":testing",
40+
"//src/material/tabs",
41+
],
42+
)
43+
44+
ng_web_test_suite(
45+
name = "unit_tests",
46+
deps = [":unit_tests_lib"],
47+
)

src/material/tabs/testing/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './public-api';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './tab-group-harness';
10+
export * from './tab-harness';
11+
export * from './tab-harness-filters';
Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,26 @@ import {MatTabsModule} from '@angular/material/tabs';
66
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
77
import {MatTabGroupHarness} from './tab-group-harness';
88

9-
let fixture: ComponentFixture<TabGroupHarnessTest>;
10-
let loader: HarnessLoader;
11-
let tabGroupHarness: typeof MatTabGroupHarness;
12-
13-
describe('MatTabGroupHarness', () => {
14-
describe('non-MDC-based', () => {
15-
beforeEach(async () => {
16-
await TestBed
17-
.configureTestingModule({
18-
imports: [MatTabsModule, NoopAnimationsModule],
19-
declarations: [TabGroupHarnessTest],
20-
})
21-
.compileComponents();
22-
23-
fixture = TestBed.createComponent(TabGroupHarnessTest);
24-
fixture.detectChanges();
25-
loader = TestbedHarnessEnvironment.loader(fixture);
26-
tabGroupHarness = MatTabGroupHarness;
27-
});
28-
29-
runTests();
9+
/** Shared tests to run on both the original and MDC-based tab-group's. */
10+
export function runHarnessTests(
11+
tabsModule: typeof MatTabsModule,
12+
tabGroupHarness: typeof MatTabGroupHarness) {
13+
let fixture: ComponentFixture<TabGroupHarnessTest>;
14+
let loader: HarnessLoader;
15+
16+
beforeEach(async () => {
17+
await TestBed
18+
.configureTestingModule({
19+
imports: [tabsModule, NoopAnimationsModule],
20+
declarations: [TabGroupHarnessTest],
21+
})
22+
.compileComponents();
23+
24+
fixture = TestBed.createComponent(TabGroupHarnessTest);
25+
fixture.detectChanges();
26+
loader = TestbedHarnessEnvironment.loader(fixture);
3027
});
3128

32-
describe(
33-
'MDC-based',
34-
() => {
35-
// TODO: run tests for MDC based tab-group once implemented.
36-
});
37-
});
38-
39-
/** Shared tests to run on both the original and MDC-based tab-group's. */
40-
function runTests() {
4129
it('should load harness for tab-group', async () => {
4230
const tabGroups = await loader.getAllHarnesses(tabGroupHarness);
4331
expect(tabGroups.length).toBe(1);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {MatTabsModule} from '@angular/material/tabs';
2+
import {runHarnessTests} from '@angular/material/tabs/testing/shared.spec';
3+
import {MatTabGroupHarness} from './tab-group-harness';
4+
5+
describe('Non-MDC-based MatTabGroupHarness', () => {
6+
runHarnessTests(MatTabsModule, MatTabGroupHarness);
7+
});

src/material-experimental/mdc-tabs/harness/tab-group-harness.ts renamed to src/material/tabs/testing/tab-group-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

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

1313
/**
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*/
88
import {BaseHarnessFilters} from '@angular/cdk/testing';
99

10+
export interface TabHarnessFilters extends BaseHarnessFilters {}
11+
1012
export interface TabGroupHarnessFilters extends BaseHarnessFilters {
1113
selectedTabLabel?: string | RegExp;
1214
}

src/material-experimental/mdc-tabs/harness/tab-harness.ts renamed to src/material/tabs/testing/tab-harness.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

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

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

19+
/**
20+
* Gets a `HarnessPredicate` that can be used to search for a tab with specific attributes.
21+
*/
22+
static with(options: TabHarnessFilters = {}): HarnessPredicate<MatTabHarness> {
23+
return new HarnessPredicate(MatTabHarness, options);
24+
}
25+
1826
private _rootLocatorFactory = this.documentRootLocatorFactory();
1927

2028
/** Gets the label of the tab. */

test/karma-system-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ System.config({
147147
'@angular/material/stepper': 'dist/packages/material/stepper/index.js',
148148
'@angular/material/table': 'dist/packages/material/table/index.js',
149149
'@angular/material/tabs': 'dist/packages/material/tabs/index.js',
150+
'@angular/material/tabs/testing': 'dist/packages/material/tabs/testing/index.js',
151+
'@angular/material/tabs/testing/shared.spec': 'dist/packages/material/tabs/testing/shared.spec.js',
150152
'@angular/material/testing': 'dist/packages/material/testing/index.js',
151153
'@angular/material/toolbar': 'dist/packages/material/toolbar/index.js',
152154
'@angular/material/tooltip': 'dist/packages/material/tooltip/index.js',

0 commit comments

Comments
 (0)