Skip to content

refactor(multiple): clean up entryComponents usages #24019

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
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
43 changes: 11 additions & 32 deletions src/cdk-experimental/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Directive,
Inject,
Injector,
NgModule,
TemplateRef,
ViewChild,
ViewContainerRef,
Expand Down Expand Up @@ -45,7 +44,16 @@ describe('Dialog', () => {

beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [DialogModule, DialogTestModule],
imports: [DialogModule, NoopAnimationsModule],
declarations: [
ComponentWithChildViewContainer,
ComponentWithTemplateRef,
PizzaMsg,
ContentElementDialog,
DialogWithInjectedData,
DialogWithoutFocusableElements,
DirectiveWithViewContainer,
],
providers: [{provide: Location, useClass: SpyLocation}],
});

Expand Down Expand Up @@ -1138,7 +1146,7 @@ describe('Dialog with a parent Dialog', () => {

beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [DialogModule, DialogTestModule],
imports: [DialogModule, NoopAnimationsModule],
declarations: [ComponentThatProvidesMatDialog],
providers: [
{
Expand Down Expand Up @@ -1315,32 +1323,3 @@ class DialogWithoutFocusableElements {}
encapsulation: ViewEncapsulation.ShadowDom,
})
class ShadowDomComponent {}

// Create a real (non-test) NgModule as a workaround for
// https://github.com/angular/angular/issues/10760
const TEST_DIRECTIVES = [
ComponentWithChildViewContainer,
ComponentWithTemplateRef,
PizzaMsg,
DirectiveWithViewContainer,
ComponentWithOnPushViewContainer,
ContentElementDialog,
DialogWithInjectedData,
DialogWithoutFocusableElements,
ShadowDomComponent,
];

@NgModule({
imports: [DialogModule, NoopAnimationsModule],
exports: TEST_DIRECTIVES,
declarations: TEST_DIRECTIVES,
entryComponents: [
ComponentWithChildViewContainer,
ComponentWithTemplateRef,
PizzaMsg,
ContentElementDialog,
DialogWithInjectedData,
DialogWithoutFocusableElements,
],
})
class DialogTestModule {}
14 changes: 3 additions & 11 deletions src/cdk/overlay/dispatchers/overlay-keyboard-dispatcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {TestBed, inject} from '@angular/core/testing';
import {dispatchKeyboardEvent} from '../../testing/private';
import {ESCAPE} from '@angular/cdk/keycodes';
import {Component, NgModule} from '@angular/core';
import {Component} from '@angular/core';
import {OverlayModule, Overlay} from '../index';
import {OverlayKeyboardDispatcher} from './overlay-keyboard-dispatcher';
import {ComponentPortal} from '@angular/cdk/portal';
Expand All @@ -12,7 +12,8 @@ describe('OverlayKeyboardDispatcher', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [OverlayModule, TestComponentModule],
imports: [OverlayModule],
declarations: [TestComponent],
});

inject([OverlayKeyboardDispatcher, Overlay], (kbd: OverlayKeyboardDispatcher, o: Overlay) => {
Expand Down Expand Up @@ -184,12 +185,3 @@ describe('OverlayKeyboardDispatcher', () => {
template: 'Hello',
})
class TestComponent {}

// Create a real (non-test) NgModule as a workaround for
// https://github.com/angular/angular/issues/10760
@NgModule({
exports: [TestComponent],
declarations: [TestComponent],
entryComponents: [TestComponent],
})
class TestComponentModule {}
162 changes: 83 additions & 79 deletions src/cdk/overlay/dispatchers/overlay-outside-click-dispatcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TestBed, inject, fakeAsync} from '@angular/core/testing';
import {Component, NgModule} from '@angular/core';
import {Component} from '@angular/core';
import {dispatchFakeEvent, dispatchMouseEvent} from '../../testing/private';
import {OverlayModule, Overlay} from '../index';
import {OverlayOutsideClickDispatcher} from './overlay-outside-click-dispatcher';
Expand All @@ -11,7 +11,8 @@ describe('OverlayOutsideClickDispatcher', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [OverlayModule, TestComponentModule],
imports: [OverlayModule],
declarations: [TestComponent],
});

inject(
Expand Down Expand Up @@ -186,78 +187,90 @@ describe('OverlayOutsideClickDispatcher', () => {
overlayRef.dispose();
});

it('should dispatch an event when a click is started outside the overlay and ' +
'released outside of it', () => {
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);
const context = document.createElement('div');
document.body.appendChild(context);

const spy = jasmine.createSpy('overlay mouse click event spy');
overlayRef.outsidePointerEvents().subscribe(spy);

dispatchMouseEvent(context, 'pointerdown');
context.click();
expect(spy).toHaveBeenCalled();

context.remove();
overlayRef.dispose();
});

it('should not dispatch an event when a click is started inside the overlay and ' +
'released inside of it', () => {
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);

const spy = jasmine.createSpy('overlay mouse click event spy');
overlayRef.outsidePointerEvents().subscribe(spy);

dispatchMouseEvent(overlayRef.overlayElement, 'pointerdown');
overlayRef.overlayElement.click();
expect(spy).not.toHaveBeenCalled();

overlayRef.dispose();
});

