mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
[ci:force][AAE-30877] - fixing core pdf test
This commit is contained in:
committed by
Wojciech Duda
parent
6e230adaa5
commit
6d0571a308
@@ -26,15 +26,13 @@ describe('DownloadService', () => {
|
|||||||
|
|
||||||
describe('Download blob', () => {
|
describe('Download blob', () => {
|
||||||
it('Should use native msSaveOrOpenBlob if the browser is IE', () => {
|
it('Should use native msSaveOrOpenBlob if the browser is IE', () => {
|
||||||
const navigatorAny: any = window.navigator;
|
const mockNavigator = jasmine.createSpyObj(['msSaveOrOpenBlob']);
|
||||||
|
spyOnProperty(window, 'navigator', 'get').and.returnValue(mockNavigator);
|
||||||
// eslint-disable-next-line no-underscore-dangle
|
|
||||||
navigatorAny.__defineGetter__('msSaveOrOpenBlob', (result) => {
|
|
||||||
expect(result).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
const blob = new Blob([''], { type: 'text/html' });
|
const blob = new Blob([''], { type: 'text/html' });
|
||||||
service.downloadBlob(blob, 'test_ie');
|
service.downloadBlob(blob, 'test_ie');
|
||||||
|
|
||||||
|
expect(mockNavigator.msSaveOrOpenBlob).toHaveBeenCalledOnceWith(blob, 'test_ie');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -16,13 +16,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, inject, TestBed } from '@angular/core/testing';
|
||||||
import { CoreTestingModule } from '../../testing/core.testing.module';
|
|
||||||
import { NotificationHistoryComponent } from './notification-history.component';
|
import { NotificationHistoryComponent } from './notification-history.component';
|
||||||
import { OverlayContainer } from '@angular/cdk/overlay';
|
import { OverlayContainer } from '@angular/cdk/overlay';
|
||||||
import { NotificationService } from '../services/notification.service';
|
import { NotificationService } from '../services/notification.service';
|
||||||
import { StorageService } from '../../common/services/storage.service';
|
import { StorageService } from '../../common/services/storage.service';
|
||||||
import { NOTIFICATION_TYPE, NotificationModel } from '../models/notification.model';
|
import { NOTIFICATION_TYPE, NotificationModel } from '../models/notification.model';
|
||||||
import { UnitTestingUtils } from '../../testing/unit-testing-utils';
|
import { UnitTestingUtils } from '../../testing/unit-testing-utils';
|
||||||
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { NoopTranslateModule } from '../../testing/noop-translate.module';
|
||||||
|
import { NoopAuthModule } from '../../testing/noop-auth.module';
|
||||||
|
import { MatIconTestingModule } from '@angular/material/icon/testing';
|
||||||
|
|
||||||
describe('Notification History Component', () => {
|
describe('Notification History Component', () => {
|
||||||
let fixture: ComponentFixture<NotificationHistoryComponent>;
|
let fixture: ComponentFixture<NotificationHistoryComponent>;
|
||||||
@@ -40,7 +43,7 @@ describe('Notification History Component', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [CoreTestingModule, NotificationHistoryComponent]
|
imports: [NoopAnimationsModule, NoopTranslateModule, NoopAuthModule, NotificationHistoryComponent, MatIconTestingModule]
|
||||||
});
|
});
|
||||||
fixture = TestBed.createComponent(NotificationHistoryComponent);
|
fixture = TestBed.createComponent(NotificationHistoryComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
@@ -131,15 +131,15 @@ describe('NotificationService', () => {
|
|||||||
it('should open a message notification bar', async () => {
|
it('should open a message notification bar', async () => {
|
||||||
fixture.componentInstance.sendMessage();
|
fixture.componentInstance.sendMessage();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
const isLoaded = await testingUtils.checkIfMatSnackbarExists();
|
||||||
expect(await testingUtils.checkIfMatSnackbarExists()).toBe(true);
|
expect(isLoaded).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should open a message notification bar without custom configuration', async () => {
|
it('should open a message notification bar without custom configuration', async () => {
|
||||||
fixture.componentInstance.sendMessageWithoutConfig();
|
fixture.componentInstance.sendMessageWithoutConfig();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
const isLoaded = await testingUtils.checkIfMatSnackbarExists();
|
||||||
expect(await testingUtils.checkIfMatSnackbarExists()).toBe(true);
|
expect(isLoaded).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should open a message notification bar with custom configuration', async () => {
|
it('should open a message notification bar with custom configuration', async () => {
|
||||||
|
@@ -21,7 +21,6 @@ import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testin
|
|||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { firstValueFrom, of } from 'rxjs';
|
import { firstValueFrom, of } from 'rxjs';
|
||||||
import { take } from 'rxjs/operators';
|
|
||||||
import { AppConfigService } from '../../../app-config';
|
import { AppConfigService } from '../../../app-config';
|
||||||
import { EventMock } from '../../../mock';
|
import { EventMock } from '../../../mock';
|
||||||
import { NoopAuthModule, NoopTranslateModule, UnitTestingUtils } from '../../../testing';
|
import { NoopAuthModule, NoopTranslateModule, UnitTestingUtils } from '../../../testing';
|
||||||
@@ -32,12 +31,12 @@ import { AnnotationMode } from 'pdfjs-dist';
|
|||||||
|
|
||||||
declare const pdfjsLib: any;
|
declare const pdfjsLib: any;
|
||||||
|
|
||||||
@Component({
|
// @Component({
|
||||||
selector: 'adf-test-dialog-component',
|
// selector: 'adf-test-dialog-component',
|
||||||
standalone: true,
|
// standalone: true,
|
||||||
template: ''
|
// template: ''
|
||||||
})
|
// })
|
||||||
class TestDialogComponent {}
|
// class TestDialogComponent {}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-url-test-component',
|
selector: 'adf-url-test-component',
|
||||||
@@ -117,7 +116,7 @@ describe('Test PdfViewer component', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [NoopAuthModule, NoopTranslateModule, UrlTestComponent, TestDialogComponent, UrlTestPasswordComponent, BlobTestComponent],
|
imports: [NoopAuthModule, NoopTranslateModule, PdfViewerComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
provide: MatDialog,
|
provide: MatDialog,
|
||||||
@@ -144,350 +143,10 @@ describe('Test PdfViewer component', () => {
|
|||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('User interaction', () => {
|
|
||||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
|
||||||
let componentUrlTestComponent: UrlTestComponent;
|
|
||||||
let elementUrlTestComponent: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach((done) => {
|
|
||||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
|
||||||
componentUrlTestComponent = fixtureUrlTestComponent.componentInstance;
|
|
||||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
|
||||||
testingUtils.setDebugElement(fixtureUrlTestComponent.debugElement);
|
|
||||||
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
|
||||||
appConfig.config['adf-viewer.pdf-viewer-scaling'] = 10;
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
document.body.removeChild(elementUrlTestComponent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should init the viewer with annotation mode disabled', fakeAsync(() => {
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
tick(400);
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.annotationEditorMode).toBe(AnnotationMode.DISABLE);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should Total number of pages be loaded', fakeAsync(() => {
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
tick(400);
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.totalPages).toBe(6);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should nextPage move to the next page', fakeAsync(() => {
|
|
||||||
testingUtils.clickByCSS('#viewer-next-page-button');
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
tick(400);
|
|
||||||
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should event RIGHT_ARROW keyboard change pages', fakeAsync(() => {
|
|
||||||
fixtureUrlTestComponent.whenStable();
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
EventMock.keyDown(RIGHT_ARROW);
|
|
||||||
|
|
||||||
tick(250);
|
|
||||||
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should event LEFT_ARROW keyboard change pages', (done) => {
|
|
||||||
component.inputPage('2');
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
EventMock.keyDown(LEFT_ARROW);
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(1);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should previous page move to the previous page', (done) => {
|
|
||||||
testingUtils.clickByCSS('#viewer-next-page-button');
|
|
||||||
testingUtils.clickByCSS('#viewer-next-page-button');
|
|
||||||
testingUtils.clickByCSS('#viewer-previous-page-button');
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should previous page not move to the previous page if is page 1', (done) => {
|
|
||||||
component.previousPage();
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(1);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should Input page move to the inserted page', (done) => {
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.inputPage('2');
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
describe('Zoom', () => {
|
|
||||||
it('should zoom in increment the scale value', async () => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
|
||||||
|
|
||||||
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue;
|
|
||||||
testingUtils.clickByCSS('#viewer-zoom-in-button');
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
await fixtureUrlTestComponent.whenRenderingDone();
|
|
||||||
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
|
||||||
const currentZoom = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue;
|
|
||||||
expect(zoomBefore < currentZoom).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should zoom out decrement the scale value', async () => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
|
||||||
testingUtils.clickByCSS('#viewer-zoom-in-button');
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue;
|
|
||||||
|
|
||||||
testingUtils.clickByCSS('#viewer-zoom-out-button');
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
await fixtureUrlTestComponent.whenRenderingDone();
|
|
||||||
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
|
||||||
const currentZoom = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue;
|
|
||||||
expect(zoomBefore > currentZoom).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should it-in button toggle page-fit and auto scale mode', fakeAsync(() => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
|
||||||
tick(250);
|
|
||||||
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('init');
|
|
||||||
testingUtils.clickByCSS('#viewer-scale-page-button');
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit');
|
|
||||||
testingUtils.clickByCSS('#viewer-scale-page-button');
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
|
||||||
testingUtils.clickByCSS('#viewer-scale-page-button');
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit');
|
|
||||||
}), 300);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Resize interaction', () => {
|
|
||||||
it('should resize event trigger setScaleUpdatePages', (done) => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent, 'onResize');
|
|
||||||
EventMock.resizeMobileView();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.onResize).toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Thumbnails', () => {
|
|
||||||
it('should have own context', (done) => {
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfThumbnailsContext.viewer).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should open thumbnails panel', (done) => {
|
|
||||||
expect(testingUtils.getByCSS('.adf-pdf-viewer__thumbnails')).toBeNull();
|
|
||||||
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.toggleThumbnails();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(testingUtils.getByCSS('.adf-pdf-viewer__thumbnails')).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should not render PdfThumbListComponent during initialization of new pdfViewer', () => {
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.toggleThumbnails();
|
|
||||||
componentUrlTestComponent.urlFile = 'file.pdf';
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
expect(fixtureUrlTestComponent.debugElement.query(By.directive(PdfThumbListComponent))).toBeNull();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Viewer events', () => {
|
|
||||||
it('should react on the emit of pageChange event', (done) => {
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
const args = {
|
|
||||||
pageNumber: 6,
|
|
||||||
source: {
|
|
||||||
container: document.getElementById(`${componentUrlTestComponent.pdfViewerComponent.randomPdfId}-viewer-pdf-viewer`)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* cspell:disable-next-line */
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.pdfViewer.eventBus.dispatch('pagechanging', args);
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(6);
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.page).toBe(6);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should react on the emit of pagesLoaded event', (done) => {
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled).toBeFalsy();
|
|
||||||
|
|
||||||
const args = {
|
|
||||||
pagesCount: 10,
|
|
||||||
source: {
|
|
||||||
container: document.getElementById(`${componentUrlTestComponent.pdfViewerComponent.randomPdfId}-viewer-pdf-viewer`)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* cspell:disable-next-line */
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.pdfViewer.eventBus.dispatch('pagesloaded', args);
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled).toBe(false);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should Loader be present', () => {
|
it('should Loader be present', () => {
|
||||||
expect(testingUtils.getByCSS('.adf-loader-container')).not.toBeNull();
|
expect(testingUtils.getByCSS('.adf-loader-container')).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Zoom customization', () => {
|
|
||||||
describe('custom value', () => {
|
|
||||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
|
||||||
let componentUrlTestComponent: UrlTestComponent;
|
|
||||||
let elementUrlTestComponent: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach((done) => {
|
|
||||||
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
|
||||||
appConfig.config['adf-viewer.pdf-viewer-scaling'] = 80;
|
|
||||||
|
|
||||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
|
||||||
componentUrlTestComponent = fixtureUrlTestComponent.componentInstance;
|
|
||||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
document.body.removeChild(elementUrlTestComponent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should use the custom zoom if it is present in the app.config', async () => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
await fixtureUrlTestComponent.whenStable();
|
|
||||||
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScale).toBe(0.8);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('less than the minimum allowed value', () => {
|
|
||||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
|
||||||
let componentUrlTestComponent: UrlTestComponent;
|
|
||||||
let elementUrlTestComponent: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach((done) => {
|
|
||||||
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
|
||||||
appConfig.config['adf-viewer.pdf-viewer-scaling'] = 10;
|
|
||||||
|
|
||||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
|
||||||
componentUrlTestComponent = fixtureUrlTestComponent.componentInstance;
|
|
||||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
componentUrlTestComponent.pdfViewerComponent.rendered.pipe(take(1)).subscribe(() => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
document.body.removeChild(elementUrlTestComponent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should use the minimum scale zoom if the value given in app.config is less than the minimum allowed scale', (done) => {
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue).toBe('0.25');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('greater than the maximum allowed value', () => {
|
|
||||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
|
||||||
let componentUrlTestComponent: UrlTestComponent;
|
|
||||||
let elementUrlTestComponent: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
|
||||||
appConfig.config['adf-viewer.pdf-viewer-scaling'] = 55555;
|
|
||||||
|
|
||||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
|
||||||
componentUrlTestComponent = fixtureUrlTestComponent.componentInstance;
|
|
||||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
document.body.removeChild(elementUrlTestComponent);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should use the maximum scale zoom if the value given in app.config is greater than the maximum allowed scale', async () => {
|
|
||||||
await firstValueFrom(componentUrlTestComponent.pdfViewerComponent.rendered)
|
|
||||||
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
|
||||||
await fixtureUrlTestComponent.whenStable();
|
|
||||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScale).toBe(10);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Required values', () => {
|
describe('Required values', () => {
|
||||||
it('should thrown an error If urlFile is not present', () => {
|
it('should thrown an error If urlFile is not present', () => {
|
||||||
change = new SimpleChange(null, null, true);
|
change = new SimpleChange(null, null, true);
|
||||||
@@ -524,39 +183,32 @@ describe('Test PdfViewer component', () => {
|
|||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should Canvas be present', (done) => {
|
it('should Canvas be present', async () => {
|
||||||
fixtureUrlTestComponent.detectChanges();
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
expect(testingUtils.getByCSS('.adf-pdfViewer')).not.toBeNull();
|
||||||
expect(testingUtils.getByCSS('.adf-pdfViewer')).not.toBeNull();
|
expect(testingUtils.getByCSS('.adf-viewer-pdf-viewer')).not.toBeNull();
|
||||||
expect(testingUtils.getByCSS('.adf-viewer-pdf-viewer')).not.toBeNull();
|
});
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should Input Page elements be present', (done) => {
|
it('should Input Page elements be present', async () => {
|
||||||
fixtureUrlTestComponent.detectChanges();
|
fixtureUrlTestComponent.detectChanges();
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
await fixtureUrlTestComponent.whenStable();
|
||||||
/* cspell:disable-next-line */
|
expect(testingUtils.getByCSS('.viewer-pagenumber-input')).toBeDefined();
|
||||||
expect(testingUtils.getByCSS('.viewer-pagenumber-input')).toBeDefined();
|
expect(testingUtils.getByCSS('.viewer-total-pages')).toBeDefined();
|
||||||
expect(testingUtils.getByCSS('.viewer-total-pages')).toBeDefined();
|
|
||||||
|
|
||||||
expect(testingUtils.getByCSS('#viewer-previous-page-button')).not.toBeNull();
|
expect(testingUtils.getByCSS('#viewer-previous-page-button')).not.toBeNull();
|
||||||
expect(testingUtils.getByCSS('#viewer-next-page-button')).not.toBeNull();
|
expect(testingUtils.getByCSS('#viewer-next-page-button')).not.toBeNull();
|
||||||
done();
|
});
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should Toolbar be hide if showToolbar is false', (done) => {
|
it('should Toolbar be hide if showToolbar is false', async () => {
|
||||||
component.showToolbar = false;
|
component.showToolbar = false;
|
||||||
|
|
||||||
fixtureUrlTestComponent.detectChanges();
|
fixtureUrlTestComponent.detectChanges();
|
||||||
fixtureUrlTestComponent.whenStable().then(() => {
|
await fixtureUrlTestComponent.whenStable();
|
||||||
expect(testingUtils.getByCSS('.viewer-toolbar-command')).toBeNull();
|
expect(testingUtils.getByCSS('.viewer-toolbar-command')).toBeNull();
|
||||||
expect(testingUtils.getByCSS('.viewer-toolbar-pagination')).toBeNull();
|
expect(testingUtils.getByCSS('.viewer-toolbar-pagination')).toBeNull();
|
||||||
done();
|
});
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('View with blob file', () => {
|
describe('View with blob file', () => {
|
||||||
@@ -577,50 +229,41 @@ describe('Test PdfViewer component', () => {
|
|||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should Canvas be present', () => {
|
it('should Canvas be present', async () => {
|
||||||
fixtureBlobTestComponent.detectChanges();
|
fixtureBlobTestComponent.detectChanges();
|
||||||
|
await fixtureBlobTestComponent.whenStable();
|
||||||
|
|
||||||
fixtureBlobTestComponent.whenStable().then(() => {
|
expect(testingUtils.getByCSS('.adf-pdfViewer')).not.toBeNull();
|
||||||
expect(testingUtils.getByCSS('.adf-pdfViewer')).not.toBeNull();
|
expect(testingUtils.getByCSS('.adf-viewer-pdf-viewer')).not.toBeNull();
|
||||||
expect(testingUtils.getByCSS('.adf-viewer-pdf-viewer')).not.toBeNull();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should Next an Previous Buttons be present', (done) => {
|
it('should Next an Previous Buttons be present', async () => {
|
||||||
fixtureBlobTestComponent.detectChanges();
|
fixtureBlobTestComponent.detectChanges();
|
||||||
|
await fixtureBlobTestComponent.whenStable();
|
||||||
|
|
||||||
fixtureBlobTestComponent.whenStable().then(() => {
|
expect(testingUtils.getByCSS('#viewer-previous-page-button')).not.toBeNull();
|
||||||
expect(testingUtils.getByCSS('#viewer-previous-page-button')).not.toBeNull();
|
expect(testingUtils.getByCSS('#viewer-next-page-button')).not.toBeNull();
|
||||||
expect(testingUtils.getByCSS('#viewer-next-page-button')).not.toBeNull();
|
});
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should Input Page elements be present', (done) => {
|
it('should Input Page elements be present', async () => {
|
||||||
fixtureBlobTestComponent.detectChanges();
|
fixtureBlobTestComponent.detectChanges();
|
||||||
|
await fixtureBlobTestComponent.whenStable();
|
||||||
|
/* cspell:disable-next-line */
|
||||||
|
expect(testingUtils.getByCSS('.adf-viewer-pagenumber-input')).toBeDefined();
|
||||||
|
expect(testingUtils.getByCSS('.adf-viewer-total-pages')).toBeDefined();
|
||||||
|
expect(testingUtils.getByCSS('#viewer-previous-page-button')).not.toBeNull();
|
||||||
|
expect(testingUtils.getByCSS('#viewer-next-page-button')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
fixtureBlobTestComponent.whenStable().then(() => {
|
it('should Toolbar be hide if showToolbar is false', async () => {
|
||||||
/* cspell:disable-next-line */
|
|
||||||
expect(testingUtils.getByCSS('.adf-viewer-pagenumber-input')).toBeDefined();
|
|
||||||
expect(testingUtils.getByCSS('.adf-viewer-total-pages')).toBeDefined();
|
|
||||||
|
|
||||||
expect(testingUtils.getByCSS('#viewer-previous-page-button')).not.toBeNull();
|
|
||||||
expect(testingUtils.getByCSS('#viewer-next-page-button')).not.toBeNull();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
|
|
||||||
it('should Toolbar be hide if showToolbar is false', (done) => {
|
|
||||||
fixtureBlobTestComponent.componentInstance.pdfViewerComponent.showToolbar = false;
|
fixtureBlobTestComponent.componentInstance.pdfViewerComponent.showToolbar = false;
|
||||||
|
|
||||||
fixtureBlobTestComponent.detectChanges();
|
fixtureBlobTestComponent.detectChanges();
|
||||||
|
await fixtureBlobTestComponent.whenStable();
|
||||||
|
|
||||||
fixtureBlobTestComponent.whenStable().then(() => {
|
expect(testingUtils.getByCSS('.viewer-toolbar-command')).toBeNull();
|
||||||
expect(testingUtils.getByCSS('.viewer-toolbar-command')).toBeNull();
|
expect(testingUtils.getByCSS('.viewer-toolbar-pagination')).toBeNull();
|
||||||
expect(testingUtils.getByCSS('.viewer-toolbar-pagination')).toBeNull();
|
});
|
||||||
done();
|
|
||||||
});
|
|
||||||
}, 55000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Password protection dialog', () => {
|
describe('Password protection dialog', () => {
|
||||||
@@ -717,3 +360,318 @@ describe('Test PdfViewer component', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Test PdfViewer - Zoom customization', () => {
|
||||||
|
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||||
|
let componentUrlTestComponent: UrlTestComponent;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [NoopAuthModule, NoopTranslateModule, UrlTestComponent, PdfViewerComponent],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: MatDialog,
|
||||||
|
useValue: {
|
||||||
|
open: () => {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
RenderingQueueServices
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
||||||
|
componentUrlTestComponent = fixtureUrlTestComponent.componentInstance;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fixtureUrlTestComponent.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('custom value', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
||||||
|
appConfig.config['adf-viewer.pdf-viewer-scaling'] = 80;
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
await firstValueFrom(componentUrlTestComponent.pdfViewerComponent.rendered);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the custom zoom if it is present in the app.config', async () => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScale).toBe(0.8);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('less than the minimum allowed value', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
||||||
|
appConfig.config['adf-viewer.pdf-viewer-scaling'] = 10;
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
await firstValueFrom(componentUrlTestComponent.pdfViewerComponent.rendered);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the minimum scale zoom if the value given in app.config is less than the minimum allowed scale', async () => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue).toBe('0.25');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('greater than the maximum allowed value', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
||||||
|
appConfig.config['adf-viewer.pdf-viewer-scaling'] = 5555;
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
await firstValueFrom(componentUrlTestComponent.pdfViewerComponent.rendered);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use the maximum scale zoom if the value given in app.config is greater than the maximum allowed scale', async () => {
|
||||||
|
await firstValueFrom(componentUrlTestComponent.pdfViewerComponent.rendered);
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScale).toBe(10);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Test PdfViewer - User interaction', () => {
|
||||||
|
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||||
|
let componentUrlTestComponent: UrlTestComponent;
|
||||||
|
// let elementUrlTestComponent: HTMLElement;
|
||||||
|
let testingUtils: UnitTestingUtils;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [NoopAuthModule, NoopTranslateModule, UrlTestComponent, PdfViewerComponent],
|
||||||
|
providers: [
|
||||||
|
{
|
||||||
|
provide: MatDialog,
|
||||||
|
useValue: {
|
||||||
|
open: () => {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
RenderingQueueServices
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
||||||
|
testingUtils = new UnitTestingUtils(fixtureUrlTestComponent.debugElement);
|
||||||
|
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
|
||||||
|
appConfig.config['adf-viewer.pdf-viewer-scaling'] = 10;
|
||||||
|
|
||||||
|
componentUrlTestComponent = fixtureUrlTestComponent.componentInstance;
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
await firstValueFrom(componentUrlTestComponent.pdfViewerComponent.rendered);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fixtureUrlTestComponent.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should init the viewer with annotation mode disabled', async () => {
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.pdfViewer.annotationEditorMode).toBe(AnnotationMode.DISABLE);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should Total number of pages be loaded', fakeAsync(() => {
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
tick(400);
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.totalPages).toBe(6);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should nextPage move to the next page', fakeAsync(() => {
|
||||||
|
testingUtils.clickByCSS('#viewer-next-page-button');
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
tick(400);
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should event RIGHT_ARROW keyboard change pages', fakeAsync(() => {
|
||||||
|
fixtureUrlTestComponent.whenStable();
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
EventMock.keyDown(RIGHT_ARROW);
|
||||||
|
|
||||||
|
tick(250);
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should event LEFT_ARROW keyboard change pages', async () => {
|
||||||
|
componentUrlTestComponent.pdfViewerComponent.inputPage('2');
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
EventMock.keyDown(LEFT_ARROW);
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should previous page move to the previous page', async () => {
|
||||||
|
testingUtils.clickByCSS('#viewer-next-page-button');
|
||||||
|
testingUtils.clickByCSS('#viewer-next-page-button');
|
||||||
|
testingUtils.clickByCSS('#viewer-previous-page-button');
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should previous page not move to the previous page if is page 1', async () => {
|
||||||
|
componentUrlTestComponent.pdfViewerComponent.previousPage();
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should Input page move to the inserted page', async () => {
|
||||||
|
componentUrlTestComponent.pdfViewerComponent.inputPage('2');
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Zoom', () => {
|
||||||
|
it('should zoom in increment the scale value', async () => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||||
|
|
||||||
|
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue;
|
||||||
|
testingUtils.clickByCSS('#viewer-zoom-in-button');
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenRenderingDone();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||||
|
const currentZoom = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue;
|
||||||
|
expect(zoomBefore < currentZoom).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should zoom out decrement the scale value', async () => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||||
|
testingUtils.clickByCSS('#viewer-zoom-in-button');
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
const zoomBefore = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue;
|
||||||
|
|
||||||
|
testingUtils.clickByCSS('#viewer-zoom-out-button');
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenRenderingDone();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||||
|
const currentZoom = componentUrlTestComponent.pdfViewerComponent.pdfViewer.currentScaleValue;
|
||||||
|
expect(zoomBefore > currentZoom).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should it-in button toggle page-fit and auto scale mode', fakeAsync(() => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent.pdfViewer, 'forceRendering').and.callFake(() => {});
|
||||||
|
tick(250);
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('init');
|
||||||
|
testingUtils.clickByCSS('#viewer-scale-page-button');
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit');
|
||||||
|
testingUtils.clickByCSS('#viewer-scale-page-button');
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||||
|
testingUtils.clickByCSS('#viewer-scale-page-button');
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit');
|
||||||
|
}), 300);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Resize interaction', () => {
|
||||||
|
it('should resize event trigger setScaleUpdatePages', async () => {
|
||||||
|
spyOn(componentUrlTestComponent.pdfViewerComponent, 'onResize');
|
||||||
|
EventMock.resizeMobileView();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.onResize).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Thumbnails', () => {
|
||||||
|
it('should have own context', async () => {
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.pdfThumbnailsContext.viewer).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should open thumbnails panel', async () => {
|
||||||
|
expect(testingUtils.getByCSS('.adf-pdf-viewer__thumbnails')).toBeNull();
|
||||||
|
|
||||||
|
componentUrlTestComponent.pdfViewerComponent.toggleThumbnails();
|
||||||
|
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
expect(testingUtils.getByCSS('.adf-pdf-viewer__thumbnails')).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not render PdfThumbListComponent during initialization of new pdfViewer', () => {
|
||||||
|
componentUrlTestComponent.pdfViewerComponent.toggleThumbnails();
|
||||||
|
componentUrlTestComponent.urlFile = 'file.pdf';
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
expect(fixtureUrlTestComponent.debugElement.query(By.directive(PdfThumbListComponent))).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Viewer events', () => {
|
||||||
|
it('should react on the emit of pageChange event', async () => {
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
const args = {
|
||||||
|
pageNumber: 6,
|
||||||
|
source: {
|
||||||
|
container: document.getElementById(`${componentUrlTestComponent.pdfViewerComponent.randomPdfId}-viewer-pdf-viewer`)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* cspell:disable-next-line */
|
||||||
|
componentUrlTestComponent.pdfViewerComponent.pdfViewer.eventBus.dispatch('pagechanging', args);
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(6);
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.page).toBe(6);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should react on the emit of pagesLoaded event', async () => {
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled).toBeFalsy();
|
||||||
|
|
||||||
|
const args = {
|
||||||
|
pagesCount: 10,
|
||||||
|
source: {
|
||||||
|
container: document.getElementById(`${componentUrlTestComponent.pdfViewerComponent.randomPdfId}-viewer-pdf-viewer`)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* cspell:disable-next-line */
|
||||||
|
componentUrlTestComponent.pdfViewerComponent.pdfViewer.eventBus.dispatch('pagesloaded', args);
|
||||||
|
fixtureUrlTestComponent.detectChanges();
|
||||||
|
|
||||||
|
await fixtureUrlTestComponent.whenStable();
|
||||||
|
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@@ -213,7 +213,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
executePdf(pdfOptions: any) {
|
executePdf(pdfOptions: any) {
|
||||||
pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdf.worker.min.js';
|
pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdf.worker.min.mjs';
|
||||||
|
|
||||||
this.loadingTask = pdfjsLib.getDocument(pdfOptions);
|
this.loadingTask = pdfjsLib.getDocument(pdfOptions);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user