|
3 | 3 | * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -import { LEFT_ARROW, RIGHT_ARROW } from '@angular/cdk/keycodes'; |
| 6 | +import { ESCAPE, LEFT_ARROW, RIGHT_ARROW } from '@angular/cdk/keycodes'; |
7 | 7 | import { Overlay, OverlayContainer } from '@angular/cdk/overlay';
|
8 | 8 | import { Component, DebugElement, NgModule, NgZone, ViewChild } from '@angular/core';
|
9 | 9 | import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, inject, TestBed, tick } from '@angular/core/testing';
|
@@ -463,6 +463,23 @@ describe('Preview', () => {
|
463 | 463 | expect(previewInstance['reCenterImage']).toHaveBeenCalled();
|
464 | 464 | }));
|
465 | 465 |
|
| 466 | + it('should close image preview when escape is pressed', fakeAsync(() => { |
| 467 | + context.images = [{ src: QUICK_SRC }]; |
| 468 | + context.createUsingService(); |
| 469 | + const previewInstance = context.previewRef?.previewInstance!; |
| 470 | + previewInstance.ngOnInit(); |
| 471 | + tickChanges(); |
| 472 | + spyOn(previewInstance, 'onClose'); |
| 473 | + |
| 474 | + const event: KeyboardEvent = new KeyboardEvent('keydown', { |
| 475 | + keyCode: ESCAPE |
| 476 | + }); |
| 477 | + document.dispatchEvent(event); |
| 478 | + tick(); |
| 479 | + |
| 480 | + expect(previewInstance.onClose).toHaveBeenCalled(); |
| 481 | + })); |
| 482 | + |
466 | 483 | it('should container click work', fakeAsync(() => {
|
467 | 484 | context.firstSrc = QUICK_SRC;
|
468 | 485 | fixture.detectChanges();
|
|
0 commit comments