Skip to content

Commit 24c7435

Browse files
committed
test(material/bottom-sheet): combine shared tests
Since we only have one module, we don't need separate shared tests anymore.
1 parent 518ac69 commit 24c7435

File tree

3 files changed

+66
-90
lines changed

3 files changed

+66
-90
lines changed

src/material/bottom-sheet/testing/BUILD.bazel

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ filegroup(
2020
)
2121

2222
ng_test_library(
23-
name = "harness_tests_lib",
24-
srcs = ["shared.spec.ts"],
23+
name = "unit_tests_lib",
24+
srcs = glob(["**/*.spec.ts"]),
2525
deps = [
2626
":testing",
2727
"//src/cdk/overlay",
@@ -32,19 +32,6 @@ ng_test_library(
3232
],
3333
)
3434

35-
ng_test_library(
36-
name = "unit_tests_lib",
37-
srcs = glob(
38-
["**/*.spec.ts"],
39-
exclude = ["shared.spec.ts"],
40-
),
41-
deps = [
42-
":harness_tests_lib",
43-
":testing",
44-
"//src/material/bottom-sheet",
45-
],
46-
)
47-
4835
ng_web_test_suite(
4936
name = "unit_tests",
5037
deps = [":unit_tests_lib"],
Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,67 @@
1-
import {MatBottomSheetModule} from '@angular/material/bottom-sheet';
2-
import {runHarnessTests} from '@angular/material/bottom-sheet/testing/shared.spec';
1+
import {Component, TemplateRef, ViewChild} from '@angular/core';
2+
import {ComponentFixture, TestBed} from '@angular/core/testing';
3+
import {HarnessLoader} from '@angular/cdk/testing';
4+
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
5+
import {
6+
MatBottomSheet,
7+
MatBottomSheetConfig,
8+
MatBottomSheetModule,
9+
} from '@angular/material/bottom-sheet';
10+
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
311
import {MatBottomSheetHarness} from './bottom-sheet-harness';
412

5-
describe('Non-MDC-based MatBottomSheetHarness', () => {
6-
runHarnessTests(MatBottomSheetModule, MatBottomSheetHarness);
13+
describe('MatBottomSheetHarness', () => {
14+
let fixture: ComponentFixture<BottomSheetHarnessTest>;
15+
let loader: HarnessLoader;
16+
17+
beforeEach(async () => {
18+
await TestBed.configureTestingModule({
19+
imports: [MatBottomSheetModule, NoopAnimationsModule],
20+
declarations: [BottomSheetHarnessTest],
21+
}).compileComponents();
22+
23+
fixture = TestBed.createComponent(BottomSheetHarnessTest);
24+
fixture.detectChanges();
25+
loader = TestbedHarnessEnvironment.documentRootLoader(fixture);
26+
});
27+
28+
it('should load harness for a bottom sheet', async () => {
29+
fixture.componentInstance.open();
30+
const bottomSheets = await loader.getAllHarnesses(MatBottomSheetHarness);
31+
expect(bottomSheets.length).toBe(1);
32+
});
33+
34+
it('should be able to get aria-label of the bottom sheet', async () => {
35+
fixture.componentInstance.open({ariaLabel: 'Confirm purchase.'});
36+
const bottomSheet = await loader.getHarness(MatBottomSheetHarness);
37+
expect(await bottomSheet.getAriaLabel()).toBe('Confirm purchase.');
38+
});
39+
40+
it('should be able to dismiss the bottom sheet', async () => {
41+
fixture.componentInstance.open();
42+
let bottomSheets = await loader.getAllHarnesses(MatBottomSheetHarness);
43+
44+
expect(bottomSheets.length).toBe(1);
45+
await bottomSheets[0].dismiss();
46+
47+
bottomSheets = await loader.getAllHarnesses(MatBottomSheetHarness);
48+
expect(bottomSheets.length).toBe(0);
49+
});
750
});
51+
52+
@Component({
53+
template: `
54+
<ng-template>
55+
Hello from the bottom sheet!
56+
</ng-template>
57+
`,
58+
})
59+
class BottomSheetHarnessTest {
60+
@ViewChild(TemplateRef) template: TemplateRef<any>;
61+
62+
constructor(readonly bottomSheet: MatBottomSheet) {}
63+
64+
open(config?: MatBottomSheetConfig) {
65+
return this.bottomSheet.open(this.template, config);
66+
}
67+
}

src/material/bottom-sheet/testing/shared.spec.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)