1
1
import { TestBed , inject , fakeAsync } from '@angular/core/testing' ;
2
2
import { Component , NgModule } from '@angular/core' ;
3
- import { dispatchMouseEvent } from '@angular/cdk/testing/private' ;
3
+ import { dispatchFakeEvent , dispatchMouseEvent } from '@angular/cdk/testing/private' ;
4
4
import { OverlayModule , OverlayContainer , Overlay } from '../index' ;
5
5
import { OverlayOutsideClickDispatcher } from './overlay-outside-click-dispatcher' ;
6
6
import { ComponentPortal } from '@angular/cdk/portal' ;
@@ -51,9 +51,7 @@ describe('OverlayOutsideClickDispatcher', () => {
51
51
overlayTwo . dispose ( ) ;
52
52
} ) ;
53
53
54
- it (
55
- 'should dispatch mouse click events to the attached overlays' ,
56
- ( ) => {
54
+ it ( 'should dispatch mouse click events to the attached overlays' , ( ) => {
57
55
const overlayOne = overlay . create ( ) ;
58
56
overlayOne . attach ( new ComponentPortal ( TestComponent ) ) ;
59
57
const overlayTwo = overlay . create ( ) ;
@@ -80,27 +78,53 @@ describe('OverlayOutsideClickDispatcher', () => {
80
78
overlayTwo . dispose ( ) ;
81
79
} ) ;
82
80
83
- it (
84
- 'should dispatch mouse click events to the attached overlays even when propagation is stopped' ,
85
- ( ) => {
86
- const overlayRef = overlay . create ( ) ;
87
- overlayRef . attach ( new ComponentPortal ( TestComponent ) ) ;
88
- const spy = jasmine . createSpy ( 'overlay mouse click event spy' ) ;
89
- overlayRef . outsidePointerEvents ( ) . subscribe ( spy ) ;
81
+ it ( 'should dispatch auxiliary button click events to the attached overlays' , ( ) => {
82
+ const overlayOne = overlay . create ( ) ;
83
+ overlayOne . attach ( new ComponentPortal ( TestComponent ) ) ;
84
+ const overlayTwo = overlay . create ( ) ;
85
+ overlayTwo . attach ( new ComponentPortal ( TestComponent ) ) ;
90
86
91
- outsideClickDispatcher . add ( overlayRef ) ;
87
+ const overlayOneSpy = jasmine . createSpy ( 'overlayOne auxiliary click event spy' ) ;
88
+ const overlayTwoSpy = jasmine . createSpy ( 'overlayTwo auxiliary click event spy' ) ;
89
+
90
+ overlayOne . outsidePointerEvents ( ) . subscribe ( overlayOneSpy ) ;
91
+ overlayTwo . outsidePointerEvents ( ) . subscribe ( overlayTwoSpy ) ;
92
+
93
+ outsideClickDispatcher . add ( overlayOne ) ;
94
+ outsideClickDispatcher . add ( overlayTwo ) ;
92
95
93
96
const button = document . createElement ( 'button' ) ;
94
97
document . body . appendChild ( button ) ;
95
- button . addEventListener ( 'click' , event => event . stopPropagation ( ) ) ;
96
- button . click ( ) ;
98
+ dispatchFakeEvent ( button , 'auxclick' ) ;
97
99
98
- expect ( spy ) . toHaveBeenCalled ( ) ;
100
+ expect ( overlayOneSpy ) . toHaveBeenCalled ( ) ;
101
+ expect ( overlayTwoSpy ) . toHaveBeenCalled ( ) ;
99
102
100
103
button . parentNode ! . removeChild ( button ) ;
101
- overlayRef . dispose ( ) ;
104
+ overlayOne . dispose ( ) ;
105
+ overlayTwo . dispose ( ) ;
102
106
} ) ;
103
107
108
+ it ( 'should dispatch mouse click events to the attached overlays even when propagation is stopped' ,
109
+ ( ) => {
110
+ const overlayRef = overlay . create ( ) ;
111
+ overlayRef . attach ( new ComponentPortal ( TestComponent ) ) ;
112
+ const spy = jasmine . createSpy ( 'overlay mouse click event spy' ) ;
113
+ overlayRef . outsidePointerEvents ( ) . subscribe ( spy ) ;
114
+
115
+ outsideClickDispatcher . add ( overlayRef ) ;
116
+
117
+ const button = document . createElement ( 'button' ) ;
118
+ document . body . appendChild ( button ) ;
119
+ button . addEventListener ( 'click' , event => event . stopPropagation ( ) ) ;
120
+ button . click ( ) ;
121
+
122
+ expect ( spy ) . toHaveBeenCalled ( ) ;
123
+
124
+ button . parentNode ! . removeChild ( button ) ;
125
+ overlayRef . dispose ( ) ;
126
+ } ) ;
127
+
104
128
it ( 'should dispose of the global click event handler correctly' , ( ) => {
105
129
const overlayRef = overlay . create ( ) ;
106
130
const body = document . body ;
@@ -191,10 +215,8 @@ describe('OverlayOutsideClickDispatcher', () => {
191
215
overlayRef . dispose ( ) ;
192
216
} ) ;
193
217
194
- it (
195
- 'should not throw an error when when closing out related components via the' +
196
- ' outsidePointerEvents emitter on background click' ,
197
- fakeAsync ( ( ) => {
218
+ it ( 'should not throw an error when when closing out related components via the ' +
219
+ 'outsidePointerEvents emitter on background click' , fakeAsync ( ( ) => {
198
220
const firstOverlayRef = overlay . create ( ) ;
199
221
firstOverlayRef . attach ( new ComponentPortal ( TestComponent ) ) ;
200
222
const secondOverlayRef = overlay . create ( ) ;
0 commit comments