Skip to content

Commit

Permalink
fix(material/dialog): remove dialog deps on legacy-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Sep 8, 2022
1 parent 1ade334 commit 5e34770
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/material/dialog/dialog.md
Expand Up @@ -65,7 +65,7 @@ To access the data in your dialog component, you have to use the MAT_DIALOG_DATA

```ts
import {Component, Inject} from '@angular/core';
import {MAT_DIALOG_DATA} from '@angular/material/legacy-dialog';
import {MAT_DIALOG_DATA} from '@angular/material/dialog';

@Component({
selector: 'your-dialog',
Expand Down
15 changes: 14 additions & 1 deletion src/material/dialog/testing/BUILD.bazel
Expand Up @@ -30,9 +30,9 @@ ng_test_library(
exclude = ["shared.spec.ts"],
),
deps = [
":harness_tests_lib",
":testing",
"//src/material/dialog",
"//src/material/legacy-dialog/testing:harness_tests_lib",
"@npm//@angular/platform-browser",
],
)
Expand All @@ -43,3 +43,16 @@ ng_web_test_suite(
":unit_tests_lib",
],
)

ng_test_library(
name = "harness_tests_lib",
srcs = ["shared.spec.ts"],
deps = [
":testing",
"//src/cdk/overlay",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/dialog",
"@npm//@angular/platform-browser",
],
)
4 changes: 2 additions & 2 deletions src/material/dialog/testing/dialog-harness.spec.ts
@@ -1,7 +1,7 @@
import {MatDialog, MatDialogModule} from '@angular/material/dialog';
import {runHarnessTests} from '@angular/material/legacy-dialog/testing/shared.spec';
import {runHarnessTests} from './shared.spec';
import {MatDialogHarness} from './dialog-harness';

describe('MDC-based MatDialog', () => {
runHarnessTests(MatDialogModule, MatDialogHarness as any, MatDialog as any);
runHarnessTests(MatDialogModule, MatDialogHarness, MatDialog);
});
Expand Up @@ -2,19 +2,15 @@ import {HarnessLoader} from '@angular/cdk/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk/testing/testbed';
import {Component, TemplateRef, ViewChild} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {
MatLegacyDialog,
MatLegacyDialogModule,
MatLegacyDialogConfig,
} from '@angular/material/legacy-dialog';
import {MatDialog, MatDialogModule, MatDialogConfig} from '@angular/material/dialog';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {MatLegacyDialogHarness} from './dialog-harness';
import {MatDialogHarness} from './dialog-harness';

/** Shared tests to run on both the original and MDC-based dialog's. */
export function runHarnessTests(
dialogModule: typeof MatLegacyDialogModule,
dialogHarness: typeof MatLegacyDialogHarness,
dialogService: typeof MatLegacyDialog,
dialogModule: typeof MatDialogModule,
dialogHarness: typeof MatDialogHarness,
dialogService: typeof MatDialog,
) {
let fixture: ComponentFixture<DialogHarnessTest>;
let loader: HarnessLoader;
Expand All @@ -25,9 +21,7 @@ export function runHarnessTests(
// the existing instance of the specified dialog service. This allows us to run these
// tests for the MDC-based version of the dialog too.
const providers =
dialogService !== MatLegacyDialog
? [{provide: MatLegacyDialog, useExisting: dialogService}]
: undefined;
dialogService !== MatDialog ? [{provide: MatDialog, useExisting: dialogService}] : undefined;
await TestBed.configureTestingModule({
imports: [dialogModule, NoopAnimationsModule],
declarations: [DialogHarnessTest],
Expand Down Expand Up @@ -138,9 +132,9 @@ export function runHarnessTests(
class DialogHarnessTest {
@ViewChild(TemplateRef) dialogTmpl: TemplateRef<any>;

constructor(readonly dialog: MatLegacyDialog) {}
constructor(readonly dialog: MatDialog) {}

open(config?: MatLegacyDialogConfig) {
open(config?: MatDialogConfig) {
return this.dialog.open(this.dialogTmpl, config);
}
}
Expand Down
15 changes: 1 addition & 14 deletions src/material/legacy-dialog/testing/BUILD.bazel
Expand Up @@ -25,28 +25,15 @@ filegroup(
srcs = glob(["**/*.ts"]),
)

ng_test_library(
name = "harness_tests_lib",
srcs = ["shared.spec.ts"],
deps = [
":testing",
"//src/cdk/overlay",
"//src/cdk/testing",
"//src/cdk/testing/testbed",
"//src/material/legacy-dialog",
"@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/dialog/testing:harness_tests_lib",
"//src/material/legacy-dialog",
"@npm//@angular/platform-browser",
],
Expand Down
4 changes: 2 additions & 2 deletions src/material/legacy-dialog/testing/dialog-harness.spec.ts
@@ -1,7 +1,7 @@
import {MatLegacyDialog, MatLegacyDialogModule} from '@angular/material/legacy-dialog';
import {runHarnessTests} from '@angular/material/legacy-dialog/testing/shared.spec';
import {runHarnessTests} from '@angular/material/dialog/testing/shared.spec';
import {MatLegacyDialogHarness} from './dialog-harness';

describe('Non-MDC-based MatDialogHarness', () => {
runHarnessTests(MatLegacyDialogModule, MatLegacyDialogHarness, MatLegacyDialog);
runHarnessTests(MatLegacyDialogModule, MatLegacyDialogHarness as any, MatLegacyDialog as any);
});

0 comments on commit 5e34770

Please sign in to comment.