Add more tests
This commit is contained in:
42
test/browser/spec/ol/source/datatile.test.js
Normal file
42
test/browser/spec/ol/source/datatile.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import DataTile from '../../../../../src/ol/DataTile.js';
|
||||
import DataTileSource from '../../../../../src/ol/source/DataTile.js';
|
||||
import TileState from '../../../../../src/ol/TileState.js';
|
||||
|
||||
describe('ol.source.DataTile', function () {
|
||||
/** @type {DataTileSource} */
|
||||
let source;
|
||||
beforeEach(function () {
|
||||
const loader = function (z, x, y) {
|
||||
return new Promise((resolve) => {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 256;
|
||||
canvas.height = 256;
|
||||
const context = canvas.getContext('2d');
|
||||
// encode tile coordinate in rgb
|
||||
context.fillStyle = `rgb(${z}, ${x % 255}, ${y % 255})`;
|
||||
context.fillRect(0, 0, 256, 256);
|
||||
resolve(context.getImageData(0, 0, 256, 256).data);
|
||||
});
|
||||
};
|
||||
source = new DataTileSource({
|
||||
loader: loader,
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTile()', function () {
|
||||
it('gets tiles and fires a tileloadend event', function (done) {
|
||||
const tile = source.getTile(3, 2, 1);
|
||||
expect(tile).to.be.a(DataTile);
|
||||
expect(tile.state).to.be(TileState.IDLE);
|
||||
|
||||
source.on('tileloadend', () => {
|
||||
expect(tile.state).to.be(TileState.LOADED);
|
||||
// decode tile coordinate from rgb
|
||||
expect(Array.from(tile.getData().slice(0, 3))).to.eql([3, 2, 1]);
|
||||
done();
|
||||
});
|
||||
|
||||
tile.load();
|
||||
});
|
||||
});
|
||||
});
|
||||
45
test/browser/spec/ol/source/geotiff.test.js
Normal file
45
test/browser/spec/ol/source/geotiff.test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import GeoTIFFSource from '../../../../../src/ol/source/GeoTIFF.js';
|
||||
import State from '../../../../../src/ol/source/State.js';
|
||||
import TileState from '../../../../../src/ol/TileState.js';
|
||||
|
||||
describe('ol.source.GeoTIFF', function () {
|
||||
/** @type {GeoTIFFSource} */
|
||||
let source;
|
||||
beforeEach(function () {
|
||||
source = new GeoTIFFSource({
|
||||
sources: [
|
||||
{
|
||||
url: 'spec/ol/source/images/0-0-0.tif',
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('manages load states', function (done) {
|
||||
expect(source.getState()).to.be(State.LOADING);
|
||||
source.on('change', () => {
|
||||
expect(source.getState()).to.be(State.READY);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('configures itself from source metadata', function (done) {
|
||||
source.on('change', () => {
|
||||
expect(source.bandCount).to.be(3);
|
||||
expect(source.getTileGrid().getResolutions().length).to.be(1);
|
||||
expect(source.projection.getCode()).to.be('EPSG:4326');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('loads tiles', function (done) {
|
||||
source.on('change', () => {
|
||||
const tile = source.getTile(0, 0, 0);
|
||||
source.on('tileloadend', () => {
|
||||
expect(tile.getState()).to.be(TileState.LOADED);
|
||||
done();
|
||||
});
|
||||
tile.load();
|
||||
});
|
||||
});
|
||||
});
|
||||
BIN
test/browser/spec/ol/source/images/0-0-0.tif
Normal file
BIN
test/browser/spec/ol/source/images/0-0-0.tif
Normal file
Binary file not shown.
Reference in New Issue
Block a user