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 blank nodes", () => {
const bn = new BlankNode();
const opts = ctx.chargeLRS(
[
new Statement(bn, defaultNS.rdf("type"), defaultNS.schema("Thing")),
new Statement(bn, defaultNS.schema("name"), new Literal("title")),
],
bn,
);
const comp = createTestElement();
opts.lrs.registerAll(LinkedRenderStore.registerRenderer(comp, defaultNS.schema("Thing")));
const elem = mount(
opts.wrapComponent(createElement(LinkedResourceContainer, {
loadLinkedObject,
subject: bn,
})),
);
expect(elem.find("span.testComponent")).toExist();
});
it("renders the children and association renderer when data is not present with forceRender and children", () => {
const opts = ctx.fullCW();
opts.lrs.registerAll(LinkedRenderStore.registerRenderer(
({ children }) => React.createElement("div", { className: "association" }, children),
defaultNS.schema("CreativeWork"),
defaultNS.rdf("predicate"),
));
const elem = mount(opts.wrapComponent(React.createElement(
Property,
{
children: React.createElement("span", { className: "child-elem" }),
forceRender: true,
label: defaultNS.ex("nonexistent"),
subject,
...opts.contextProps(),
},
)));
expect(elem).toContainMatchingElement(".association");
expect(elem).toContainMatchingElement(".child-elem");
});
const typeObject = (id: NamedNode) => [
new Statement(id, NS.rdf("type"), NS.schema("CreativeWork")),
];
const typeObject = id => [
new rdf.Statement(exNS(id), defaultNS.rdf('type'), schema('CreativeWork')),
];
const objRaw = subjectData
.filter((s) => labels.includes(s.predicate))
.map((s) => s.object);
if (error) {
return renderError(childProps, lrs, error);
}
if (objRaw.length === 0 && !childProps.forceRender) {
return null;
}
const associationRenderer = getLinkedObjectClass(
childProps,
lrs,
defaultNS.rdf("predicate"),
) || React.Fragment;
const associationProps = associationRenderer !== React.Fragment ? childProps : null;
const childComp = typeof childProps.children === "function" ? childProps.children(objRaw) : childProps.children;
if (typeof childProps.children === "function") {
return React.createElement(associationRenderer, associationProps, childComp);
}
const component = getLinkedObjectClass(childProps, lrs);
if (component) {
const toRender = limitTimes(
childProps,
objRaw,
lrs,
(p) => React.createElement(component, { ...childProps, linkedProp: p }, childComp),
associationRenderer,
);