In test/unit/api_spec.js rename the function waitsForPromise
to waitsForPromiseResolved
and add a waitsForPromiseRejected
function
This commit is contained in:
parent
2701edc7c6
commit
6077e93275
@ -8,7 +8,7 @@
|
|||||||
describe('api', function() {
|
describe('api', function() {
|
||||||
// TODO run with worker enabled
|
// TODO run with worker enabled
|
||||||
var basicApiUrl = combineUrl(window.location.href, '../pdfs/basicapi.pdf');
|
var basicApiUrl = combineUrl(window.location.href, '../pdfs/basicapi.pdf');
|
||||||
function waitsForPromise(promise, successCallback) {
|
function waitsForPromiseResolved(promise, successCallback) {
|
||||||
var data;
|
var data;
|
||||||
promise.then(function(val) {
|
promise.then(function(val) {
|
||||||
data = val;
|
data = val;
|
||||||
@ -22,11 +22,25 @@ describe('api', function() {
|
|||||||
return data !== undefined;
|
return data !== undefined;
|
||||||
}, 20000);
|
}, 20000);
|
||||||
}
|
}
|
||||||
|
function waitsForPromiseRejected(promise, failureCallback) {
|
||||||
|
var data;
|
||||||
|
promise.then(function(val) {
|
||||||
|
// Shouldn't get here.
|
||||||
|
expect(false).toEqual(true);
|
||||||
|
},
|
||||||
|
function(error) {
|
||||||
|
data = error;
|
||||||
|
failureCallback(data);
|
||||||
|
});
|
||||||
|
waitsFor(function() {
|
||||||
|
return data !== undefined;
|
||||||
|
}, 20000);
|
||||||
|
}
|
||||||
describe('PDFJS', function() {
|
describe('PDFJS', function() {
|
||||||
describe('getDocument', function() {
|
describe('getDocument', function() {
|
||||||
it('creates pdf doc from URL', function() {
|
it('creates pdf doc from URL', function() {
|
||||||
var promise = PDFJS.getDocument(basicApiUrl);
|
var promise = PDFJS.getDocument(basicApiUrl);
|
||||||
waitsForPromise(promise, function(data) {
|
waitsForPromiseResolved(promise, function(data) {
|
||||||
expect(true).toEqual(true);
|
expect(true).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -61,7 +75,7 @@ describe('api', function() {
|
|||||||
expect(typedArrayPdf.length).toEqual(105779);
|
expect(typedArrayPdf.length).toEqual(105779);
|
||||||
|
|
||||||
var promise = PDFJS.getDocument(typedArrayPdf);
|
var promise = PDFJS.getDocument(typedArrayPdf);
|
||||||
waitsForPromise(promise, function(data) {
|
waitsForPromiseResolved(promise, function(data) {
|
||||||
expect(true).toEqual(true);
|
expect(true).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -70,7 +84,7 @@ describe('api', function() {
|
|||||||
describe('PDFDocument', function() {
|
describe('PDFDocument', function() {
|
||||||
var promise = PDFJS.getDocument(basicApiUrl);
|
var promise = PDFJS.getDocument(basicApiUrl);
|
||||||
var doc;
|
var doc;
|
||||||
waitsForPromise(promise, function(data) {
|
waitsForPromiseResolved(promise, function(data) {
|
||||||
doc = data;
|
doc = data;
|
||||||
});
|
});
|
||||||
it('gets number of pages', function() {
|
it('gets number of pages', function() {
|
||||||
@ -81,7 +95,7 @@ describe('api', function() {
|
|||||||
});
|
});
|
||||||
it('gets page', function() {
|
it('gets page', function() {
|
||||||
var promise = doc.getPage(1);
|
var promise = doc.getPage(1);
|
||||||
waitsForPromise(promise, function(data) {
|
waitsForPromiseResolved(promise, function(data) {
|
||||||
expect(true).toEqual(true);
|
expect(true).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -89,32 +103,32 @@ describe('api', function() {
|
|||||||
// reference to second page
|
// reference to second page
|
||||||
var ref = {num: 17, gen: 0};
|
var ref = {num: 17, gen: 0};
|
||||||
var promise = doc.getPageIndex(ref);
|
var promise = doc.getPageIndex(ref);
|
||||||
waitsForPromise(promise, function(pageIndex) {
|
waitsForPromiseResolved(promise, function(pageIndex) {
|
||||||
expect(pageIndex).toEqual(1);
|
expect(pageIndex).toEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('gets destinations', function() {
|
it('gets destinations', function() {
|
||||||
var promise = doc.getDestinations();
|
var promise = doc.getDestinations();
|
||||||
waitsForPromise(promise, function(data) {
|
waitsForPromiseResolved(promise, function(data) {
|
||||||
expect(data).toEqual({ chapter1: [{ gen: 0, num: 17 }, { name: 'XYZ' },
|
expect(data).toEqual({ chapter1: [{ gen: 0, num: 17 }, { name: 'XYZ' },
|
||||||
0, 841.89, null] });
|
0, 841.89, null] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('gets attachments', function() {
|
it('gets attachments', function() {
|
||||||
var promise = doc.getAttachments();
|
var promise = doc.getAttachments();
|
||||||
waitsForPromise(promise, function (data) {
|
waitsForPromiseResolved(promise, function (data) {
|
||||||
expect(data).toEqual(null);
|
expect(data).toEqual(null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('gets javascript', function() {
|
it('gets javascript', function() {
|
||||||
var promise = doc.getJavaScript();
|
var promise = doc.getJavaScript();
|
||||||
waitsForPromise(promise, function (data) {
|
waitsForPromiseResolved(promise, function (data) {
|
||||||
expect(data).toEqual([]);
|
expect(data).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('gets outline', function() {
|
it('gets outline', function() {
|
||||||
var promise = doc.getOutline();
|
var promise = doc.getOutline();
|
||||||
waitsForPromise(promise, function(outline) {
|
waitsForPromiseResolved(promise, function(outline) {
|
||||||
// Two top level entries.
|
// Two top level entries.
|
||||||
expect(outline.length).toEqual(2);
|
expect(outline.length).toEqual(2);
|
||||||
// Make sure some basic attributes are set.
|
// Make sure some basic attributes are set.
|
||||||
@ -125,26 +139,26 @@ describe('api', function() {
|
|||||||
});
|
});
|
||||||
it('gets metadata', function() {
|
it('gets metadata', function() {
|
||||||
var promise = doc.getMetadata();
|
var promise = doc.getMetadata();
|
||||||
waitsForPromise(promise, function(metadata) {
|
waitsForPromiseResolved(promise, function(metadata) {
|
||||||
expect(metadata.info['Title']).toEqual('Basic API Test');
|
expect(metadata.info['Title']).toEqual('Basic API Test');
|
||||||
expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test');
|
expect(metadata.metadata.get('dc:title')).toEqual('Basic API Test');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('gets data', function() {
|
it('gets data', function() {
|
||||||
var promise = doc.getData();
|
var promise = doc.getData();
|
||||||
waitsForPromise(promise, function (data) {
|
waitsForPromiseResolved(promise, function (data) {
|
||||||
expect(true).toEqual(true);
|
expect(true).toEqual(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('gets filesize in bytes', function() {
|
it('gets filesize in bytes', function() {
|
||||||
var promise = doc.getDownloadInfo();
|
var promise = doc.getDownloadInfo();
|
||||||
waitsForPromise(promise, function (data) {
|
waitsForPromiseResolved(promise, function (data) {
|
||||||
expect(data.length).toEqual(105779);
|
expect(data.length).toEqual(105779);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('gets stats', function() {
|
it('gets stats', function() {
|
||||||
var promise = doc.getStats();
|
var promise = doc.getStats();
|
||||||
waitsForPromise(promise, function (stats) {
|
waitsForPromiseResolved(promise, function (stats) {
|
||||||
expect(isArray(stats.streamTypes)).toEqual(true);
|
expect(isArray(stats.streamTypes)).toEqual(true);
|
||||||
expect(isArray(stats.fontTypes)).toEqual(true);
|
expect(isArray(stats.fontTypes)).toEqual(true);
|
||||||
});
|
});
|
||||||
@ -161,7 +175,7 @@ describe('api', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
var page;
|
var page;
|
||||||
waitsForPromise(promise, function(data) {
|
waitsForPromiseResolved(promise, function(data) {
|
||||||
page = data;
|
page = data;
|
||||||
});
|
});
|
||||||
it('gets page number', function () {
|
it('gets page number', function () {
|
||||||
@ -187,13 +201,13 @@ describe('api', function() {
|
|||||||
});
|
});
|
||||||
it('gets annotations', function () {
|
it('gets annotations', function () {
|
||||||
var promise = page.getAnnotations();
|
var promise = page.getAnnotations();
|
||||||
waitsForPromise(promise, function (data) {
|
waitsForPromiseResolved(promise, function (data) {
|
||||||
expect(data.length).toEqual(4);
|
expect(data.length).toEqual(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('gets text content', function () {
|
it('gets text content', function () {
|
||||||
var promise = page.getTextContent();
|
var promise = page.getTextContent();
|
||||||
waitsForPromise(promise, function (data) {
|
waitsForPromiseResolved(promise, function (data) {
|
||||||
expect(!!data.items).toEqual(true);
|
expect(!!data.items).toEqual(true);
|
||||||
expect(data.items.length).toEqual(7);
|
expect(data.items.length).toEqual(7);
|
||||||
expect(!!data.styles).toEqual(true);
|
expect(!!data.styles).toEqual(true);
|
||||||
@ -201,7 +215,7 @@ describe('api', function() {
|
|||||||
});
|
});
|
||||||
it('gets operator list', function() {
|
it('gets operator list', function() {
|
||||||
var promise = page.getOperatorList();
|
var promise = page.getOperatorList();
|
||||||
waitsForPromise(promise, function (oplist) {
|
waitsForPromiseResolved(promise, function (oplist) {
|
||||||
expect(!!oplist.fnArray).toEqual(true);
|
expect(!!oplist.fnArray).toEqual(true);
|
||||||
expect(!!oplist.argsArray).toEqual(true);
|
expect(!!oplist.argsArray).toEqual(true);
|
||||||
expect(oplist.lastChunk).toEqual(true);
|
expect(oplist.lastChunk).toEqual(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user