Skip to content

Commit

Permalink
test(core): add source unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Aug 21, 2018
1 parent 37254cf commit 24adf87
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/unit/source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import assert from 'assert';
import fs from 'fs';
import Path from 'path';
import Source from '../../src/Source/Source';
import WMTSSource from '../../src/Source/WMTSSource';
import WMSSource from '../../src/Source/WMSSource';
import TMSSource from '../../src/Source/TMSSource';
import fileSource from '../../src/Source/fileSource';
import StaticSource from '../../src/Source/StaticSource';
import Fetcher from '../../src/Provider/Fetcher';

function defer() {
var deferredPromise = {};
deferredPromise.promise = new Promise(function (resolve) {
deferredPromise.resolve = resolve;
});
return deferredPromise;
}

const geojson = defer();

// To load geojson without parse the file content
const urlGeojson = Path.resolve(__dirname, '../data/geojson/holes.geojson.json');
fs.readFile(urlGeojson, 'utf8', function (err, content) {
geojson.resolve(content);
});

global.window = {};

describe('Source', function () {
it('Should instance Source', function () {
const source = new Source({
url: 'http://',
protocol: 'unknow' });
assert.ok(source.protocol);
});
it('Should instance WMTSSource', function () {
const source = new WMTSSource({
url: 'http://',
protocol: 'wmts',
format: 'image/png',
});
assert.ok(source.protocol);
});
it('Should instance WMSSource', function () {
const source = new WMSSource({
url: 'http://',
name: 'name',
protocol: 'wms',
format: 'image/png',
extent: [-90, 90, -45, 45],
projection: 'EPSG:4326',
});
assert.ok(source.protocol);
});
it('Should instance TMSSource', function () {
const source = new TMSSource({
url: 'http://',
protocol: 'tms',
});
assert.ok(source.protocol);
});
it('Should instance FileSource', function () {
Fetcher.text = function () { return geojson.promise; };
const source = new fileSource({
url: '..',
protocol: 'file',
}, 'EPSG:4326');
assert.ok(source.protocol);
});
it('Should instance StaticSource', function () {
Fetcher.json = function () { return Promise.resolve({}); };
const source = new StaticSource({
url: 'http://itowns.org',
protocol: 'file',
extent: [-90, 90, -45, 45],
});
assert.ok(source.protocol);
});
});

0 comments on commit 24adf87

Please sign in to comment.