How to use the link-lib.defaultNS.schema function in link-lib

To help you get started, we’ve selected a few link-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fletcher91 / link-redux / src / hocs / __tests__ / link.spec.ts View on Github external
it("passes named node array as terms", () => {
            const opts = ctx.fullCW(iri);

            const comp = link([
                defaultNS.schema("name"),
                defaultNS.schema("text"),
                defaultNS.schema("author"),
                defaultNS.example("tags"),
            ])(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)).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", defaultNS.example("tag/0"));
        });
github fletcher91 / link-redux / src / components / __tests__ / Property.spec.ts View on Github external
it("renders null when the given property is not present", () => {
        const opts = ctx.fullCW(subject);

        const comp = React.createElement(
            Property,
            { label: defaultNS.schema("title"), ...opts.contextProps() },
        );
        const elem = mount(opts.wrapComponent(comp));

        expect(elem.find(Property).children()).toHaveLength(0);
    });
github fletcher91 / link-redux / src / hocs / __tests__ / link.spec.ts View on Github external
it("can return JS native objects", () => {
                const opts = ctx.fullCW(iri);

                const comp = link(
                    [
                        defaultNS.schema("name"),
                        defaultNS.ex("timesRead"),
                        defaultNS.schema("dateCreated"),
                        defaultNS.schema("author"),
                    ],
                    { returnType: "literal" },
                )(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)).toHaveProp("name", "title");
                expect(elem.find(TestComponent)).toHaveProp("timesRead", 5);
                expect(elem.find(TestComponent)).toHaveProp("dateCreated", new Date("2019-01-01"));
                expect(elem.find(TestComponent)).toHaveProp("author", new NamedNode("http://example.org/people/0"));
            });
github fletcher91 / link-redux / src / components / __tests__ / Type.spec.ts View on Github external
it("renders default when set", () => {
        const opts = ctx.type(undefined);
        opts.lrs.registerAll(LinkedRenderStore.registerRenderer(
            createComponent("thing"),
            defaultNS.schema("Thing"),
        ));

        const elem = mount(opts.wrapComponent(createElement(Type)));

        expect(elem.find("span")).toHaveClassName("thing");
    });
github fletcher91 / link-redux / src / components / __tests__ / Property.spec.ts View on Github external
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");
    });
github fletcher91 / link-redux / src / hocs / __tests__ / link.spec.ts View on Github external
it("passes object as terms", () => {
            const opts = ctx.fullCW(iri);

            const comp = link({
                author: defaultNS.schema("author"),
                name: defaultNS.schema("name"),
                tags: defaultNS.example("tags"),
                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)).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", defaultNS.example("tag/0"));
        });
github fletcher91 / link-redux / src / hocs / __tests__ / link.spec.ts View on Github external
it("passes object as terms under custom keys", () => {
            const opts = ctx.fullCW(iri);

            const comp = link({
                author: defaultNS.schema("author"),
                tags: defaultNS.example("tags"),
                text: defaultNS.schema("text"),
                title: defaultNS.schema("name"),
            })(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)).toHaveProp("title", new Literal("title"));
            expect(elem.find(TestComponent)).not.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", defaultNS.example("tag/0"));
        });
github fletcher91 / link-redux / src / hocs / __tests__ / link.spec.ts View on Github external
it("can return JS native objects", () => {
                const opts = ctx.fullCW(iri);

                const comp = link(
                    [
                        defaultNS.schema("name"),
                        defaultNS.ex("timesRead"),
                        defaultNS.schema("dateCreated"),
                        defaultNS.schema("author"),
                    ],
                    { returnType: "literal" },
                )(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)).toHaveProp("name", "title");
                expect(elem.find(TestComponent)).toHaveProp("timesRead", 5);
                expect(elem.find(TestComponent)).toHaveProp("dateCreated", new Date("2019-01-01"));
                expect(elem.find(TestComponent)).toHaveProp("author", new NamedNode("http://example.org/people/0"));
            });
github fletcher91 / link-redux / src / components / __tests__ / LinkedResourceContainer.spec.ts View on Github external
it("renders correct topology through children", () => {
        const opts = ctx.multipleCW(iri, { second: { id: "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.argu("collection"),
        ));

        const comp = createElement(
            LinkedResourceContainer,
            { loadLinkedObject, subject: iri, topology: defaultNS.argu("collection") },
            createElement(
                LinkedResourceContainer,
                { loadLinkedObject, subject: iri },
                createElement(
                    LinkedResourceContainer,
                    { loadLinkedObject, subject: defaultNS.example("resources/10") },
                ),
            ),
        );
github fletcher91 / link-redux / test / fixtures.ts View on Github external
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")),
    ];
};