it('should not dispatch an event when a click is started inside the overlay and ' +
'released outside of it', () => {
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);
const context = document.createElement('div');
document.body.appendChild(context);

const spy = jasmine.createSpy('overlay mouse click event spy');
overlayRef.outsidePointerEvents().subscribe(spy);

dispatchMouseEvent(overlayRef.overlayElement, 'pointerdown');
context.click();
expect(spy).not.toHaveBeenCalled();

context.remove();
overlayRef.dispose();
});
it(
'should dispatch an event when a click is started outside the overlay and ' +
'released outside of it',
() => {
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);
const context = document.createElement('div');
document.body.appendChild(context);

const spy = jasmine.createSpy('overlay mouse click event spy');
overlayRef.outsidePointerEvents().subscribe(spy);

dispatchMouseEvent(context, 'pointerdown');
context.click();
expect(spy).toHaveBeenCalled();

it('should not dispatch an event when a click is started outside the overlay and ' +
'released inside of it', () => {
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);
const context = document.createElement('div');
document.body.appendChild(context);
context.remove();
overlayRef.dispose();
},
);

const spy = jasmine.createSpy('overlay mouse click event spy');
overlayRef.outsidePointerEvents().subscribe(spy);
it(
'should not dispatch an event when a click is started inside the overlay and ' +
'released inside of it',
() => {
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);

const spy = jasmine.createSpy('overlay mouse click event spy');
overlayRef.outsidePointerEvents().subscribe(spy);

dispatchMouseEvent(overlayRef.overlayElement, 'pointerdown');
overlayRef.overlayElement.click();
expect(spy).not.toHaveBeenCalled();

overlayRef.dispose();
},
);

dispatchMouseEvent(context, 'pointerdown');
overlayRef.overlayElement.click();
expect(spy).not.toHaveBeenCalled();
it(
'should not dispatch an event when a click is started inside the overlay and ' +
'released outside of it',
() => {
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);
const context = document.createElement('div');
document.body.appendChild(context);

const spy = jasmine.createSpy('overlay mouse click event spy');
overlayRef.outsidePointerEvents().subscribe(spy);

dispatchMouseEvent(overlayRef.overlayElement, 'pointerdown');
context.click();
expect(spy).not.toHaveBeenCalled();

context.remove();
overlayRef.dispose();
},
);

context.remove();
overlayRef.dispose();
});
it(
'should not dispatch an event when a click is started outside the overlay and ' +
'released inside of it',
() => {
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);
const context = document.createElement('div');
document.body.appendChild(context);

const spy = jasmine.createSpy('overlay mouse click event spy');
overlayRef.outsidePointerEvents().subscribe(spy);

dispatchMouseEvent(context, 'pointerdown');
overlayRef.overlayElement.click();
expect(spy).not.toHaveBeenCalled();

context.remove();
overlayRef.dispose();
},
);

