Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint no-magic-numbers: 0 */
import { mount } from "enzyme";
import { defaultNS, LinkedRenderStore, RENDER_CLASS_NAME } from "link-lib";
import { BlankNode, Literal, Statement } from "rdflib";
import { createElement } from "react";
import * as ctx from "../../../test/fixtures";
import { LinkedResourceContainer } from "../LinkedResourceContainer";
const id = "resources/5";
const iri = defaultNS.example(id);
const createTestElement = (className = "testComponent") => () => createElement(
"span",
{ className },
);
const loadLinkedObject = () => undefined;
describe("LinkedResourceContainer component", () => {
it("renders null when type is not present", () => {
const opts = ctx.empty(iri);
const comp = createElement(LinkedResourceContainer, {
className: "testmarker",
loadLinkedObject,
subject: iri,
});
/* eslint no-magic-numbers: 0 */
import { mount } from "enzyme";
import { defaultNS, LinkedRenderStore } from "link-lib";
import { Literal, NamedNode, Statement } from "rdflib";
import * as React from "react";
import { Component } from "react";
import * as ctx from "../../../test/fixtures";
import { dataPropsToPropMap, link } from "../link";
const id = "resources/5";
const iri = defaultNS.example(id);
class TestComponent extends Component {
public render() {
return React.createElement("span", { className: "testComponent" });
}
}
describe("link", () => {
describe("dataPropsToPropMap", () => {
describe("with array mapping", () => {
it("throws with an empty map", () => {
expect(() => {
dataPropsToPropMap([], {});
}).toThrowError(TypeError);
});
});
it("does not raise with a subject", () => {
const opts = ctx.empty();
const comp = linkedVersion(() => null);
let caught = false;
try {
mapStateToProps(new Map(), { subject: defaultNS.example("1") });
} catch (e) {
caught = true;
}
expect(caught).toEqual(false);
});
it("merges dataSubjects with the subject", () => {
expect(normalizeDataSubjects({
dataSubjects: [defaultNS.example("Roy")],
subject: defaultNS.example("Tim"),
})).toEqual([
defaultNS.example("Tim"),
defaultNS.example("Roy"),
]);
});
it("makes an array from the subject", () => {
expect(normalizeDataSubjects({ subject: defaultNS.example("Tim") }))
.toEqual([defaultNS.example("Tim")]);
});
it("returns true when subject is changed", () => {
const opts = ctx.fullCW(subject);
const comp = getComp();
const elem = mount(opts.wrapComponent(comp)).find(CustomClass).instance();
const nextProps = { label, subject: NS.example("different") };
expect(elem.shouldComponentUpdate(nextProps)).toEqual(true);
});
});
it("allows the property to be passed", () => {
const opts = ctx.fullCW(subject);
const comp = getComp();
const elem = mount(opts.wrapComponent(comp)).find(CustomClass).instance();
expect(elem.getLinkedObjectPropertyRaw(NS.example("tags"))).toEqual([
new Statement(subject, NS.example("tags"), NS.example("tag/0"), NS.example("default")),
new Statement(subject, NS.example("tags"), NS.example("tag/1"), NS.example("default")),
new Statement(subject, NS.example("tags"), NS.example("tag/2"), NS.example("default")),
new Statement(subject, NS.example("tags"), NS.example("tag/3"), NS.example("default")),
]);
});
});
it("sets the topology", () => {
const opts = ctx.multipleCWArr([{ id: iri }, { id: defaultNS.example("resources/10") }]);
opts.lrs.registerAll(LinkedRenderStore.registerRenderer(
createTestElement("normalRendered"),
defaultNS.schema("CreativeWork"),
));
opts.lrs.registerAll(LinkedRenderStore.registerRenderer(
createTestElement("collectionRendered"),
defaultNS.schema("CreativeWork"),
RENDER_CLASS_NAME,
defaultNS.example("collection"),
));
class CollectionProvider extends TopologyProvider {
constructor(props) {
super(props);
this.topology = defaultNS.example("collection");
}
const sFull = (id: NamedNode, attrs: Test) => {
return [
typeObject(id)[0],
new Statement(id, NS.schema("name"), new Literal(attrs.title || "title"), NS.example("default")),
new Statement(id, NS.schema("text"), new Literal(attrs.text || "text"), NS.example("default")),
new Statement(id, NS.schema("author"), new NamedNode(attrs.author || "http://example.org/people/0"), NS.example("default")),
new Statement(id, NS.schema("dateCreated"), Literal.fromDate(new Date("2019-01-01")), NS.example("default")),
new Statement(id, NS.ex("timesRead"), Literal.fromValue(5), NS.example("default")),
new Statement(id, NS.example("tags"), NS.example("tag/0"), NS.example("default")),
new Statement(id, NS.example("tags"), NS.example("tag/1"), NS.example("default")),
new Statement(id, NS.example("tags"), NS.example("tag/2"), NS.example("default")),
new Statement(id, NS.example("tags"), NS.example("tag/3"), NS.example("default")),
];
};