@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
13
13
limitations under the License.
14
14
==============================================================================*/
15
15
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
16
+ import { By } from '@angular/platform-browser' ;
16
17
import { CustomModalComponent } from './custom_modal_component' ;
17
18
import { CommonModule } from '@angular/common' ;
18
19
import {
@@ -135,4 +136,59 @@ describe('custom modal', () => {
135
136
expect ( fixture . componentInstance . isOpen ) . toBeFalse ( ) ;
136
137
} ) ;
137
138
} ) ;
139
+
140
+ describe ( 'ensures content is always within the window' , ( ) => {
141
+ beforeEach ( ( ) => {
142
+ window . innerHeight = 1000 ;
143
+ window . innerWidth = 1000 ;
144
+ } ) ;
145
+
146
+ it ( 'sets left to 0 if less than 0' , async ( ) => {
147
+ const fixture = TestBed . createComponent ( TestableComponent ) ;
148
+ fixture . detectChanges ( ) ;
149
+ fixture . componentInstance . openAtPosition ( { x : - 10 , y : 0 } ) ;
150
+ expect ( fixture . componentInstance . isOpen ) . toBeFalse ( ) ;
151
+ await waitFrame ( ) ;
152
+ fixture . detectChanges ( ) ;
153
+
154
+ const content = fixture . debugElement . query ( By . css ( '.content' ) ) ;
155
+ expect ( content . nativeElement . style . left ) . toEqual ( '0px' ) ;
156
+ } ) ;
157
+
158
+ it ( 'sets top to 0 if less than 0' , async ( ) => {
159
+ const fixture = TestBed . createComponent ( TestableComponent ) ;
160
+ fixture . detectChanges ( ) ;
161
+ fixture . componentInstance . openAtPosition ( { x : 0 , y : - 10 } ) ;
162
+ expect ( fixture . componentInstance . isOpen ) . toBeFalse ( ) ;
163
+ await waitFrame ( ) ;
164
+ fixture . detectChanges ( ) ;
165
+
166
+ const content = fixture . debugElement . query ( By . css ( '.content' ) ) ;
167
+ expect ( content . nativeElement . style . top ) . toEqual ( '0px' ) ;
168
+ } ) ;
169
+
170
+ it ( 'sets left to maximum if content overflows the window' , async ( ) => {
171
+ const fixture = TestBed . createComponent ( TestableComponent ) ;
172
+ fixture . detectChanges ( ) ;
173
+ fixture . componentInstance . openAtPosition ( { x : 1010 , y : 0 } ) ;
174
+ expect ( fixture . componentInstance . isOpen ) . toBeFalse ( ) ;
175
+ await waitFrame ( ) ;
176
+ fixture . detectChanges ( ) ;
177
+ const content = fixture . debugElement . query ( By . css ( '.content' ) ) ;
178
+ // While rendering in a test the elements width and height will appear to be 0.
179
+ expect ( content . nativeElement . style . left ) . toEqual ( '1000px' ) ;
180
+ } ) ;
181
+
182
+ it ( 'sets top to maximum if content overflows the window' , async ( ) => {
183
+ const fixture = TestBed . createComponent ( TestableComponent ) ;
184
+ fixture . detectChanges ( ) ;
185
+ fixture . componentInstance . openAtPosition ( { x : 0 , y : 1010 } ) ;
186
+ expect ( fixture . componentInstance . isOpen ) . toBeFalse ( ) ;
187
+ await waitFrame ( ) ;
188
+ fixture . detectChanges ( ) ;
189
+ const content = fixture . debugElement . query ( By . css ( '.content' ) ) ;
190
+ // While rendering in a test the elements width and height will appear to be 0.
191
+ expect ( content . nativeElement . style . top ) . toEqual ( '1000px' ) ;
192
+ } ) ;
193
+ } ) ;
138
194
} ) ;
0 commit comments