Move the XRefMock in the unit tests to a central location

This patch helps to avoid code duplication for this mock since more unit
tests are depending on it.
This commit is contained in:
Tim van der Meij 2017-07-29 00:35:10 +02:00
parent 783d42ec2b
commit ab820438ae
No known key found for this signature in database
GPG key ID: 8C3FD2925A5F2762
5 changed files with 39 additions and 80 deletions

View file

@ -14,6 +14,7 @@
*/
import { CMapCompressionType, isNodeJS } from '../../src/shared/util';
import { isRef } from '../../src/core/primitives';
class NodeFileReaderFactory {
static fetch(params) {
@ -74,9 +75,40 @@ class NodeCMapReaderFactory {
}
}
class XRefMock {
constructor(array) {
this._map = Object.create(null);
for (let key in array) {
let obj = array[key];
this._map[obj.ref.toString()] = obj.data;
}
}
fetch(ref) {
return this._map[ref.toString()];
}
fetchAsync(ref) {
return Promise.resolve(this.fetch(ref));
}
fetchIfRef(obj) {
if (!isRef(obj)) {
return obj;
}
return this.fetch(obj);
}
fetchIfRefAsync(obj) {
return Promise.resolve(this.fetchIfRef(obj));
}
}
export {
NodeFileReaderFactory,
NodeCMapReaderFactory,
XRefMock,
buildGetDocumentParams,
TEST_PDFS_PATH,
};