Skip to content

Commit

Permalink
test(source): cleanUp
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Oct 25, 2024
1 parent 755b70e commit f397804
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 38 deletions.
35 changes: 10 additions & 25 deletions src/Source/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,7 @@ export const supportedParsers = new Map([

const noCache = { get: () => {}, set: a => a, clear: () => {} };

/**
* @property {string} crs - data crs projection.
* @property {boolean} isInverted - This option is to be set to the
* correct value, true or false (default being false), if the computation of
* the coordinates needs to be inverted to same scheme as OSM, Google Maps
* or other system. See [this link](
* https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates)
* for more informations.
*
*/
class InformationsData {
constructor(options) {
/* istanbul ignore next */
if (options.projection) {
console.warn('Source projection parameter is deprecated, use crs instead.');
options.crs = options.crs || options.projection;
}
if (options.crs) {
CRS.isValid(options.crs);
}
this.crs = options.crs;
}
}

/**
* This interface describes parsing options.
* @typedef {Object} ParsingOptions
Expand Down Expand Up @@ -100,13 +78,20 @@ let uid = 0;
* depending on the current fetched tile for example</li>
* </ul>
*/
class Source extends InformationsData {
class Source {
/**
* @param {Object} source - An object that can contain all properties of a
* Source. Only the `url` property is mandatory.
*/
constructor(source) {
super(source);
if (source.projection) {
console.warn('Source projection parameter is deprecated, use crs instead.');
source.crs = source.crs || source.projection;
}
if (source.crs) {
CRS.isValid(source.crs);
}
this.crs = source.crs;
this.isSource = true;

if (!source.url) {
Expand Down
39 changes: 26 additions & 13 deletions test/unit/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,41 @@ import fileSource from '../data/filesource/featCollec_Polygone.geojson';
const tileset = {};

describe('Sources', function () {
const vendorSpecific = {
buffer: 4096,
format_options: 'dpi:300;quantizer:octree',
tiled: true,
};

describe('Source', function () {
const paramsSource = {
url: 'http://',
};

it('should instance and throw error for Source', function () {
const source = new Source(paramsSource);
assert.throws(source.urlFromExtent, Error);
assert.throws(source.extentInsideLimit, Error);
});
describe('Instancing of a Source', function () {
let source;
it('should throw an error for having no url', function () {
assert.throws(() => new Source({}), Error);
});
it('should succeed', function () {
source = new Source(paramsSource);
assert.ok(source.isSource);
});
it('testing deprecated options', function () {
paramsSource.projection = 'EPSG:4326';
source = new Source(paramsSource);
assert.ok(source.isSource);
assert.equal(source.crs, paramsSource.projection);
});

it('should throw an error for having no url', function () {
assert.throws(() => new Source({}), Error);
it('testing abstract methods', function () {
const source = new Source(paramsSource);
assert.throws(source.urlFromExtent, Error);
assert.throws(source.extentInsideLimit, Error);
});
});
});

const vendorSpecific = {
buffer: 4096,
format_options: 'dpi:300;quantizer:octree',
tiled: true,
};

describe('WFSSource', function () {
const paramsWFS = {
url: 'http://domain.com',
Expand Down

0 comments on commit f397804

Please sign in to comment.