|
| 1 | +import { ESCAPE } from '@angular/cdk/keycodes'; |
1 | 2 | import { OverlayContainer, ScrollDispatcher } from '@angular/cdk/overlay';
|
2 | 3 | import { ApplicationRef, Component, Provider, Type, ViewChild } from '@angular/core';
|
3 | 4 | import { ComponentFixture, TestBed, fakeAsync, inject, tick } from '@angular/core/testing';
|
4 | 5 | import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
5 | 6 | import { RouterTestingModule } from '@angular/router/testing';
|
6 | 7 | import { Subject } from 'rxjs';
|
7 | 8 |
|
8 |
| -import { createMouseEvent } from 'ng-zorro-antd/core/testing'; |
| 9 | +import { createKeyboardEvent, createMouseEvent, dispatchEvent } from 'ng-zorro-antd/core/testing'; |
9 | 10 | import { NzMenuModule } from 'ng-zorro-antd/menu';
|
10 | 11 |
|
11 | 12 | import { NzContextMenuService } from './context-menu.service';
|
@@ -120,6 +121,27 @@ describe('context-menu', () => {
|
120 | 121 | expect(overlayContainerElement.textContent).toBe('');
|
121 | 122 | }).not.toThrowError();
|
122 | 123 | }));
|
| 124 | + it('should backdrop work with keyboard event ESCAPE', fakeAsync(() => { |
| 125 | + const fixture = createComponent(NzTestDropdownContextMenuComponent, [], []); |
| 126 | + const keyboardEvent = createKeyboardEvent('keydown', ESCAPE, undefined, 'Escape'); |
| 127 | + fixture.detectChanges(); |
| 128 | + expect(overlayContainerElement.textContent).toBe(''); |
| 129 | + fixture.detectChanges(); |
| 130 | + expect(() => { |
| 131 | + const fakeEvent = createMouseEvent('contextmenu', 300, 300); |
| 132 | + const component = fixture.componentInstance; |
| 133 | + component.nzContextMenuService.create(fakeEvent, component.nzDropdownMenuComponent); |
| 134 | + fixture.detectChanges(); |
| 135 | + tick(1000); |
| 136 | + fixture.detectChanges(); |
| 137 | + expect(overlayContainerElement.textContent).toContain('1st menu item'); |
| 138 | + dispatchEvent(document.body, keyboardEvent); |
| 139 | + fixture.detectChanges(); |
| 140 | + tick(1000); |
| 141 | + fixture.detectChanges(); |
| 142 | + expect(overlayContainerElement.textContent).toBe(''); |
| 143 | + }).not.toThrowError(); |
| 144 | + })); |
123 | 145 | it('should not run change detection if the overlay is clicked inside', async () => {
|
124 | 146 | const fixture = createComponent(NzTestDropdownContextMenuComponent, [], []);
|
125 | 147 | fixture.detectChanges();
|
|
0 commit comments