diff --git a/test/unit/source.js b/test/unit/source.js new file mode 100644 index 0000000000..bef4e767c8 --- /dev/null +++ b/test/unit/source.js @@ -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); + }); +});