it('should dispatch an event when a context menu is triggered outside the overlay', () => {
const portal = new ComponentPortal(TestComponent);
Expand Down Expand Up @@ -329,12 +342,3 @@ describe('OverlayOutsideClickDispatcher', () => {
template: 'Hello',
})
class TestComponent {}

// Create a real (non-test) NgModule as a workaround for
// https://github.com/angular/angular/issues/10760
@NgModule({
exports: [TestComponent],
declarations: [TestComponent],
entryComponents: [TestComponent],
})
class TestComponentModule {}
15 changes: 2 additions & 13 deletions src/cdk/overlay/overlay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@angular/core/testing';
import {
Component,
NgModule,
ViewChild,
ViewContainerRef,
ErrorHandler,
Expand Down Expand Up @@ -47,7 +46,8 @@ describe('Overlay', () => {
waitForAsync(() => {
dir = 'ltr';
TestBed.configureTestingModule({
imports: [OverlayModule, PortalModule, OverlayTestModule],
imports: [OverlayModule, PortalModule],
declarations: [PizzaMsg, TestComponentWithTemplatePortals],
providers: [
{
provide: Directionality,
Expand Down Expand Up @@ -1080,17 +1080,6 @@ class TestComponentWithTemplatePortals {
constructor(public viewContainerRef: ViewContainerRef) {}
}

// Create a real (non-test) NgModule as a workaround for
// https://github.com/angular/angular/issues/10760
const TEST_COMPONENTS = [PizzaMsg, TestComponentWithTemplatePortals];
@NgModule({
imports: [OverlayModule, PortalModule],
exports: TEST_COMPONENTS,
declarations: TEST_COMPONENTS,
entryComponents: TEST_COMPONENTS,
})
class OverlayTestModule {}

class FakePositionStrategy implements PositionStrategy {
element: HTMLElement;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {ComponentPortal, PortalModule} from '@angular/cdk/portal';
import {CdkScrollable, ScrollingModule, ViewportRuler} from '@angular/cdk/scrolling';
import {dispatchFakeEvent, MockNgZone} from '../../testing/private';
import {Component, ElementRef, NgModule, NgZone} from '@angular/core';
import {Component, ElementRef, NgZone} from '@angular/core';
import {fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
import {Subscription} from 'rxjs';
import {map} from 'rxjs/operators';
Expand All @@ -28,7 +28,8 @@ describe('FlexibleConnectedPositionStrategy', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ScrollingModule, OverlayModule, OverlayTestModule],
imports: [ScrollingModule, OverlayModule, PortalModule],
declarations: [TestOverlay],
providers: [{provide: NgZone, useFactory: () => (zone = new MockNgZone())}],
});

Expand Down Expand Up @@ -2889,11 +2890,3 @@ function createOverflowContainerElement() {
`,
})
class TestOverlay {}

@NgModule({
imports: [OverlayModule, PortalModule],
exports: [TestOverlay],
declarations: [TestOverlay],
entryComponents: [TestOverlay],
})
class OverlayTestModule {}
13 changes: 3 additions & 10 deletions src/cdk/overlay/position/global-position-strategy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NgModule, NgZone, Component} from '@angular/core';
import {NgZone, Component} from '@angular/core';
import {TestBed} from '@angular/core/testing';
import {MockNgZone} from '../../testing/private';
import {PortalModule, ComponentPortal} from '@angular/cdk/portal';
Expand All @@ -11,7 +11,8 @@ describe('GlobalPositonStrategy', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [GlobalOverlayTestModule],
imports: [OverlayModule, PortalModule],
declarations: [BlankPortal],
providers: [{provide: NgZone, useFactory: () => (zone = new MockNgZone())}],
});

Expand Down Expand Up @@ -370,11 +371,3 @@ describe('GlobalPositonStrategy', () => {

@Component({template: ''})
class BlankPortal {}

@NgModule({
imports: [OverlayModule, PortalModule],
exports: [BlankPortal],
declarations: [BlankPortal],
entryComponents: [BlankPortal],
})
class GlobalOverlayTestModule {}
Loading