Files
openlayers/test/spec/ol/imagetile.test.js
Tim Schaub 054af09032 Make code prettier
This updates ESLint and our shared eslint-config-openlayers to use Prettier.  Most formatting changes were automatically applied with this:

    npm run lint -- --fix

A few manual changes were required:

 * In `examples/offscreen-canvas.js`, the `//eslint-disable-line` comment needed to be moved to the appropriate line to disable the error about the `'worker-loader!./offscreen-canvas.worker.js'` import.
 * In `examples/webpack/exapmle-builder.js`, spaces could not be added after a couple `function`s for some reason.  While editing this, I reworked `ExampleBuilder` to be a class.
 * In `src/ol/format/WMSGetFeatureInfo.js`, the `// @ts-ignore` comment needed to be moved down one line so it applied to the `parsersNS` argument.
2020-04-06 12:54:09 -06:00

82 lines
2.7 KiB
JavaScript

import EventType from '../../../src/ol/events/EventType.js';
import ImageTile from '../../../src/ol/ImageTile.js';
import TileState from '../../../src/ol/TileState.js';
import {defaultImageLoadFunction} from '../../../src/ol/source/Image.js';
import {listen, unlistenByKey} from '../../../src/ol/events.js';
describe('ol.ImageTile', function () {
describe('#load()', function () {
it('can load idle tile', function (done) {
const tileCoord = [0, 0, 0];
const state = TileState.IDLE;
const src = 'spec/ol/data/osm-0-0-0.png';
const tileLoadFunction = defaultImageLoadFunction;
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
let previousState = tile.getState();
listen(tile, EventType.CHANGE, function (event) {
const state = tile.getState();
if (previousState == TileState.IDLE) {
expect(state).to.be(TileState.LOADING);
} else if (previousState == TileState.LOADING) {
expect(state).to.be(TileState.LOADED);
done();
} else {
expect().fail();
}
previousState = state;
});
tile.load();
});
it('can load error tile', function (done) {
const tileCoord = [0, 0, 0];
const state = TileState.ERROR;
const src = 'spec/ol/data/osm-0-0-0.png';
const tileLoadFunction = defaultImageLoadFunction;
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
let previousState = tile.getState();
listen(tile, EventType.CHANGE, function (event) {
const state = tile.getState();
if (previousState == TileState.ERROR) {
expect(state).to.be(TileState.LOADING);
} else if (previousState == TileState.LOADING) {
expect(state).to.be(TileState.LOADED);
done();
} else {
expect().fail();
}
previousState = state;
});
tile.load();
});
it('loads an empty image on error ', function (done) {
const tileCoord = [0, 0, 0];
const state = TileState.IDLE;
const src = 'spec/ol/data/osm-0-0-99.png';
const tileLoadFunction = defaultImageLoadFunction;
const tile = new ImageTile(tileCoord, state, src, null, tileLoadFunction);
const key = listen(tile, EventType.CHANGE, function (event) {
const state = tile.getState();
if (state == TileState.ERROR) {
expect(state).to.be(TileState.ERROR);
expect(tile.image_).to.be.a(HTMLCanvasElement);
unlistenByKey(key);
tile.load();
expect(tile.image_).to.be.a(HTMLImageElement);
done();
}
});
tile.load();
});
});
});