Skip to content

chore: fix menu harness tests #17018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2019
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HarnessLoader} from '@angular/cdk-experimental/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk-experimental/testing/testbed';
import {Component} from '@angular/core';
import {Component, Type} from '@angular/core';
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
import {MatAutocompleteModule} from '@angular/material/autocomplete';
import {OverlayContainer} from '@angular/cdk/overlay';
Expand All @@ -16,33 +16,16 @@ let overlayContainer: OverlayContainer;
describe('MatAutocompleteHarness', () => {
describe('non-MDC-based', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatAutocompleteModule],
declarations: [AutocompleteHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(AutocompleteHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
await prepareTests(MatAutocompleteModule, AutocompleteHarnessTest);
harness = MatAutocompleteHarness;
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
});

runTests();
});

describe('MDC-based', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatMdcAutocompleteModule],
declarations: [AutocompleteHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(AutocompleteHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
await prepareTests(MatMdcAutocompleteModule, AutocompleteHarnessTest);
// Public APIs are the same as MatAutocompleteHarness, but cast
// is necessary because of different private fields.
harness = MatMdcAutocompleteHarness as any;
Expand All @@ -53,11 +36,27 @@ describe('MatAutocompleteHarness', () => {
});
});

/** Shared test setup logic. */
async function prepareTests(moduleType: Type<any>, fixtureType: Type<any>) {
await TestBed.configureTestingModule({
imports: [moduleType],
declarations: [fixtureType],
}).compileComponents();

fixture = TestBed.createComponent(fixtureType);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
}

/** Shared tests to run on both the original and MDC-based autocomplete. */
function runTests() {
afterEach(() => {
// Angular won't call this for us so we need to do it ourselves to avoid leaks.
overlayContainer.ngOnDestroy();
overlayContainer = null!;
});

it('should load all autocomplete harnesses', async () => {
Expand Down
39 changes: 19 additions & 20 deletions src/material-experimental/mdc-menu/harness/menu-harness.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HarnessLoader} from '@angular/cdk-experimental/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk-experimental/testing/testbed';
import {Component} from '@angular/core';
import {Component, Type} from '@angular/core';
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
import {MatMenuModule} from '@angular/material/menu';
import {OverlayContainer} from '@angular/cdk/overlay';
Expand All @@ -16,33 +16,16 @@ let overlayContainer: OverlayContainer;
describe('MatMenuHarness', () => {
describe('non-MDC-based', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatMenuModule],
declarations: [MenuHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(MenuHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
await prepareTests(MatMenuModule, MenuHarnessTest);
menuHarness = MatMenuHarness;
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
});

runTests();
});

describe('MDC-based', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MatMdcMenuModule],
declarations: [MenuHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(MenuHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
await prepareTests(MatMdcMenuModule, MenuHarnessTest);
// Public APIs are the same as MatMenuHarness, but cast is necessary because of different
// private fields.
menuHarness = MatMdcMenuHarness as any;
Expand All @@ -52,11 +35,27 @@ describe('MatMenuHarness', () => {
});
});

/** Shared test setup logic. */
async function prepareTests(moduleType: Type<any>, fixtureType: Type<any>) {
await TestBed.configureTestingModule({
imports: [moduleType],
declarations: [fixtureType],
}).compileComponents();

fixture = TestBed.createComponent(fixtureType);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
}

/** Shared tests to run on both the original and MDC-based menues. */
function runTests() {
afterEach(() => {
// Angular won't call this for us so we need to do it ourselves to avoid leaks.
overlayContainer.ngOnDestroy();
overlayContainer = null!;
});

it('should load all menu harnesses', async () => {
Expand Down
56 changes: 26 additions & 30 deletions src/material-experimental/mdc-select/harness/select-harness.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {HarnessLoader} from '@angular/cdk-experimental/testing';
import {TestbedHarnessEnvironment} from '@angular/cdk-experimental/testing/testbed';
import {Component} from '@angular/core';
import {Component, Type} from '@angular/core';
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {ReactiveFormsModule, FormControl, Validators} from '@angular/forms';
Expand All @@ -19,43 +19,16 @@ let overlayContainer: OverlayContainer;
describe('MatSelectHarness', () => {
describe('non-MDC-based', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
MatSelectModule,
MatFormFieldModule,
NoopAnimationsModule,
ReactiveFormsModule,
],
declarations: [SelectHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(SelectHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
await prepareTests(MatSelectModule, SelectHarnessTest);
harness = MatSelectHarness;
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
});

runTests();
});

describe('MDC-based', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
MatMdcSelectModule,
MatFormFieldModule,
NoopAnimationsModule,
ReactiveFormsModule,
],
declarations: [SelectHarnessTest],
}).compileComponents();

fixture = TestBed.createComponent(SelectHarnessTest);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
await prepareTests(MatMdcSelectModule, SelectHarnessTest);
// Public APIs are the same as MatSelectHarness, but cast
// is necessary because of different private fields.
harness = MatMdcSelectHarness as any;
Expand All @@ -66,11 +39,34 @@ describe('MatSelectHarness', () => {
});
});

/** Shared test setup logic. */
async function prepareTests(moduleType: Type<any>, fixtureType: Type<any>) {
await TestBed.configureTestingModule({
imports: [
moduleType,
MatFormFieldModule,
NoopAnimationsModule,
ReactiveFormsModule,
],
declarations: [fixtureType],
}).compileComponents();

fixture = TestBed.createComponent(fixtureType);
fixture.detectChanges();
loader = TestbedHarnessEnvironment.loader(fixture);
inject([OverlayContainer], (oc: OverlayContainer) => {
overlayContainer = oc;
})();
}



/** Shared tests to run on both the original and MDC-based select. */
function runTests() {
afterEach(() => {
// Angular won't call this for us so we need to do it ourselves to avoid leaks.
overlayContainer.ngOnDestroy();
overlayContainer = null!;
});

it('should load all select harnesses', async () => {
Expand Down