Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("renders the literal renderer", () => {
const opts = ctx.fullCW();
opts.lrs.registerAll(LinkedRenderStore.registerRenderer(
({ linkedProp }) => React.createElement(
"div",
{ className: "integerRenderer", children: linkedProp.value },
),
defaultNS.rdfs("Literal"),
defaultNS.xsd("integer"),
));
const comp = React.createElement(
Property,
{ label: defaultNS.ex("timesRead"), ...opts.contextProps() },
);
const elem = mount(opts.wrapComponent(comp));
expect(elem).toContainMatchingElement(".integerRenderer");
expect(elem.find(".integerRenderer")).toHaveText("5");
});
it("passes object with custom options", () => {
const opts = ctx.fullCW(iri);
const comp = link({
author: defaultNS.schema("author"),
name: [defaultNS.schema("name"), defaultNS.rdfs("label")],
tags: {
label: defaultNS.example("tags"),
limit: Infinity,
},
text: defaultNS.schema("text"),
})(TestComponent);
opts.lrs.registerAll(LinkedRenderStore.registerRenderer(comp, defaultNS.schema("Thing")));
const elem = mount(opts.wrapComponent());
expect(elem.find(TestComponent)).toHaveLength(1);
expect(elem.find(TestComponent)).not.toHaveProp("label");
expect(elem.find(TestComponent)).toHaveProp("name", new Literal("title"));
expect(elem.find(TestComponent)).toHaveProp("text", new Literal("text"));
expect(elem.find(TestComponent)).toHaveProp("author", new NamedNode("http://example.org/people/0"));
expect(elem.find(TestComponent)).toHaveProp("tags", [
return function(p: SomeTerm): React.ReactNode {
if (props.children || p.termType !== "Literal") {
return React.createElement(React.Fragment, null, props.children || p.value);
}
const { topology, topologyCtx, subjectCtx } = props;
const literalRenderer = lrs.getComponentForProperty(
defaultNS.rdfs("Literal"),
NamedNode.find(p.datatype.value),
topology === null ? undefined : topology || topologyCtx,
);
if (!literalRenderer) {
return React.createElement(React.Fragment, null, p.value);
}
return React.createElement(
literalRenderer,
{
linkedProp: p,
subject: p.datatype,
subjectCtx,
topology,
topologyCtx,