Skip to content

Commit 7da89fd

Browse files
committed
test(material/toolbar): combine shared tests
Since we only have one module, we don't need separate shared tests anymore.
1 parent 74ef04b commit 7da89fd

File tree

3 files changed

+82
-108
lines changed

3 files changed

+82
-108
lines changed

src/material/toolbar/testing/BUILD.bazel

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ filegroup(
1919
)
2020

2121
ng_test_library(
22-
name = "harness_tests_lib",
23-
srcs = ["shared.spec.ts"],
22+
name = "unit_tests_lib",
23+
srcs = glob(["**/*.spec.ts"]),
2424
deps = [
2525
":testing",
2626
"//src/cdk/testing",
@@ -30,21 +30,6 @@ ng_test_library(
3030
],
3131
)
3232

33-
ng_test_library(
34-
name = "unit_tests_lib",
35-
srcs = glob(
36-
["**/*.spec.ts"],
37-
exclude = [
38-
"shared.spec.ts",
39-
],
40-
),
41-
deps = [
42-
":harness_tests_lib",
43-
":testing",
44-
"//src/material/toolbar",
45-
],
46-
)
47-
4833
ng_web_test_suite(
4934
name = "unit_tests",
5035
deps = [":unit_tests_lib"],

src/material/toolbar/testing/shared.spec.ts

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,83 @@
1-
import {runHarnessTests} from '@angular/material/toolbar/testing/shared.spec';
1+
import {Component} from '@angular/core';
2+
import {ComponentHarness, HarnessLoader} from '@angular/cdk/testing';
23
import {MatToolbarModule} from '@angular/material/toolbar';
3-
import {MatToolbarHarness} from '@angular/material/toolbar/testing';
4+
import {MatToolbarHarness, MatToolbarSection} from '@angular/material/toolbar/testing';
5+
import {ComponentFixture, TestBed} from '@angular/core/testing';
6+
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
47

5-
describe('Non-MDC-based MatToolbarHarness', () => {
6-
runHarnessTests(MatToolbarModule, MatToolbarHarness);
8+
describe('MatToolbarHarness', () => {
9+
let fixture: ComponentFixture<ToolbarHarnessTest>;
10+
let loader: HarnessLoader;
11+
12+
beforeEach(async () => {
13+
await TestBed.configureTestingModule({
14+
imports: [MatToolbarModule],
15+
declarations: [ToolbarHarnessTest],
16+
}).compileComponents();
17+
18+
fixture = TestBed.createComponent(ToolbarHarnessTest);
19+
fixture.detectChanges();
20+
loader = TestbedHarnessEnvironment.loader(fixture);
21+
});
22+
23+
it('should find all toolbars', async () => {
24+
const toolbars = await loader.getAllHarnesses(MatToolbarHarness);
25+
26+
expect(toolbars.length).toBe(2);
27+
});
28+
29+
it('should find toolbar with text', async () => {
30+
const toolbars = await loader.getAllHarnesses(MatToolbarHarness.with({text: 'My App'}));
31+
32+
expect(toolbars.length).toBe(1);
33+
expect(await toolbars[0].hasMultipleRows()).toBeFalse();
34+
});
35+
36+
it('should find toolbar with regex', async () => {
37+
const toolbars = await loader.getAllHarnesses(MatToolbarHarness.with({text: /Row/}));
38+
39+
expect(toolbars.length).toBe(1);
40+
expect(await toolbars[0].hasMultipleRows()).toBeTrue();
41+
});
42+
43+
it('should get toolbar text', async () => {
44+
const toolbars = await loader.getAllHarnesses(MatToolbarHarness);
45+
46+
expect(await toolbars[0].getRowsAsText()).toEqual(['My App']);
47+
expect(await toolbars[1].getRowsAsText()).toEqual(['Row 1', 'Row 2 Button 1 Button 2']);
48+
});
49+
50+
it('should get harness loaders for toolbar row', async () => {
51+
const toolbar = await loader.getHarness(MatToolbarHarness.with({text: /Button/}));
52+
const rowLoaders = await toolbar.getAllChildLoaders(MatToolbarSection.ROW);
53+
const row1 = rowLoaders[0] as HarnessLoader;
54+
const row1Subcomponents = await row1.getAllHarnesses(DummyHarness);
55+
const row2 = rowLoaders[1] as HarnessLoader;
56+
const row2Subcomponents = await row2.getAllHarnesses(DummyHarness);
57+
58+
expect(row1Subcomponents.length).toBe(1);
59+
expect(row2Subcomponents.length).toBe(3);
60+
});
761
});
62+
63+
@Component({
64+
template: `
65+
<mat-toolbar><span>My App</span></mat-toolbar>
66+
<mat-toolbar>
67+
<mat-toolbar-row><span>Row 1</span></mat-toolbar-row>
68+
<mat-toolbar-row><span>Row 2</span>
69+
<button mat-button>
70+
Button 1
71+
</button>
72+
<button mat-button>
73+
Button 2
74+
</button>
75+
</mat-toolbar-row>
76+
</mat-toolbar>
77+
`,
78+
})
79+
class ToolbarHarnessTest {}
80+
81+
class DummyHarness extends ComponentHarness {
82+
static hostSelector = 'span, button';
83+
}

0 commit comments

Comments
 (0)