Skip to content

Commit

Permalink
Get link in templated feature working. Update existing test to pass with
Browse files Browse the repository at this point in the history
fix in place.
  • Loading branch information
prushforth committed Aug 12, 2024
1 parent 08b10be commit c14aee5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/mapml/layers/DebugOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export var DebugVectors = L.LayerGroup.extend({
.getLayerEl()
.getAttribute('data-testid')
: layers[i].layerBounds &&
layers[i].options?._leafletLayer?._layerEl.hasAttribute(
layers[i].options?._leafletLayer?._layerEl?.hasAttribute(
'data-testid'
)
? layers[i].options._leafletLayer._layerEl.getAttribute(
Expand Down
1 change: 1 addition & 0 deletions src/mapml/layers/TemplatedFeaturesLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export var TemplatedFeaturesLayer = L.Layer.extend({
geometry.bindPopup(c, { autoClose: false, minWidth: 108 });
}
});
L.extend(this._features.options, { _leafletLayer: this._features });
} else {
this._features.eachLayer((layer) => layer.addTo(map));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,52 +14,62 @@ test.describe('map-a loaded inline or remote, directly or via templated map-link
const contentLocations = ['inline', 'remote'];
for (const inlineOrRemote of contentLocations) {
test(`${inlineOrRemote} map-a-wrapped-map-geometry loaded directly creates a hyperlink`, async () => {
const directlyLoadedFeaturesLayer = await page.getByTestId(`${inlineOrRemote}-features`);
const directlyLoadedFeaturesLayer = await page.getByTestId(
`${inlineOrRemote}-features`
);
const directlyLoadedFeaturesCount =
await directlyLoadedFeaturesLayer.evaluate(l => {
let node = (l.hasAttribute('src') ? l.shadowRoot : l);
await directlyLoadedFeaturesLayer.evaluate((l) => {
let node = l.hasAttribute('src') ? l.shadowRoot : l;
return node.querySelectorAll('map-feature').length;
}
);
});
expect(directlyLoadedFeaturesCount).toBe(2);
// one of them contains a map-a wrapping its map-geometry
const directlyLoadedHyperlinksCount =
await directlyLoadedFeaturesLayer.evaluate(l => {
let node = (l.hasAttribute('src') ? l.shadowRoot : l);
await directlyLoadedFeaturesLayer.evaluate((l) => {
let node = l.hasAttribute('src') ? l.shadowRoot : l;
return node.querySelectorAll('map-feature:has(map-a)').length;
}
);
});
expect(directlyLoadedHyperlinksCount).toBe(1);
// all features should have a _groupEl prop (i.e. all features are rendered)
const directlyLoadedFeaturesRenderedCount = await directlyLoadedFeaturesLayer.evaluate(l => {
let node = (l.hasAttribute('src') ? l.shadowRoot : l);
const directlyLoadedFeaturesRenderedCount =
await directlyLoadedFeaturesLayer.evaluate((l) => {
let node = l.hasAttribute('src') ? l.shadowRoot : l;
const hasRendering = (f) => Boolean(f._groupEl);
return Array.from(node.querySelectorAll('map-feature')).filter(hasRendering).length;
});
expect(directlyLoadedFeaturesRenderedCount).toEqual(directlyLoadedFeaturesCount);
return Array.from(node.querySelectorAll('map-feature')).filter(
hasRendering
).length;
});
expect(directlyLoadedFeaturesRenderedCount).toEqual(
directlyLoadedFeaturesCount
);
});
test(`${inlineOrRemote} map-a-wrapped-map-geometry loaded via templated map-link creates a hyperlink`, async () => {
await page.waitForTimeout(500);
const templatedLoadedFeaturesContainer = await page.getByTestId(`${inlineOrRemote}-templated-link`);
const templatedLoadedFeaturesContainer = await page.getByTestId(
`${inlineOrRemote}-templated-link`
);
const templatedLoadedFeaturesCount =
await templatedLoadedFeaturesContainer.evaluate(l => {
await templatedLoadedFeaturesContainer.evaluate((l) => {
return l.shadowRoot.querySelectorAll('map-feature').length;
}
);
});
expect(templatedLoadedFeaturesCount).toBe(2);
// one of them contains a map-a wrapping its map-geometry
const templatedLoadedHyperlinksCount =
await templatedLoadedFeaturesContainer.evaluate(l => {
await templatedLoadedFeaturesContainer.evaluate((l) => {
return l.shadowRoot.querySelectorAll('map-feature:has(map-a)').length;
}
);
});
expect(templatedLoadedHyperlinksCount).toBe(1);
// all features should have a _groupEl prop (i.e. all features are rendered)
const templatedLoadedFeaturesRenderedCount = await templatedLoadedFeaturesContainer.evaluate(l => {
const templatedLoadedFeaturesRenderedCount =
await templatedLoadedFeaturesContainer.evaluate((l) => {
const hasRendering = (f) => Boolean(f._groupEl);
return Array.from(l.shadowRoot.querySelectorAll('map-feature')).filter(hasRendering).length;
});
expect(templatedLoadedFeaturesRenderedCount).toEqual(templatedLoadedFeaturesCount);
return Array.from(
l.shadowRoot.querySelectorAll('map-feature')
).filter(hasRendering).length;
});
expect(templatedLoadedFeaturesRenderedCount).toEqual(
templatedLoadedFeaturesCount
);
});
}
});

0 comments on commit c14aee5

Please sign in to comment.