Upgrade Viewer to angular 2.0.0-rc.1

This commit is contained in:
Denys Vuika
2016-06-14 11:31:53 +01:00
parent 2428396ab6
commit a81378bcda
14 changed files with 546 additions and 511 deletions

View File

@@ -15,163 +15,172 @@
* limitations under the License.
*/
import { describe, expect, it, injectAsync, TestComponentBuilder, setBaseTestProviders } from 'angular2/testing';
import { TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS } from 'angular2/platform/testing/browser';
import { PdfViewerComponent } from './pdfViewer.component';
import { PDFJSmock } from './assets/PDFJS.mock';
import { PDFViewermock } from './assets/PDFViewer.mock';
import { describe, it, expect } from '@angular/core/testing';
describe('PdfViewer', () => {
setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
describe('View', () => {
it('Canvas should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PdfViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
fixture.detectChanges();
expect(element.querySelector('#viewer-viewerPdf')).not.toBeNull();
expect(element.querySelector('#viewer-pdf-container')).not.toBeNull();
});
}));
it('Loader should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PdfViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
fixture.detectChanges();
expect(element.querySelector('#viewer-loader')).not.toBeNull();
});
}));
it('Next an Previous Buttons should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PdfViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
fixture.detectChanges();
expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
});
}));
it('Input Page elements should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PdfViewerComponent)
.then((fixture) => {
let element = fixture.nativeElement;
fixture.detectChanges();
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();
});
}));
});
describe('User interaction', () => {
it('Total number of pages should be loaded', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PdfViewerComponent)
.then((fixture) => {
let component = fixture.componentInstance;
component.urlFile = 'fake-url-file';
spyOn(component, 'getPDFJS').and.returnValue(new PDFJSmock());
spyOn(component, 'initPDFViewer').and.callFake(() => {
component.pdfViewer = new PDFViewermock();
});
component.ngOnChanges().then(() => {
expect(component.totalPages).toEqual('10');
});
});
}));
it('nextPage should move to the next page', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PdfViewerComponent)
.then((fixture) => {
let component = fixture.componentInstance;
spyOn(component, 'getPDFJS').and.returnValue(new PDFJSmock());
spyOn(component, 'initPDFViewer').and.callFake(() => {
component.pdfViewer = new PDFViewermock();
});
component.urlFile = 'fake-url-file';
component.ngOnChanges().then(() => {
fixture.detectChanges();
expect(component.displayPage).toBe(1);
component.nextPage();
fixture.detectChanges();
expect(component.displayPage).toBe(2);
}).catch((error) => {
expect(error).toBeUndefined();
});
});
}));
it('previous page should move to the previous page', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PdfViewerComponent)
.then((fixture) => {
let component = fixture.componentInstance;
spyOn(component, 'getPDFJS').and.returnValue(new PDFJSmock());
spyOn(component, 'initPDFViewer').and.callFake(() => {
component.pdfViewer = new PDFViewermock();
});
component.urlFile = 'fake-url-file';
component.ngOnChanges().then(() => {
fixture.detectChanges();
expect(component.displayPage).toBe(1);
component.nextPage();
component.nextPage();
component.previousPage();
fixture.detectChanges();
expect(component.displayPage).toBe(2);
}).catch((error) => {
expect(error).toBeUndefined();
});
});
}));
/* tslint:disable:max-line-length */
it('previous page should not move to the previous page if is page 1', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
return tcb
.createAsync(PdfViewerComponent)
.then((fixture) => {
let component = fixture.componentInstance;
spyOn(component, 'getPDFJS').and.returnValue(new PDFJSmock());
spyOn(component, 'initPDFViewer').and.callFake(() => {
component.pdfViewer = new PDFViewermock();
});
component.urlFile = 'fake-url-file';
component.ngOnChanges().then(() => {
fixture.detectChanges();
expect(component.displayPage).toBe(1);
component.previousPage();
fixture.detectChanges();
expect(component.displayPage).toBe(1);
}).catch((error) => {
expect(error).toBeUndefined();
});
});
}));
it ('should be migrated to angular 2 rc.1', () => {
expect(false).toBe(true);
});
});
/* tslint:disable:max-line-length */
// import { describe, expect, it, injectAsync, TestComponentBuilder, setBaseTestProviders } from 'angular2/testing';
// import { TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS } from 'angular2/platform/testing/browser';
// import { PdfViewerComponent } from './pdfViewer.component';
// import { PDFJSmock } from './assets/PDFJS.mock';
// import { PDFViewermock } from './assets/PDFViewer.mock';
//
// describe('PdfViewer', () => {
// setBaseTestProviders(TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS);
//
// describe('View', () => {
// it('Canvas should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
// return tcb
// .createAsync(PdfViewerComponent)
// .then((fixture) => {
// let element = fixture.nativeElement;
//
// fixture.detectChanges();
//
// expect(element.querySelector('#viewer-viewerPdf')).not.toBeNull();
// expect(element.querySelector('#viewer-pdf-container')).not.toBeNull();
// });
// }));
//
// it('Loader should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
// return tcb
// .createAsync(PdfViewerComponent)
// .then((fixture) => {
// let element = fixture.nativeElement;
//
// fixture.detectChanges();
//
// expect(element.querySelector('#viewer-loader')).not.toBeNull();
// });
// }));
//
//
// it('Next an Previous Buttons should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
// return tcb
// .createAsync(PdfViewerComponent)
// .then((fixture) => {
// let element = fixture.nativeElement;
//
// fixture.detectChanges();
//
// expect(element.querySelector('#viewer-previous-page-button')).not.toBeNull();
// expect(element.querySelector('#viewer-next-page-button')).not.toBeNull();
// });
// }));
//
// it('Input Page elements should be present', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
// return tcb
// .createAsync(PdfViewerComponent)
// .then((fixture) => {
// let element = fixture.nativeElement;
//
// fixture.detectChanges();
//
// 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();
// });
// }));
// });
//
// describe('User interaction', () => {
// it('Total number of pages should be loaded', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
// return tcb
// .createAsync(PdfViewerComponent)
// .then((fixture) => {
// let component = fixture.componentInstance;
// component.urlFile = 'fake-url-file';
// spyOn(component, 'getPDFJS').and.returnValue(new PDFJSmock());
// spyOn(component, 'initPDFViewer').and.callFake(() => {
// component.pdfViewer = new PDFViewermock();
// });
//
// component.ngOnChanges().then(() => {
// expect(component.totalPages).toEqual('10');
// });
// });
// }));
//
// it('nextPage should move to the next page', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
// return tcb
// .createAsync(PdfViewerComponent)
// .then((fixture) => {
// let component = fixture.componentInstance;
// spyOn(component, 'getPDFJS').and.returnValue(new PDFJSmock());
// spyOn(component, 'initPDFViewer').and.callFake(() => {
// component.pdfViewer = new PDFViewermock();
// });
//
// component.urlFile = 'fake-url-file';
//
// component.ngOnChanges().then(() => {
// fixture.detectChanges();
// expect(component.displayPage).toBe(1);
// component.nextPage();
// fixture.detectChanges();
// expect(component.displayPage).toBe(2);
// }).catch((error) => {
// expect(error).toBeUndefined();
// });
// });
// }));
//
// it('previous page should move to the previous page', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
// return tcb
// .createAsync(PdfViewerComponent)
// .then((fixture) => {
// let component = fixture.componentInstance;
// spyOn(component, 'getPDFJS').and.returnValue(new PDFJSmock());
// spyOn(component, 'initPDFViewer').and.callFake(() => {
// component.pdfViewer = new PDFViewermock();
// });
//
// component.urlFile = 'fake-url-file';
//
// component.ngOnChanges().then(() => {
// fixture.detectChanges();
// expect(component.displayPage).toBe(1);
// component.nextPage();
// component.nextPage();
// component.previousPage();
// fixture.detectChanges();
// expect(component.displayPage).toBe(2);
// }).catch((error) => {
// expect(error).toBeUndefined();
// });
// });
// }));
//
// /* tslint:disable:max-line-length */
// it('previous page should not move to the previous page if is page 1', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
// return tcb
// .createAsync(PdfViewerComponent)
// .then((fixture) => {
// let component = fixture.componentInstance;
// spyOn(component, 'getPDFJS').and.returnValue(new PDFJSmock());
// spyOn(component, 'initPDFViewer').and.callFake(() => {
// component.pdfViewer = new PDFViewermock();
// });
//
// component.urlFile = 'fake-url-file';
//
// component.ngOnChanges().then(() => {
// fixture.detectChanges();
// expect(component.displayPage).toBe(1);
// component.previousPage();
// fixture.detectChanges();
// expect(component.displayPage).toBe(1);
// }).catch((error) => {
// expect(error).toBeUndefined();
// });
// });
// }));
// });
// });