Skip to content

Commit c14aee5

Browse files
committed
Get link in templated feature working. Update existing test to pass with
fix in place.
1 parent 08b10be commit c14aee5

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

src/mapml/layers/DebugOverlay.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export var DebugVectors = L.LayerGroup.extend({
255255
.getLayerEl()
256256
.getAttribute('data-testid')
257257
: layers[i].layerBounds &&
258-
layers[i].options?._leafletLayer?._layerEl.hasAttribute(
258+
layers[i].options?._leafletLayer?._layerEl?.hasAttribute(
259259
'data-testid'
260260
)
261261
? layers[i].options._leafletLayer._layerEl.getAttribute(

src/mapml/layers/TemplatedFeaturesLayer.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export var TemplatedFeaturesLayer = L.Layer.extend({
6565
geometry.bindPopup(c, { autoClose: false, minWidth: 108 });
6666
}
6767
});
68+
L.extend(this._features.options, { _leafletLayer: this._features });
6869
} else {
6970
this._features.eachLayer((layer) => layer.addTo(map));
7071
}

test/e2e/elements/map-a/map-a-inline-or-remote-templated-issue-968.test.js

+35-25
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,62 @@ test.describe('map-a loaded inline or remote, directly or via templated map-link
1414
const contentLocations = ['inline', 'remote'];
1515
for (const inlineOrRemote of contentLocations) {
1616
test(`${inlineOrRemote} map-a-wrapped-map-geometry loaded directly creates a hyperlink`, async () => {
17-
const directlyLoadedFeaturesLayer = await page.getByTestId(`${inlineOrRemote}-features`);
17+
const directlyLoadedFeaturesLayer = await page.getByTestId(
18+
`${inlineOrRemote}-features`
19+
);
1820
const directlyLoadedFeaturesCount =
19-
await directlyLoadedFeaturesLayer.evaluate(l => {
20-
let node = (l.hasAttribute('src') ? l.shadowRoot : l);
21+
await directlyLoadedFeaturesLayer.evaluate((l) => {
22+
let node = l.hasAttribute('src') ? l.shadowRoot : l;
2123
return node.querySelectorAll('map-feature').length;
22-
}
23-
);
24+
});
2425
expect(directlyLoadedFeaturesCount).toBe(2);
2526
// one of them contains a map-a wrapping its map-geometry
2627
const directlyLoadedHyperlinksCount =
27-
await directlyLoadedFeaturesLayer.evaluate(l => {
28-
let node = (l.hasAttribute('src') ? l.shadowRoot : l);
28+
await directlyLoadedFeaturesLayer.evaluate((l) => {
29+
let node = l.hasAttribute('src') ? l.shadowRoot : l;
2930
return node.querySelectorAll('map-feature:has(map-a)').length;
30-
}
31-
);
31+
});
3232
expect(directlyLoadedHyperlinksCount).toBe(1);
3333
// all features should have a _groupEl prop (i.e. all features are rendered)
34-
const directlyLoadedFeaturesRenderedCount = await directlyLoadedFeaturesLayer.evaluate(l => {
35-
let node = (l.hasAttribute('src') ? l.shadowRoot : l);
34+
const directlyLoadedFeaturesRenderedCount =
35+
await directlyLoadedFeaturesLayer.evaluate((l) => {
36+
let node = l.hasAttribute('src') ? l.shadowRoot : l;
3637
const hasRendering = (f) => Boolean(f._groupEl);
37-
return Array.from(node.querySelectorAll('map-feature')).filter(hasRendering).length;
38-
});
39-
expect(directlyLoadedFeaturesRenderedCount).toEqual(directlyLoadedFeaturesCount);
38+
return Array.from(node.querySelectorAll('map-feature')).filter(
39+
hasRendering
40+
).length;
41+
});
42+
expect(directlyLoadedFeaturesRenderedCount).toEqual(
43+
directlyLoadedFeaturesCount
44+
);
4045
});
4146
test(`${inlineOrRemote} map-a-wrapped-map-geometry loaded via templated map-link creates a hyperlink`, async () => {
4247
await page.waitForTimeout(500);
43-
const templatedLoadedFeaturesContainer = await page.getByTestId(`${inlineOrRemote}-templated-link`);
48+
const templatedLoadedFeaturesContainer = await page.getByTestId(
49+
`${inlineOrRemote}-templated-link`
50+
);
4451
const templatedLoadedFeaturesCount =
45-
await templatedLoadedFeaturesContainer.evaluate(l => {
52+
await templatedLoadedFeaturesContainer.evaluate((l) => {
4653
return l.shadowRoot.querySelectorAll('map-feature').length;
47-
}
48-
);
54+
});
4955
expect(templatedLoadedFeaturesCount).toBe(2);
5056
// one of them contains a map-a wrapping its map-geometry
5157
const templatedLoadedHyperlinksCount =
52-
await templatedLoadedFeaturesContainer.evaluate(l => {
58+
await templatedLoadedFeaturesContainer.evaluate((l) => {
5359
return l.shadowRoot.querySelectorAll('map-feature:has(map-a)').length;
54-
}
55-
);
60+
});
5661
expect(templatedLoadedHyperlinksCount).toBe(1);
5762
// all features should have a _groupEl prop (i.e. all features are rendered)
58-
const templatedLoadedFeaturesRenderedCount = await templatedLoadedFeaturesContainer.evaluate(l => {
63+
const templatedLoadedFeaturesRenderedCount =
64+
await templatedLoadedFeaturesContainer.evaluate((l) => {
5965
const hasRendering = (f) => Boolean(f._groupEl);
60-
return Array.from(l.shadowRoot.querySelectorAll('map-feature')).filter(hasRendering).length;
61-
});
62-
expect(templatedLoadedFeaturesRenderedCount).toEqual(templatedLoadedFeaturesCount);
66+
return Array.from(
67+
l.shadowRoot.querySelectorAll('map-feature')
68+
).filter(hasRendering).length;
69+
});
70+
expect(templatedLoadedFeaturesRenderedCount).toEqual(
71+
templatedLoadedFeaturesCount
72+
);
6373
});
6474
}
6575
});

0 commit comments

Comments
 (0)