|
1 | 1 | import {Component, ViewChild, ElementRef, ViewChildren, QueryList} from '@angular/core';
|
2 |
| -import {TestBed, ComponentFixture} from '@angular/core/testing'; |
3 |
| -import {CdkMenu} from './menu'; |
| 2 | +import {TestBed, ComponentFixture, fakeAsync, tick} from '@angular/core/testing'; |
| 3 | +import {CDK_MENU_DEFAULT_OPTIONS, CdkMenu} from './menu'; |
4 | 4 | import {CdkContextMenuTrigger} from './context-menu-trigger';
|
5 | 5 | import {dispatchKeyboardEvent, dispatchMouseEvent} from '../testing/private';
|
6 | 6 | import {By} from '@angular/platform-browser';
|
7 | 7 | import {CdkMenuItem} from './menu-item';
|
8 | 8 | import {CdkMenuTrigger} from './menu-trigger';
|
9 | 9 | import {CdkMenuBar} from './menu-bar';
|
10 | 10 | import {LEFT_ARROW, RIGHT_ARROW} from '../keycodes';
|
| 11 | +import {OverlayContainer} from '../overlay'; |
11 | 12 |
|
12 | 13 | describe('CdkContextMenuTrigger', () => {
|
13 | 14 | describe('with simple context menu trigger', () => {
|
@@ -380,6 +381,77 @@ describe('CdkContextMenuTrigger', () => {
|
380 | 381 | });
|
381 | 382 | });
|
382 | 383 |
|
| 384 | + describe('with backdrop in options', () => { |
| 385 | + let fixture: ComponentFixture<SimpleContextMenu>; |
| 386 | + let overlayContainerElement: HTMLElement; |
| 387 | + |
| 388 | + beforeEach(() => { |
| 389 | + fixture = TestBed.createComponent(SimpleContextMenu); |
| 390 | + fixture.detectChanges(); |
| 391 | + }); |
| 392 | + |
| 393 | + /** Get the context in which the context menu should trigger. */ |
| 394 | + function getMenuTrigger() { |
| 395 | + return fixture.componentInstance.triggerElement.nativeElement; |
| 396 | + } |
| 397 | + |
| 398 | + /** Open up the context menu and run change detection. */ |
| 399 | + function openContextMenu() { |
| 400 | + // right click triggers a context menu event |
| 401 | + dispatchMouseEvent(getMenuTrigger(), 'contextmenu'); |
| 402 | + fixture.detectChanges(); |
| 403 | + } |
| 404 | + |
| 405 | + it('should not contain backdrop by default', fakeAsync(() => { |
| 406 | + openContextMenu(); |
| 407 | + overlayContainerElement = TestBed.inject(OverlayContainer).getContainerElement(); |
| 408 | + fixture.detectChanges(); |
| 409 | + tick(500); |
| 410 | + expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeFalsy(); |
| 411 | + })); |
| 412 | + |
| 413 | + it('should be able to add the backdrop using hasBackdrop option', fakeAsync(() => { |
| 414 | + TestBed.resetTestingModule(); |
| 415 | + TestBed.configureTestingModule({ |
| 416 | + providers: [{provide: CDK_MENU_DEFAULT_OPTIONS, useValue: {hasBackdrop: true}}], |
| 417 | + }); |
| 418 | + |
| 419 | + fixture = TestBed.createComponent(SimpleContextMenu); |
| 420 | + fixture.detectChanges(); |
| 421 | + |
| 422 | + openContextMenu(); |
| 423 | + |
| 424 | + overlayContainerElement = TestBed.inject(OverlayContainer).getContainerElement(); |
| 425 | + fixture.detectChanges(); |
| 426 | + tick(500); |
| 427 | + |
| 428 | + expect(overlayContainerElement.querySelector('.cdk-overlay-backdrop')).toBeTruthy(); |
| 429 | + })); |
| 430 | + |
| 431 | + it('should be able to add the custom backdrop class using backdropClass option', fakeAsync(() => { |
| 432 | + TestBed.resetTestingModule(); |
| 433 | + TestBed.configureTestingModule({ |
| 434 | + providers: [ |
| 435 | + { |
| 436 | + provide: CDK_MENU_DEFAULT_OPTIONS, |
| 437 | + useValue: {hasBackdrop: true, backdropClass: 'custom-backdrop'}, |
| 438 | + }, |
| 439 | + ], |
| 440 | + }); |
| 441 | + |
| 442 | + fixture = TestBed.createComponent(SimpleContextMenu); |
| 443 | + fixture.detectChanges(); |
| 444 | + |
| 445 | + openContextMenu(); |
| 446 | + |
| 447 | + overlayContainerElement = TestBed.inject(OverlayContainer).getContainerElement(); |
| 448 | + fixture.detectChanges(); |
| 449 | + tick(500); |
| 450 | + |
| 451 | + expect(overlayContainerElement.querySelector('.custom-backdrop')).toBeTruthy(); |
| 452 | + })); |
| 453 | + }); |
| 454 | + |
383 | 455 | describe('with shared triggered menu', () => {
|
384 | 456 | it('should allow a context menu and menubar trigger share a menu', () => {
|
385 | 457 | const fixture = TestBed.createComponent(MenuBarAndContextTriggerShareMenu);
|
|
0 commit comments