Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("allows overriding subject", () => {
const opts = ctx.fullCW();
const Comp = withLinkCtx(TestComponent, { subject: true, lrs: true });
const elem = ;
const tree = mount(opts.wrapComponent(elem));
const node = tree.find("TestComponent");
// enzyme-matchers' `toHaveProps` does a slow recursive deep compare
expect((node.props() as any).lrs).toEqual(opts.lrs);
expect(node).toHaveProp("subject", defaultNS.ex("override"));
expect(node).toHaveProp("topology", DEFAULT_TOPOLOGY);
expect(node).toHaveProp("subjectCtx", opts.subject);
expect(node).not.toHaveProp("topologyCtx");
});
it("skips others' properties", () => {
const dataProps = Object.create({ oLabel: defaultNS.ex("o") });
dataProps.cLabel = defaultNS.ex("p");
const [ propMap, requestedProperties ] = dataPropsToPropMap(dataProps, {});
expect(propMap).toHaveProperty("cLabel");
expect(propMap).not.toHaveProperty("oLabel");
expect(requestedProperties).toEqual([defaultNS.ex("p").sI]);
const { cLabel } = propMap;
expect(cLabel).toHaveProperty("label", [defaultNS.ex("p")]);
expect(cLabel).toHaveProperty("name", "cLabel");
});
it("skips others' properties", () => {
const dataProps = Object.create({ oLabel: defaultNS.ex("o") });
dataProps.cLabel = defaultNS.ex("p");
const [ propMap, requestedProperties ] = dataPropsToPropMap(dataProps, {});
expect(propMap).toHaveProperty("cLabel");
expect(propMap).not.toHaveProperty("oLabel");
expect(requestedProperties).toEqual([defaultNS.ex("p").sI]);
const { cLabel } = propMap;
expect(cLabel).toHaveProperty("label", [defaultNS.ex("p")]);
expect(cLabel).toHaveProperty("name", "cLabel");
});
it("registers a class component", () => {
class Comp extends Component {
public static type = defaultNS.ex("TestClass");
public render() { return null; }
}
const [ registration ] = register(Comp);
expect(registration).toHaveProperty("component", Comp);
expect(registration).toHaveProperty("property", RENDER_CLASS_NAME.sI);
expect(registration).toHaveProperty("topology", DEFAULT_TOPOLOGY.sI);
expect(registration).toHaveProperty("type", defaultNS.ex("TestClass").sI);
});
it("processes a map with a NamedNode value", () => {
const [ propMap, requestedProperties ] = dataPropsToPropMap({
cLabel: defaultNS.ex("p"),
}, {});
expect(propMap).toHaveProperty("cLabel");
expect(requestedProperties).toEqual([defaultNS.ex("p").sI]);
const { cLabel } = propMap;
expect(cLabel).toHaveProperty("label", [defaultNS.ex("p")]);
expect(cLabel).toHaveProperty("name", "cLabel");
});
it("renders a registered no-view component", () => {
const opts = ctx.empty();
const errorComp = () => createElement("span", { className: "custom-no-view" });
errorComp.type = defaultNS.ll("NoView");
errorComp.topology = defaultNS.ex("t");
opts.lrs.registerAll(register(errorComp));
const element = renderNoView({
subject: new BlankNode(),
topology: defaultNS.ex("t"),
}, opts.lrs);
const tree = mount(element);
expect(tree).toContainMatchingElement(".custom-no-view");
});
});
it("registers a class component", () => {
class Comp extends Component {
public static type = defaultNS.ex("TestClass");
public render() { return null; }
}
const [ registration ] = register(Comp);
expect(registration).toHaveProperty("component", Comp);
expect(registration).toHaveProperty("property", RENDER_CLASS_NAME.sI);
expect(registration).toHaveProperty("topology", DEFAULT_TOPOLOGY.sI);
expect(registration).toHaveProperty("type", defaultNS.ex("TestClass").sI);
});
it("renders null when data is not present with forceRender", () => {
const opts = ctx.fullCW();
const elem = mount(opts.wrapComponent(React.createElement(
Property,
{
forceRender: true,
label: defaultNS.ex("nonexistent"),
subject,
...opts.contextProps(),
},
)));
expect(elem.find(Property).children()).toHaveLength(0);
});
it("processes a map with an array value", () => {
const [ propMap, requestedProperties ] = dataPropsToPropMap({
cLabel: [defaultNS.ex("p"), defaultNS.ex("q")],
}, {});
expect(propMap).toHaveProperty("cLabel");
expect(requestedProperties).toEqual([defaultNS.ex("p").sI, defaultNS.ex("q").sI]);
const { cLabel } = propMap;
expect(cLabel).toHaveProperty("label", [defaultNS.ex("p"), defaultNS.ex("q")]);
expect(cLabel).toHaveProperty("name", "cLabel");
});
it("processes a map with an array value", () => {
const [ propMap, requestedProperties ] = dataPropsToPropMap({
cLabel: [defaultNS.ex("p"), defaultNS.ex("q")],
}, {});
expect(propMap).toHaveProperty("cLabel");
expect(requestedProperties).toEqual([defaultNS.ex("p").sI, defaultNS.ex("q").sI]);
const { cLabel } = propMap;
expect(cLabel).toHaveProperty("label", [defaultNS.ex("p"), defaultNS.ex("q")]);
expect(cLabel).toHaveProperty("name", "cLabel");
});