MCPcopy
hub / github.com/palantir/plottable / assertBasicRendering

Function assertBasicRendering

test/components/interpolatedColorLegendTests.ts:29–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27 });
28
29 function assertBasicRendering() {
30 const scaleDomain = colorScale.domain();
31 const legendContent = legend.content();
32
33 const swatchesNodes = legendContent.selectAll<Element, any>(SWATCH_SELECTOR).nodes();
34 assert.strictEqual(d3.select(swatchesNodes[0]).attr("fill"),
35 colorScale.scale(scaleDomain[0]),
36 "first swatch's color corresponds with first domain value");
37 assert.strictEqual(d3.select(swatchesNodes[swatchesNodes.length - 1]).attr("fill"),
38 colorScale.scale(scaleDomain[1]),
39 "last swatch's color corresponds with second domain value");
40
41 const defaultNumSwatches = (<any> Plottable.Components.InterpolatedColorLegend)._DEFAULT_NUM_SWATCHES;
42 assert.operator(swatchesNodes.length, ">=", defaultNumSwatches, "there are at least 11 swatches");
43
44 const swatchContainer = legendContent.select(SWATCH_CONTAINER_SELECTOR);
45 const swatchContainerBCR = (<Element> swatchContainer.node()).getBoundingClientRect();
46 const swatchBoundingBox = legendContent.select(SWATCH_BBOX_SELECTOR);
47 const boundingBoxBCR = (<Element> swatchBoundingBox.node()).getBoundingClientRect();
48 assert.isTrue(Plottable.Utils.DOM.clientRectInside(swatchContainerBCR, boundingBoxBCR),
49 "bounding box contains all swatches");
50
51 const elementBCR = (<Element> legendContent.node()).getBoundingClientRect();
52 assert.isTrue(Plottable.Utils.DOM.clientRectInside(swatchContainerBCR, elementBCR),
53 "swatches are drawn within the legend's element");
54
55 const formattedDomainValues = scaleDomain.map(legend.formatter());
56 const labels = legendContent.selectAll<Element, any>("text");
57 const labelTexts = labels.nodes().map((textNode: HTMLScriptElement) => textNode.textContent);
58 assert.deepEqual(labelTexts, formattedDomainValues, "formatter is used to format label text");
59 }
60
61 it("renders correctly when horizontal", () => {
62 legend.renderTo(div);

Callers 1

Calls 5

contentMethod · 0.80
attrMethod · 0.80
domainMethod · 0.45
scaleMethod · 0.45
formatterMethod · 0.45

Tested by

no test coverage detected