disable esc button when the viewer is not in overlaymode

This commit is contained in:
Eugenio Romano
2016-08-02 14:37:04 +01:00
parent 90f1dec1e3
commit 99f5744543
2 changed files with 19 additions and 1 deletions

View File

@@ -117,6 +117,23 @@ import { EventMock } from './assets/event.mock';
}); });
})); }));
it('Esc button should not hide the viewer if is not overlay mode', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(ViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
let component = fixture.componentInstance;
component.overlayMode = false;
component.urlFile = 'fake-url-file';
fixture.detectChanges();
EventMock.keyDown(27);
fixture.detectChanges();
expect(element.querySelector('#viewer-main-container')).not.toBeNull();
});
}));
it('Esc button should hide the viewer', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { it('Esc button should hide the viewer', inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb return tcb
.createAsync(ViewerComponent) .createAsync(ViewerComponent)
@@ -124,6 +141,7 @@ import { EventMock } from './assets/event.mock';
let element = fixture.nativeElement; let element = fixture.nativeElement;
let component = fixture.componentInstance; let component = fixture.componentInstance;
component.urlFile = 'fake-url-file'; component.urlFile = 'fake-url-file';
component.overlayMode = true;
fixture.detectChanges(); fixture.detectChanges();
EventMock.keyDown(27); EventMock.keyDown(27);

View File

@@ -166,7 +166,7 @@ export class ViewerComponent {
@HostListener('document:keydown', ['$event']) @HostListener('document:keydown', ['$event'])
handleKeyboardEvent(event: KeyboardEvent) { handleKeyboardEvent(event: KeyboardEvent) {
let key = event.keyCode; let key = event.keyCode;
if (key === 27) { // esc if (key === 27 && this.overlayMode) { // esc
this.close(); this.close();
} }
} }