Test for init and reset methods on service.

Bugfix for reset.
Adjusted expectation of number of svg layers.
This commit is contained in:
Noenandre
2023-03-03 16:43:54 +01:00
parent 9a7f473f20
commit 255c80d341
4 changed files with 97 additions and 5 deletions

View File

@@ -323,7 +323,7 @@ export default {
reset: async function () {
if (_vegbilderCache) {
for (let layer of _vegbilderCache.wfslayers.values()) {
for (let tile of layer.values()) { abortRequest(tile); }
for (let tile of layer.inflight.values()) { abortRequest(tile); }
}
}

View File

@@ -0,0 +1,48 @@
describe('iD.serviceVegbilder', function() {
const dimensions = [64, 64];
let context, vegbilder;
before(function() {
iD.services.vegbilder = iD.serviceVegbilder;
});
after(function() {
delete iD.services.vegbilder;
});
beforeEach(async function() {
context = iD.coreContext().assetPath('../dist/').init();
context.projection
.scale(iD.geoZoomToScale(14))
.translate([-116508, 0]) // 10,0
.clipExtent([[0,0], dimensions]);
vegbilder = iD.services.vegbilder;
await vegbilder.reset();
});
afterEach(function() {
fetchMock.reset();
});
describe('#init', function() {
it('Initializes cache one time', function() {
const cache = vegbilder.cache();
expect(cache).to.have.property('wfslayers');
expect(cache).to.have.property('rtree');
expect(cache).to.have.property('sequences');
vegbilder.init();
const cache2 = vegbilder.cache();
expect(cache).to.equal(cache2);
});
});
describe('#reset', function() {
it('resets cache', function() {
vegbilder.cache().foo = 'bar';
vegbilder.reset();
expect(vegbilder.cache()).to.not.have.property('foo');
});
});
});

View File

@@ -137,5 +137,48 @@ const capabilities = `<?xml version="1.0" encoding="UTF-8"?>
fetchMock.sticky('https://www.openstreetmap.org/api/capabilities', capabilities, {sticky: true});
fetchMock.sticky('http://www.openstreetmap.org/api/capabilities', capabilities, {sticky: true});
const vegbilderOwsCapabilities = `<?xml version="1.0" encoding="UTF-8"?>
<wfs:WFS_Capabilities version="2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.opengis.net/wfs/2.0"
xmlns:wfs="http://www.opengis.net/wfs/2.0"
xmlns:ows="http://www.opengis.net/ows/1.1"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:fes="http://www.opengis.net/fes/2.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 https://www.vegvesen.no/kart/ogc/schemas/wfs/2.0/wfs.xsd"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:vegbilder_1_0="http://vegbilder_1_0">
<ows:ServiceIdentification>
<ows:Title>Mock OGC</ows:Title>
<ows:ServiceType>WFS</ows:ServiceType>
<ows:ServiceTypeVersion>2.0.0</ows:ServiceTypeVersion>
</ows:ServiceIdentification>
<FeatureTypeList>
<FeatureType xmlns:vegbilder_1_0="http://vegbilder_1_0">
<Name>vegbilder_1_0:Vegbilder_2020</Name>
<Title>Vegbilder_2020</Title>
<Abstract>Testlayer</Abstract>
<DefaultCRS>urn:ogc:def:crs:EPSG::4326</DefaultCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3857</OtherCRS>
</FeatureType>
<FeatureType xmlns:vegbilder_1_0="http://vegbilder_1_0">
<Name>not_matched_layer:Vegbilder_2020</Name>
<Title>Vegbilder_2020_4</Title>
<Abstract>Not matched layer</Abstract>
<DefaultCRS>urn:ogc:def:crs:EPSG::4326</DefaultCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3857</OtherCRS>
</FeatureType>
</FeatureTypeList>
<fes:Filter_Capabilities/>
</wfs:WFS_Capabilities>`;
fetchMock.sticky({
url: 'https://www.vegvesen.no/kart/ogc/vegbilder_1_0/ows',
query: {
service: 'WFS',
request: 'GetCapabilities'
}
}, vegbilderOwsCapabilities, {sticky: true});
fetchMock.config.fallbackToNetwork = true;
fetchMock.config.overwriteRoutes = false;

View File

@@ -26,7 +26,7 @@ describe('iD.svgLayers', function () {
it('creates default data layers', function () {
container.call(iD.svgLayers(projection, context));
var nodes = container.selectAll('svg .data-layer').nodes();
expect(nodes.length).to.eql(15);
expect(nodes.length).to.eql(16);
expect(d3.select(nodes[0]).classed('osm')).to.be.true;
expect(d3.select(nodes[1]).classed('notes')).to.be.true;
expect(d3.select(nodes[2]).classed('data')).to.be.true;
@@ -39,9 +39,10 @@ describe('iD.svgLayers', function () {
expect(d3.select(nodes[9]).classed('mapillary-map-features')).to.be.true;
expect(d3.select(nodes[10]).classed('mapillary-signs')).to.be.true;
expect(d3.select(nodes[11]).classed('kartaview')).to.be.true;
expect(d3.select(nodes[12]).classed('debug')).to.be.true;
expect(d3.select(nodes[13]).classed('geolocate')).to.be.true;
expect(d3.select(nodes[14]).classed('touch')).to.be.true;
expect(d3.select(nodes[12]).classed('vegbilder')).to.be.true;
expect(d3.select(nodes[13]).classed('debug')).to.be.true;
expect(d3.select(nodes[14]).classed('geolocate')).to.be.true;
expect(d3.select(nodes[15]).classed('touch')).to.be.true;
});
});