Files
openlayers/test/spec/ol/render/box.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

74 lines
2.3 KiB
JavaScript

import Disposable from '../../../../src/ol/Disposable.js';
import Map from '../../../../src/ol/Map.js';
import Polygon from '../../../../src/ol/geom/Polygon.js';
import RenderBox from '../../../../src/ol/render/Box.js';
import View from '../../../../src/ol/View.js';
describe('ol.render.Box', function () {
let box, map, target;
beforeEach(function () {
box = new RenderBox('test-box');
target = document.createElement('div');
target.style.height = '256px';
document.body.appendChild(target);
map = new Map({
target: target,
view: new View({
center: [0, 0],
zoom: 0,
}),
});
map.renderSync();
box.setMap(map);
});
afterEach(function () {
map.dispose();
document.body.removeChild(target);
});
describe('constructor', function () {
it('creates an instance', function () {
const obj = new RenderBox('test-box');
expect(obj).to.be.a(RenderBox);
expect(obj).to.be.a(Disposable);
obj.dispose();
});
it('creates an absolutely positioned DIV with a className', function () {
expect(box.element_).to.be.a(HTMLDivElement);
expect(box.element_.style.position).to.be('absolute');
expect(box.element_.className).to.be('ol-box test-box');
expect(box.element_.style.position).to.be('absolute');
});
it("appends the DIV to the map's overlay container", function () {
expect(box.element_.parentNode).to.equal(map.getOverlayContainer());
});
});
describe('#setPixels()', function () {
it('applies correct styles for a box', function () {
box.setPixels([1, 2], [4, 8]);
expect(box.element_.style.left).to.be('1px');
expect(box.element_.style.top).to.be('2px');
expect(box.element_.style.width).to.be('3px');
expect(box.element_.style.height).to.be('6px');
});
it('applies correct styles for a flipped box', function () {
box.setPixels([4, 8], [1, 2]);
expect(box.element_.style.left).to.be('1px');
expect(box.element_.style.top).to.be('2px');
expect(box.element_.style.width).to.be('3px');
expect(box.element_.style.height).to.be('6px');
});
it('creates a polygon geometry', function () {
expect(box.getGeometry()).to.be(null);
box.setPixels([1, 2], [3, 4]);
expect(box.getGeometry()).to.be.a(Polygon);
});
});
});