mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ADF-2240] fix e2e and test in demo shell (#3035)
* fix e2e and test in demo shell * test single run demo shell conf * fix script e2e * fix test lint problems * remove async from nested test * fix pdf test * modify url load pdf strategy test * SimpleChange import * pdf viewer test fix * remove force closing * refactor pdf viewer -remove promise approach -add event rendered -add destroy worker * increment timeout * use proxy files * remove require * fix viewer component test * remove last require * prefer use of done for txt viewer test
This commit is contained in:
parent
606009cac2
commit
ae489f6737
@ -149,14 +149,6 @@
|
||||
{
|
||||
"project": "src/tsconfig.app.json",
|
||||
"exclude": "**/node_modules/**/*"
|
||||
},
|
||||
{
|
||||
"project": "src/tsconfig.spec.json",
|
||||
"exclude": "**/node_modules/**/*"
|
||||
},
|
||||
{
|
||||
"project": "e2e/tsconfig.e2e.json",
|
||||
"exclude": "**/node_modules/**/*"
|
||||
}
|
||||
],
|
||||
"test": {
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { MyappPage } from './app.po';
|
||||
|
||||
describe('myapp App', () => {
|
||||
let page: MyappPage;
|
||||
let page: MyappPage;
|
||||
|
||||
beforeEach(() => {
|
||||
page = new MyappPage();
|
||||
});
|
||||
beforeEach(() => {
|
||||
page = new MyappPage();
|
||||
});
|
||||
|
||||
it('should display message saying app works', () => {
|
||||
page.navigateTo();
|
||||
expect(page.getParagraphText()).toEqual('app works!');
|
||||
});
|
||||
it('should display toolbar', () => {
|
||||
page.navigateTo();
|
||||
expect(page.getToolbar()).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { browser, element, by } from 'protractor';
|
||||
|
||||
export class MyappPage {
|
||||
navigateTo() {
|
||||
return browser.get('/');
|
||||
}
|
||||
navigateTo() {
|
||||
return browser.get('/');
|
||||
}
|
||||
|
||||
getParagraphText() {
|
||||
return element(by.css('app-root h1')).getText();
|
||||
}
|
||||
getToolbar() {
|
||||
return element(by.tagName('adf-toolbar'));
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
"build:dist": "npm run validate-config && npm run style:dev && npm run server-versions && rimraf dist && node --max_old_space_size=30000 node_modules/.bin/ng build --prod --build-optimizer=false --aot=false --app dist",
|
||||
"style:dev": "npm run webpack -- --config config/webpack.style.js --progress --profile --bail",
|
||||
"copy:dev": "node ./config/dev-copy-watch.js",
|
||||
"test": "ng test",
|
||||
"test": " npm run clean-lib-angular && ng test --single-run",
|
||||
"lint": "ng lint",
|
||||
"e2e": "ng e2e",
|
||||
"validate-config": "ajv validate -s ../lib/core/app-config/schema.json -d ./src/app.config.json --errors=text --verbose",
|
||||
|
@ -1,32 +1,25 @@
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
|
||||
import { AdfModule } from './adf.module';
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
describe('AppComponent', () => {
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
AppComponent
|
||||
],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
RouterTestingModule,
|
||||
AdfModule
|
||||
],
|
||||
declarations: [
|
||||
AppComponent
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
it('should create the app', async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
}));
|
||||
|
||||
it(`should have as title 'app works!'`, async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app.title).toEqual('app works!');
|
||||
}));
|
||||
|
||||
it('should render title in a h1 tag', async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.debugElement.nativeElement;
|
||||
expect(compiled.querySelector('h1').textContent).toContain('app works!');
|
||||
}));
|
||||
it('should create the app', async(() => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
const app = fixture.debugElement.componentInstance;
|
||||
expect(app).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
|
@ -60,6 +60,10 @@ import 'zone.js/dist/zone'; // Included with Angular CLI.
|
||||
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
|
||||
*/
|
||||
import 'intl'; // Run `npm install --save intl`.
|
||||
/**
|
||||
* Need to import at least one locale-data with intl.
|
||||
*/
|
||||
import 'intl/locale-data/jsonp/en';
|
||||
|
||||
/**
|
||||
* Support custom event in IE11
|
||||
|
@ -2,19 +2,41 @@
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "../out-tsc/spec",
|
||||
"module": "commonjs",
|
||||
"target": "es5",
|
||||
"baseUrl": "",
|
||||
"module": "es2015",
|
||||
"rootDir": "..",
|
||||
"baseUrl": ".",
|
||||
"skipLibCheck": false,
|
||||
"types": [
|
||||
"jasmine",
|
||||
"node"
|
||||
]
|
||||
],
|
||||
"paths": {
|
||||
"alfresco-js-api": [
|
||||
"../node_modules/alfresco-js-api/dist/alfresco-js-api.js"
|
||||
],
|
||||
"rxjs/*": [
|
||||
"../node_modules/rxjs/*"
|
||||
],
|
||||
"@angular/*": [
|
||||
"../node_modules/@angular/*"
|
||||
],
|
||||
"@alfresco/adf-core": [
|
||||
"../../lib/core"
|
||||
],
|
||||
"@alfresco/adf-content-services": [
|
||||
"../../lib/content-services"
|
||||
],
|
||||
"@alfresco/adf-process-services": [
|
||||
"../../lib/process-services"
|
||||
],
|
||||
"@alfresco/adf-insights": [
|
||||
"../../lib/insights"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"test.ts"
|
||||
"exclude": [
|
||||
],
|
||||
"include": [
|
||||
"**/*.spec.ts",
|
||||
"**/*.d.ts"
|
||||
]
|
||||
"angularCompilerOptions": {
|
||||
"skipTemplateCodegen": false
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,6 @@
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"typeof-compare": true,
|
||||
"unified-signatures": true,
|
||||
"variable-name": false,
|
||||
"whitespace": [
|
||||
|
@ -44,7 +44,9 @@ module.exports = function (config) {
|
||||
|
||||
{pattern: config.component + '/**/*.ts', included: false, served: true, watched: false},
|
||||
|
||||
{pattern: './config/app.config.json', included: false, served: true, watched: false}
|
||||
{pattern: './config/app.config.json', included: false, served: true, watched: false},
|
||||
{pattern: './core/viewer/assets/fake-test-file.pdf', included: false, served: true, watched: false},
|
||||
{pattern: './core/viewer/assets/fake-test-file.txt', included: false, served: true, watched: false}
|
||||
],
|
||||
|
||||
webpack: (config.mode === 'coverage') ? webpackCoverage(config) : webpackTest(config),
|
||||
@ -59,7 +61,9 @@ module.exports = function (config) {
|
||||
port: 9876,
|
||||
|
||||
proxies: {
|
||||
'/app.config.json': '/base/config/app.config.json'
|
||||
'/app.config.json': '/base/config/app.config.json',
|
||||
'/fake-test-file.pdf': '/base/core/viewer/assets/fake-test-file.pdf',
|
||||
'/fake-test-file.txt': '/base/core/viewer/assets/fake-test-file.txt'
|
||||
},
|
||||
|
||||
// level of logging
|
||||
|
@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* tslint:disable:no-input-rename */
|
||||
/* tslint:disable: no-input-rename no-use-before-declare no-input-rename */
|
||||
|
||||
import { ENTER, ESCAPE } from '@angular/cdk/keycodes';
|
||||
import {
|
||||
|
@ -59,7 +59,7 @@ describe('SearchComponent', () => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should clear results straight away when a new search term is entered', async(() => {
|
||||
it('should clear results straight away when a new search term is entered', (done) => {
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValues(Observable.of(result), Observable.of(differentResult));
|
||||
|
||||
@ -75,11 +75,12 @@ describe('SearchComponent', () => {
|
||||
fixture.detectChanges();
|
||||
optionShowed = element.querySelectorAll('#autocomplete-search-result-list > li').length;
|
||||
expect(optionShowed).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should display the returned search results', async(() => {
|
||||
it('should display the returned search results', (done) => {
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValue(Observable.of(result));
|
||||
|
||||
@ -89,10 +90,11 @@ describe('SearchComponent', () => {
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('#result_option_0').textContent.trim()).toBe('MyDoc');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should emit error event when search call fail', async(() => {
|
||||
it('should emit error event when search call fail', (done) => {
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValue(Observable.fromPromise(Promise.reject({ status: 402 })));
|
||||
component.setSearchWordTo('searchTerm');
|
||||
@ -101,10 +103,11 @@ describe('SearchComponent', () => {
|
||||
fixture.detectChanges();
|
||||
let message: HTMLElement = <HTMLElement> element.querySelector('#component-result-message');
|
||||
expect(message.textContent).toBe('ERROR');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should be able to hide the result panel', async(() => {
|
||||
it('should be able to hide the result panel', (done) => {
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValues(Observable.of(result), Observable.of(differentResult));
|
||||
|
||||
@ -120,9 +123,10 @@ describe('SearchComponent', () => {
|
||||
fixture.detectChanges();
|
||||
let elementList = element.querySelector('#adf-search-results-content');
|
||||
expect(elementList.classList).toContain('adf-search-hide');
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('search node', () => {
|
||||
@ -131,7 +135,7 @@ describe('SearchComponent', () => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should perform a search based on the query node given', async(() => {
|
||||
it('should perform a search based on the query node given', (done) => {
|
||||
spyOn(searchService, 'searchByQueryBody')
|
||||
.and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
|
||||
let fakeSearchNode: QueryBody = {
|
||||
@ -151,10 +155,11 @@ describe('SearchComponent', () => {
|
||||
expect(optionShowed).toBe(1);
|
||||
let folderOption: HTMLElement = <HTMLElement> element.querySelector('#result_option_0');
|
||||
expect(folderOption.textContent.trim()).toBe('MyFolder');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should perform a search with a defaultNode if no searchnode is given', async(() => {
|
||||
it('should perform a search with a defaultNode if no searchnode is given', (done) => {
|
||||
spyOn(searchService, 'search')
|
||||
.and.returnValue(Observable.of(result));
|
||||
component.setSearchWordTo('searchTerm');
|
||||
@ -165,10 +170,11 @@ describe('SearchComponent', () => {
|
||||
expect(optionShowed).toBe(1);
|
||||
let folderOption: HTMLElement = <HTMLElement> element.querySelector('#result_option_0');
|
||||
expect(folderOption.textContent.trim()).toBe('MyDoc');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should perform a search with the searchNode given', async(() => {
|
||||
it('should perform a search with the searchNode given', (done) => {
|
||||
spyOn(searchService, 'searchByQueryBody')
|
||||
.and.callFake((searchObj) => fakeNodeResultSearch(searchObj));
|
||||
let fakeSearchNode: QueryBody = {
|
||||
@ -188,7 +194,8 @@ describe('SearchComponent', () => {
|
||||
expect(optionShowed).toBe(1);
|
||||
let folderOption: HTMLElement = <HTMLElement> element.querySelector('#result_option_0');
|
||||
expect(folderOption.textContent.trim()).toBe('TEST_DOC');
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -18,6 +18,17 @@
|
||||
import { BaseEvent } from '../../../events';
|
||||
import { DataRow } from '../../data/data-row.model';
|
||||
|
||||
export class DataRowActionModel {
|
||||
|
||||
row: DataRow;
|
||||
action: any;
|
||||
|
||||
constructor(row: DataRow, action: any) {
|
||||
this.row = row;
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
||||
export class DataRowActionEvent extends BaseEvent<DataRowActionModel> {
|
||||
|
||||
// backwards compatibility with 1.2.0 and earlier
|
||||
@ -31,14 +42,3 @@ export class DataRowActionEvent extends BaseEvent<DataRowActionModel> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class DataRowActionModel {
|
||||
|
||||
row: DataRow;
|
||||
action: any;
|
||||
|
||||
constructor(row: DataRow, action: any) {
|
||||
this.row = row;
|
||||
this.action = action;
|
||||
}
|
||||
}
|
||||
|
@ -33,29 +33,6 @@ export class BpmProductVersionModel {
|
||||
}
|
||||
}
|
||||
|
||||
export class EcmProductVersionModel {
|
||||
edition: string;
|
||||
version: VersionModel;
|
||||
license: LicenseModel;
|
||||
status: VersionStatusModel;
|
||||
modules: VersionModuleModel[] = [];
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj && obj.entry && obj.entry.repository) {
|
||||
this.edition = obj.entry.repository.edition || null;
|
||||
this.version = new VersionModel(obj.entry.repository.version);
|
||||
this.license = new LicenseModel(obj.entry.repository.license);
|
||||
this.status = new VersionStatusModel(obj.entry.repository.status);
|
||||
if (obj.entry.repository.modules) {
|
||||
obj.entry.repository.modules.forEach((module) => {
|
||||
this.modules.push(new VersionModuleModel(module));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class VersionModel {
|
||||
major: string;
|
||||
minor: string;
|
||||
@ -139,3 +116,26 @@ export class VersionModuleModel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class EcmProductVersionModel {
|
||||
edition: string;
|
||||
version: VersionModel;
|
||||
license: LicenseModel;
|
||||
status: VersionStatusModel;
|
||||
modules: VersionModuleModel[] = [];
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj && obj.entry && obj.entry.repository) {
|
||||
this.edition = obj.entry.repository.edition || null;
|
||||
this.version = new VersionModel(obj.entry.repository.version);
|
||||
this.license = new LicenseModel(obj.entry.repository.license);
|
||||
this.status = new VersionStatusModel(obj.entry.repository.status);
|
||||
if (obj.entry.repository.modules) {
|
||||
obj.entry.repository.modules.forEach((module) => {
|
||||
this.modules.push(new VersionModuleModel(module));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, SimpleChange, ViewChild } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
@ -28,36 +29,48 @@ import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
import { PdfViewerComponent } from './pdfViewer.component';
|
||||
import { PdfThumbListComponent } from './pdfViewer-thumbnails.component';
|
||||
import { PdfThumbComponent } from './pdfViewer-thumb.component';
|
||||
import { RIGHT_ARROW, LEFT_ARROW } from '@angular/cdk/keycodes';
|
||||
|
||||
declare var require: any;
|
||||
@Component({
|
||||
template: `
|
||||
<adf-pdf-viewer [allowThumbnails]="true"
|
||||
[showToolbar]="true"
|
||||
[urlFile]="urlFile">
|
||||
</adf-pdf-viewer>
|
||||
`
|
||||
})
|
||||
class UrlTestComponent {
|
||||
|
||||
describe('Test PdfViewer component', () => {
|
||||
@ViewChild(PdfViewerComponent)
|
||||
pdfViewerComponent: PdfViewerComponent;
|
||||
|
||||
let component: PdfViewerComponent;
|
||||
let fixture: ComponentFixture<PdfViewerComponent>;
|
||||
let element: HTMLElement;
|
||||
urlFile: any;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
ToolbarModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
PdfViewerComponent,
|
||||
PdfThumbListComponent,
|
||||
PdfThumbComponent
|
||||
],
|
||||
providers: [
|
||||
SettingsService,
|
||||
AuthenticationService,
|
||||
AlfrescoApiService,
|
||||
RenderingQueueServices
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
constructor() {
|
||||
this.urlFile = './fake-test-file.pdf';
|
||||
}
|
||||
}
|
||||
|
||||
function createFakeBlob(): Blob {
|
||||
@Component({
|
||||
template: `
|
||||
<adf-pdf-viewer [allowThumbnails]="true"
|
||||
[showToolbar]="true"
|
||||
[blobFile]="blobFile">
|
||||
</adf-pdf-viewer>
|
||||
`
|
||||
})
|
||||
class BlobTestComponent {
|
||||
|
||||
@ViewChild(PdfViewerComponent)
|
||||
pdfViewerComponent: PdfViewerComponent;
|
||||
|
||||
blobFile: any;
|
||||
|
||||
constructor() {
|
||||
this.blobFile = this.createFakeBlob();
|
||||
}
|
||||
|
||||
createFakeBlob(): Blob {
|
||||
let pdfData = atob(
|
||||
'JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' +
|
||||
'IC9QYWdlcyAyIDAgUgo+PgplbmRvYmoKCjIgMCBvYmoKPDwKICAvVHlwZSAvUGFnZXMKICAv' +
|
||||
@ -75,418 +88,408 @@ describe('Test PdfViewer component', () => {
|
||||
return new Blob([pdfData], { type: 'application/pdf' });
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
}
|
||||
|
||||
describe('Test PdfViewer component', () => {
|
||||
|
||||
let component: PdfViewerComponent;
|
||||
let fixture: ComponentFixture<PdfViewerComponent>;
|
||||
let element: HTMLElement;
|
||||
let change: any;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
ToolbarModule,
|
||||
MaterialModule
|
||||
],
|
||||
declarations: [
|
||||
PdfViewerComponent,
|
||||
PdfThumbListComponent,
|
||||
PdfThumbComponent,
|
||||
UrlTestComponent,
|
||||
BlobTestComponent
|
||||
],
|
||||
providers: [
|
||||
SettingsService,
|
||||
AuthenticationService,
|
||||
AlfrescoApiService,
|
||||
RenderingQueueServices
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach((done) => {
|
||||
fixture = TestBed.createComponent(PdfViewerComponent);
|
||||
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
|
||||
component.showToolbar = true;
|
||||
component.inputPage('1');
|
||||
component.currentScale = 1;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should Loader be present', () => {
|
||||
expect(element.querySelector('.loader-container')).not.toBeNull();
|
||||
});
|
||||
|
||||
describe('Required values', () => {
|
||||
it('should thrown an error If urlfile is not present', () => {
|
||||
change = new SimpleChange(null, null, true);
|
||||
|
||||
expect(() => {
|
||||
component.ngOnChanges({ 'urlFile': change });
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
|
||||
it('should If blobFile is not present thrown an error ', () => {
|
||||
change = new SimpleChange(null, null, true);
|
||||
|
||||
expect(() => {
|
||||
component.ngOnChanges({ 'blobFile': change });
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('View with url file', () => {
|
||||
beforeEach(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
|
||||
beforeEach((done) => {
|
||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should thrown an error If urlfile is not present', () => {
|
||||
component.urlFile = undefined;
|
||||
it('should Canvas be present', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('.pdfViewer')).not.toBeNull();
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-pdf-viewer')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
fixture.detectChanges();
|
||||
it('should Next an Previous Buttons be present', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(elementUrlTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
expect(() => {
|
||||
component.ngOnChanges(null);
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
it('should Input Page elements be present', (done) => {
|
||||
|
||||
it('should Canvas be present', () => {
|
||||
expect(element.querySelector('.pdfViewer')).not.toBeNull();
|
||||
expect(element.querySelector('.viewer-pdf-viewer')).not.toBeNull();
|
||||
});
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-pagenumber-input')).toBeDefined();
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-total-pages')).toBeDefined();
|
||||
|
||||
it('should Loader be present', () => {
|
||||
expect(element.querySelector('.loader-container')).not.toBeNull();
|
||||
});
|
||||
expect(elementUrlTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(elementUrlTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should Next an Previous Buttons be present', () => {
|
||||
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should Input Page elements be present', () => {
|
||||
expect(element.querySelector('.viewer-pagenumber-input')).toBeDefined();
|
||||
expect(element.querySelector('.viewer-total-pages')).toBeDefined();
|
||||
|
||||
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should Toolbar be hide if showToolbar is false', () => {
|
||||
it('should Toolbar be hide if showToolbar is false', (done) => {
|
||||
component.showToolbar = false;
|
||||
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.querySelector('.viewer-toolbar-command')).toBeNull();
|
||||
expect(element.querySelector('.viewer-toolbar-pagination')).toBeNull();
|
||||
});
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-toolbar-command')).toBeNull();
|
||||
expect(elementUrlTestComponent.querySelector('.viewer-toolbar-pagination')).toBeNull();
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
describe('View with blob file', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
component.urlFile = undefined;
|
||||
component.blobFile = createFakeBlob();
|
||||
let fixtureBlobTestComponent: ComponentFixture<BlobTestComponent>;
|
||||
let componentBlobTestComponent: BlobTestComponent;
|
||||
let elementBlobTestComponent: HTMLElement;
|
||||
|
||||
fixture.detectChanges();
|
||||
beforeEach((done) => {
|
||||
fixtureBlobTestComponent = TestBed.createComponent(BlobTestComponent);
|
||||
componentBlobTestComponent = fixtureBlobTestComponent.componentInstance;
|
||||
elementBlobTestComponent = fixtureBlobTestComponent.nativeElement;
|
||||
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
componentBlobTestComponent.pdfViewerComponent.rendered.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should If blobFile is not present thrown an error ', () => {
|
||||
component.blobFile = undefined;
|
||||
expect(() => {
|
||||
component.ngOnChanges(null);
|
||||
}).toThrow(new Error('Attribute urlFile or blobFile is required'));
|
||||
});
|
||||
it('should Canvas be present', (done) => {
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
it('should Canvas be present', () => {
|
||||
expect(element.querySelector('.pdfViewer')).not.toBeNull();
|
||||
expect(element.querySelector('.viewer-pdf-viewer')).not.toBeNull();
|
||||
});
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
expect(elementBlobTestComponent.querySelector('.pdfViewer')).not.toBeNull();
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-pdf-viewer')).not.toBeNull();
|
||||
done();
|
||||
};
|
||||
}, 5000);
|
||||
|
||||
it('should Loader be present', () => {
|
||||
expect(element.querySelector('.loader-container')).not.toBeNull();
|
||||
});
|
||||
it('should Next an Previous Buttons be present', (done) => {
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
it('should Next an Previous Buttons be present', () => {
|
||||
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
});
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
expect(elementBlobTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(elementBlobTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
done();
|
||||
};
|
||||
}, 5000);
|
||||
|
||||
it('should Input Page elements be present', () => {
|
||||
expect(element.querySelector('.viewer-pagenumber-input')).toBeDefined();
|
||||
expect(element.querySelector('.viewer-total-pages')).toBeDefined();
|
||||
it('should Input Page elements be present', (done) => {
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
});
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-pagenumber-input')).toBeDefined();
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-total-pages')).toBeDefined();
|
||||
|
||||
it('should Toolbar be hide if showToolbar is false', () => {
|
||||
component.showToolbar = false;
|
||||
expect(elementBlobTestComponent.querySelector('#viewer-previous-page-button')).not.toBeNull();
|
||||
expect(elementBlobTestComponent.querySelector('#viewer-next-page-button')).not.toBeNull();
|
||||
done();
|
||||
};
|
||||
}, 5000);
|
||||
|
||||
fixture.detectChanges();
|
||||
it('should Toolbar be hide if showToolbar is false', (done) => {
|
||||
componentBlobTestComponent.pdfViewerComponent.showToolbar = false;
|
||||
|
||||
expect(element.querySelector('.viewer-toolbar-command')).toBeNull();
|
||||
expect(element.querySelector('.viewer-toolbar-pagination')).toBeNull();
|
||||
});
|
||||
fixtureBlobTestComponent.detectChanges();
|
||||
|
||||
fixtureBlobTestComponent.whenStable().then(() => {
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-toolbar-command')).toBeNull();
|
||||
expect(elementBlobTestComponent.querySelector('.viewer-toolbar-pagination')).toBeNull();
|
||||
done();
|
||||
};
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
describe('User interaction', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
let fixtureUrlTestComponent: ComponentFixture<UrlTestComponent>;
|
||||
let componentUrlTestComponent: UrlTestComponent;
|
||||
let elementUrlTestComponent: HTMLElement;
|
||||
|
||||
beforeEach((done) => {
|
||||
fixtureUrlTestComponent = TestBed.createComponent(UrlTestComponent);
|
||||
componentUrlTestComponent = fixtureUrlTestComponent.componentInstance;
|
||||
elementUrlTestComponent = fixtureUrlTestComponent.nativeElement;
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
componentUrlTestComponent.pdfViewerComponent.rendered.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should Total number of pages be loaded', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.totalPages).toEqual(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
it('should right arrow move to the next page', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.displayPage).toBe(1);
|
||||
EventMock.keyDown(39);
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.totalPages).toBe(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should nextPage move to the next page', (done) => {
|
||||
let nextPageButton: any = element.querySelector('#viewer-next-page-button');
|
||||
let nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
|
||||
nextPageButton.click();
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
nextPageButton.click();
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should event RIGHT_ARROW keyboard change pages', (done) => {
|
||||
EventMock.keyDown(RIGHT_ARROW);
|
||||
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should event keyboard change pages', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
EventMock.keyDown(39);
|
||||
EventMock.keyDown(39);
|
||||
EventMock.keyDown(37);
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should previous page move to the previous page', (done) => {
|
||||
let previousPageButton: any = element.querySelector('#viewer-previous-page-button');
|
||||
let nextPageButton: any = element.querySelector('#viewer-next-page-button');
|
||||
let previousPageButton: any = elementUrlTestComponent.querySelector('#viewer-previous-page-button');
|
||||
let nextPageButton: any = elementUrlTestComponent.querySelector('#viewer-next-page-button');
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
nextPageButton.click();
|
||||
nextPageButton.click();
|
||||
previousPageButton.click();
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
nextPageButton.click();
|
||||
nextPageButton.click();
|
||||
previousPageButton.click();
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should previous page not move to the previous page if is page 1', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.previousPage();
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
component.previousPage();
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(1);
|
||||
done();
|
||||
});
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should Input page move to the inserted page', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
componentUrlTestComponent.pdfViewerComponent.inputPage('2');
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
component.inputPage('2');
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
describe('Zoom', () => {
|
||||
describe('Zoom', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
component.currentScale = 1;
|
||||
});
|
||||
}));
|
||||
it('should zoom in increment the scale value', () => {
|
||||
let zoomInButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-in-button');
|
||||
|
||||
it('should zoom in increment the scale value', (done) => {
|
||||
let zoomInButton: any = element.querySelector('#viewer-zoom-in-button');
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
let zoomBefore = component.currentScale;
|
||||
let zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||
zoomInButton.click();
|
||||
expect(component.currentScaleMode).toBe('auto');
|
||||
let currentZoom = component.currentScale;
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||
let currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||
expect(zoomBefore < currentZoom).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should zoom out decrement the scale value', (done) => {
|
||||
let zoomOutButton: any = element.querySelector('#viewer-zoom-out-button');
|
||||
it('should zoom out decrement the scale value', () => {
|
||||
let zoomOutButton: any = elementUrlTestComponent.querySelector('#viewer-zoom-out-button');
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
let zoomBefore = component.currentScale;
|
||||
let zoomBefore = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||
zoomOutButton.click();
|
||||
expect(component.currentScaleMode).toBe('auto');
|
||||
let currentZoom = component.currentScale;
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||
let currentZoom = componentUrlTestComponent.pdfViewerComponent.currentScale;
|
||||
expect(zoomBefore > currentZoom).toBe(true);
|
||||
done();
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should it-in button toggle page-fit and auto scale mode', () => {
|
||||
let itPage: any = elementUrlTestComponent.querySelector('#viewer-scale-page-button');
|
||||
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||
itPage.click();
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('page-fit');
|
||||
itPage.click();
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.currentScaleMode).toBe('auto');
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
it('should fit-in button toggle page-fit and auto scale mode', (done) => {
|
||||
let fitPage: any = element.querySelector('#viewer-scale-page-button');
|
||||
describe('Resize interaction', () => {
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
expect(component.currentScaleMode).toBe('auto');
|
||||
fitPage.click();
|
||||
expect(component.currentScaleMode).toBe('page-fit');
|
||||
fitPage.click();
|
||||
expect(component.currentScaleMode).toBe('auto');
|
||||
done();
|
||||
});
|
||||
it('should resize event trigger setScaleUpdatePages', () => {
|
||||
spyOn(componentUrlTestComponent.pdfViewerComponent, 'onResize');
|
||||
EventMock.resizeMobileView();
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.onResize).toHaveBeenCalled();
|
||||
}, 5000);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Resize interaction', () => {
|
||||
describe('Thumbnails', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
component.currentScale = 1;
|
||||
});
|
||||
}));
|
||||
it('should have own context', () => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.pdfThumbnailsContext.viewer).not.toBeNull();
|
||||
}, 5000);
|
||||
|
||||
it('should resize event trigger setScaleUpdatePages', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
it('should open thumbnails panel', (done) => {
|
||||
expect(elementUrlTestComponent.querySelector('.adf-pdf-viewer__thumbnails')).toBeNull();
|
||||
|
||||
spyOn(component, 'onResize');
|
||||
EventMock.resizeMobileView();
|
||||
expect(component.onResize).toHaveBeenCalled();
|
||||
componentUrlTestComponent.pdfViewerComponent.toggleThumbnails();
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(elementUrlTestComponent.querySelector('.adf-pdf-viewer__thumbnails')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('scroll interaction', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
component.currentScale = 1;
|
||||
});
|
||||
}));
|
||||
|
||||
it('should scroll page return the current page', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
|
||||
expect(component.displayPage).toBe(1);
|
||||
|
||||
component.inputPage('2');
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(2);
|
||||
|
||||
component.pdfViewer.currentPageNumber = 6;
|
||||
fixture.detectChanges();
|
||||
expect(component.displayPage).toBe(6);
|
||||
expect(component.page).toBe(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Thumbnails', () => {
|
||||
beforeEach(async () => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
component.showThumbnails = false;
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.inputPage('1');
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
it('should have own context', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.pdfThumbnailsContext.viewer).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should open thumbnails panel', (done) => {
|
||||
expect(element.querySelector('.adf-pdf-viewer__thumbnails')).toBeNull();
|
||||
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
component.toggleThumbnails();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(element.querySelector('.adf-pdf-viewer__thumbnails')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Viewer events', () => {
|
||||
beforeEach(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.pdf');
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should emit pagechange event', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
return fixture.whenStable().then(() => {
|
||||
expect(component.displayPage).toBe(1);
|
||||
describe('Viewer events', () => {
|
||||
|
||||
it('should react on the emit of pagechange event', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
const args = {
|
||||
pageNumber: 6,
|
||||
source: {
|
||||
container: component.documentContainer
|
||||
container: componentUrlTestComponent.pdfViewerComponent.documentContainer
|
||||
}
|
||||
};
|
||||
|
||||
component.pdfViewer.eventBus.dispatch('pagechange', args);
|
||||
fixture.detectChanges();
|
||||
componentUrlTestComponent.pdfViewerComponent.pdfViewer.eventBus.dispatch('pagechange', args);
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.displayPage).toBe(6);
|
||||
expect(component.page).toBe(6);
|
||||
done();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.displayPage).toBe(6);
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.page).toBe(6);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
it('should emit pagesloaded event', (done) => {
|
||||
component.ngOnChanges(null).then(() => {
|
||||
fixture.detectChanges();
|
||||
return fixture.whenStable().then(() => {
|
||||
expect(component.isPanelDisabled).toBe(true);
|
||||
it('should react on the emit of pagesloaded event', (done) => {
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled = false;
|
||||
|
||||
const args = {
|
||||
pagesCount: 10,
|
||||
source: {
|
||||
container: component.documentContainer
|
||||
container: componentUrlTestComponent.pdfViewerComponent.documentContainer
|
||||
}
|
||||
};
|
||||
|
||||
component.pdfViewer.eventBus.dispatch('pagesloaded', args);
|
||||
fixture.detectChanges();
|
||||
componentUrlTestComponent.pdfViewerComponent.pdfViewer.eventBus.dispatch('pagesloaded', args);
|
||||
fixtureUrlTestComponent.detectChanges();
|
||||
|
||||
expect(component.isPanelDisabled).toBe(false);
|
||||
done();
|
||||
fixtureUrlTestComponent.whenStable().then(() => {
|
||||
expect(componentUrlTestComponent.pdfViewerComponent.isPanelDisabled).toBe(false);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 5000);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -15,7 +15,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, TemplateRef, HostListener, Input, OnChanges, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
TemplateRef,
|
||||
HostListener,
|
||||
Output,
|
||||
Input,
|
||||
OnChanges,
|
||||
OnDestroy,
|
||||
ViewEncapsulation,
|
||||
EventEmitter
|
||||
} from '@angular/core';
|
||||
import { LogService } from '../../services/log.service';
|
||||
import { RenderingQueueServices } from '../services/rendering-queue.services';
|
||||
|
||||
@ -52,6 +62,13 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
@Input()
|
||||
thumbnailsTemplate: TemplateRef<any> = null;
|
||||
|
||||
@Output()
|
||||
rendered = new EventEmitter<any>();
|
||||
|
||||
@Output()
|
||||
error = new EventEmitter<any>();
|
||||
|
||||
loadingTask: any;
|
||||
currentPdfDocument: any;
|
||||
page: number;
|
||||
displayPage: number;
|
||||
@ -80,37 +97,39 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
// needed to preserve "this" context
|
||||
this.onPageChange = this.onPageChange.bind(this);
|
||||
this.onPagesLoaded = this.onPagesLoaded.bind(this);
|
||||
this.onPagerendered = this.onPagerendered.bind(this);
|
||||
}
|
||||
|
||||
ngOnChanges(changes) {
|
||||
let blobFile = changes['blobFile'];
|
||||
|
||||
if (blobFile && blobFile.currentValue) {
|
||||
let reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
this.executePdf(reader.result);
|
||||
};
|
||||
reader.readAsArrayBuffer(blobFile.currentValue);
|
||||
}
|
||||
|
||||
let urlFile = changes['urlFile'];
|
||||
if (urlFile && urlFile.currentValue) {
|
||||
this.executePdf(urlFile.currentValue);
|
||||
}
|
||||
|
||||
if (!this.urlFile && !this.blobFile) {
|
||||
throw new Error('Attribute urlFile or blobFile is required');
|
||||
}
|
||||
|
||||
if (this.urlFile) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.executePdf(this.urlFile, resolve, reject);
|
||||
});
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
let reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
this.executePdf(reader.result, resolve, reject);
|
||||
};
|
||||
reader.readAsArrayBuffer(this.blobFile);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
executePdf(src, resolve, reject) {
|
||||
let loadingTask = this.getPDFJS().getDocument(src);
|
||||
executePdf(src) {
|
||||
this.loadingTask = this.getPDFJS().getDocument(src);
|
||||
|
||||
loadingTask.onProgress = (progressData) => {
|
||||
this.loadingTask.onProgress = (progressData) => {
|
||||
let level = progressData.loaded / progressData.total;
|
||||
this.loadingPercent = Math.round(level * 100);
|
||||
};
|
||||
|
||||
loadingTask.then((pdfDocument) => {
|
||||
this.loadingTask.then((pdfDocument) => {
|
||||
this.currentPdfDocument = pdfDocument;
|
||||
this.totalPages = pdfDocument.numPages;
|
||||
this.page = 1;
|
||||
@ -119,13 +138,12 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
|
||||
this.currentPdfDocument.getPage(1).then(() => {
|
||||
this.scalePage('auto');
|
||||
resolve();
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
this.error.emit();
|
||||
});
|
||||
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
this.error.emit();
|
||||
});
|
||||
}
|
||||
|
||||
@ -145,6 +163,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
this.documentContainer = document.getElementById('viewer-pdf-viewer');
|
||||
this.documentContainer.addEventListener('pagechange', this.onPageChange, true);
|
||||
this.documentContainer.addEventListener('pagesloaded', this.onPagesLoaded, true);
|
||||
this.documentContainer.addEventListener('textlayerrendered', this.onPagerendered, true);
|
||||
|
||||
this.pdfViewer = new PDFJS.PDFViewer({
|
||||
container: this.documentContainer,
|
||||
@ -163,6 +182,11 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
if (this.documentContainer) {
|
||||
this.documentContainer.removeEventListener('pagechange', this.onPageChange, true);
|
||||
this.documentContainer.removeEventListener('pagesloaded', this.onPagesLoaded, true);
|
||||
this.documentContainer.removeEventListener('textlayerrendered', this.onPagerendered, true);
|
||||
}
|
||||
|
||||
if (this.loadingTask) {
|
||||
this.loadingTask.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,6 +397,13 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
|
||||
this.displayPage = event.pageNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Page Rendered Event
|
||||
*/
|
||||
onPagerendered() {
|
||||
this.rendered.emit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pages Loaded Event
|
||||
*
|
||||
|
@ -24,8 +24,6 @@ import {
|
||||
} from '../../services';
|
||||
import { TxtViewerComponent } from './txtViewer.component';
|
||||
|
||||
declare var require: any;
|
||||
|
||||
describe('Text View component', () => {
|
||||
|
||||
let component: TxtViewerComponent;
|
||||
@ -54,7 +52,7 @@ describe('Text View component', () => {
|
||||
|
||||
it('Should text container be present with urlfile', (done) => {
|
||||
fixture.detectChanges();
|
||||
let urlFile = require('../assets/fake-test-file.txt');
|
||||
let urlFile = './fake-test-file.txt';
|
||||
let change = new SimpleChange(null, urlFile, true);
|
||||
|
||||
component.ngOnChanges({ 'urlFile': change }).then(() => {
|
||||
|
@ -127,8 +127,6 @@ class ViewerWithCustomOpenWithComponent {}
|
||||
})
|
||||
class ViewerWithCustomMoreActionsComponent {}
|
||||
|
||||
declare var require: any;
|
||||
|
||||
describe('ViewerComponent', () => {
|
||||
|
||||
let component: ViewerComponent;
|
||||
@ -593,7 +591,7 @@ describe('ViewerComponent', () => {
|
||||
}));
|
||||
|
||||
it('should extension file txt be loaded', async(() => {
|
||||
component.urlFile = require('../assets/fake-test-file.txt');
|
||||
component.urlFile = 'fake-test-file.txt';
|
||||
component.ngOnChanges(null);
|
||||
fixture.detectChanges();
|
||||
|
||||
@ -678,18 +676,18 @@ describe('ViewerComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should display the txt viewer if the file identified by mimetype is a txt when the filename has wrong extension', async(() => {
|
||||
it('should display the txt viewer if the file identified by mimetype is a txt when the filename has wrong extension', (done) => {
|
||||
component.urlFile = 'content.bin';
|
||||
component.mimeType = 'text/plain';
|
||||
component.urlFile = require('../assets/fake-test-file.txt');
|
||||
fixture.detectChanges();
|
||||
component.ngOnChanges(null);
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('adf-txt-viewer')).not.toBeNull();
|
||||
done();
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should display the media player if the file identified by mimetype is a media when the filename has no extension', async(() => {
|
||||
component.urlFile = 'content';
|
||||
|
@ -57,6 +57,30 @@ export class FilterParamsModel {
|
||||
}
|
||||
}
|
||||
|
||||
export class FilterParamRepresentationModel {
|
||||
processDefinitionId: string;
|
||||
processDefinitionKey: string;
|
||||
name: string;
|
||||
state: string;
|
||||
sort: string;
|
||||
assignment: string;
|
||||
dueAfter: Date;
|
||||
dueBefore: Date;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
this.processDefinitionId = obj.processDefinitionId || null;
|
||||
this.processDefinitionKey = obj.processDefinitionKey || null;
|
||||
this.name = obj.name || null;
|
||||
this.state = obj.state || null;
|
||||
this.sort = obj.sort || null;
|
||||
this.assignment = obj.assignment || null;
|
||||
this.dueAfter = obj.dueAfter || null;
|
||||
this.dueBefore = obj.dueBefore || null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class FilterRepresentationModel implements UserTaskFilterRepresentation {
|
||||
id: number;
|
||||
appId: number;
|
||||
@ -83,30 +107,6 @@ export class FilterRepresentationModel implements UserTaskFilterRepresentation {
|
||||
}
|
||||
}
|
||||
|
||||
export class FilterParamRepresentationModel {
|
||||
processDefinitionId: string;
|
||||
processDefinitionKey: string;
|
||||
name: string;
|
||||
state: string;
|
||||
sort: string;
|
||||
assignment: string;
|
||||
dueAfter: Date;
|
||||
dueBefore: Date;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
this.processDefinitionId = obj.processDefinitionId || null;
|
||||
this.processDefinitionKey = obj.processDefinitionKey || null;
|
||||
this.name = obj.name || null;
|
||||
this.state = obj.state || null;
|
||||
this.sort = obj.sort || null;
|
||||
this.assignment = obj.assignment || null;
|
||||
this.dueAfter = obj.dueAfter || null;
|
||||
this.dueBefore = obj.dueBefore || null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class TaskQueryRequestRepresentationModel implements TaskQueryRequestRepresentation {
|
||||
appDefinitionId: string;
|
||||
processInstanceId: string;
|
||||
|
@ -52,6 +52,7 @@ All the commands before can be used in combination
|
||||
| -u or --update | run the update of the node_modules packages on the demo shell |
|
||||
| -c or --clean | clean the demo shell folder before starting it |
|
||||
| -t or --test | run the tests on the demo-shell |
|
||||
| --e2e | execute e2e test |
|
||||
| -r or --registry | Start the demo using an alternative npm registry |
|
||||
| -v or --version | Use the version defined in the pacakge.json . Download from npm and Install a different version of the lib (this option is not compatible with -dev) |
|
||||
| -si or --skipinstall | skip the install of the node_modules |
|
||||
|
@ -12,6 +12,7 @@ eval EXEC_GIT_NPM_INSTALL_JSAPI=false
|
||||
eval EXEC_VERSION_JSAPI=false
|
||||
eval EXEC_START=true
|
||||
eval EXEC_TEST=false
|
||||
eval EXEC_E2E=false
|
||||
eval JSAPI_VERSION=""
|
||||
eval NG2_COMPONENTS_VERSION=""
|
||||
eval GIT_ISH=""
|
||||
@ -28,6 +29,7 @@ show_help() {
|
||||
echo "-dev or -develop start the demo shell using the relative lib folder to link the components"
|
||||
echo "-dist create the disbuild the demo shell in dist mode"
|
||||
echo "-t or -test execute test"
|
||||
echo "--e2e execute e2e test"
|
||||
echo "-u or -update start the demo shell and update the dependencies"
|
||||
echo "-c or -clean clean the demo shell and reinstall the dependencies"
|
||||
echo "-r or -registry to download the packages from an alternative npm registry example -registry 'http://npm.local.me:8080/' "
|
||||
@ -57,7 +59,11 @@ disable_start() {
|
||||
}
|
||||
|
||||
enable_test() {
|
||||
EXEC_TEST=false
|
||||
EXEC_TEST=true
|
||||
}
|
||||
|
||||
enable_e2e() {
|
||||
EXEC_E2E=true
|
||||
}
|
||||
|
||||
enable_js_api_git_link() {
|
||||
@ -113,6 +119,7 @@ while [[ $1 == -* ]]; do
|
||||
-u|--update) update; shift;;
|
||||
-c|--clean) clean; shift;;
|
||||
-t|--test) enable_test; shift;;
|
||||
--e2e) enable_e2e; shift;;
|
||||
-r|--registry) change_registry $2; shift 2;;
|
||||
-v|--version) version_component $2; shift 2;;
|
||||
-si|--skipinstall) install; shift;;
|
||||
@ -186,8 +193,13 @@ if $EXEC_VERSION_JSAPI == true; then
|
||||
fi
|
||||
|
||||
if $EXEC_TEST == true; then
|
||||
echo "====== Demo shell Test====="
|
||||
npm run test
|
||||
echo "====== Demo shell Test ====="
|
||||
npm install && npm run test
|
||||
fi
|
||||
|
||||
if $EXEC_E2E == true; then
|
||||
echo "====== Demo shell e2e ====="
|
||||
npm run e2e
|
||||
fi
|
||||
|
||||
if $EXEC_START == true; then
|
||||
|
@ -126,7 +126,6 @@
|
||||
"no-string-literal": false,
|
||||
"no-string-throw": true,
|
||||
"prefer-const": false,
|
||||
"typeof-compare": true,
|
||||
"unified-signatures": true,
|
||||
"whitespace": [
|
||||
true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user