view src/layout/ViewConfig.test.ts @ 143:5adf79d4a9f4

release v0.11.0
author drewp@bigasterisk.com
date Mon, 08 May 2023 13:29:48 -0700
parents 2e8fa3fec0c8
children
line wrap: on
line source

import { Util } from "n3";
import { EX } from "./namespaces";
import { ViewConfig } from "./ViewConfig";

describe("ViewModel", () => {
  it("gets a table description", async () => {
    const vc = new ViewConfig();

    await vc.readFromGraph(`
        @prefix ex: <http://example.com/> .
        @prefix demo: <http://example.com/demo/> .
        @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
        @prefix : <http://bigasterisk.com/netRoutes/ns#> .

        <> a ex:View ; rdfs:label "repos" .
        <> ex:table demo:table1 .
        demo:table1
        ex:primaryType :FilteredNic;
        ex:joinType :Traffic .
        `);
    const NET = Util.prefix("http://bigasterisk.com/netRoutes/ns#");

    expect(vc.tables[0].primary).toEqual(NET("FilteredNic"));
    expect(vc.tables[0].joins).toEqual([NET("Traffic")]);
  });
  it("gets pred joins", async () => {
    const vc = new ViewConfig();
    await vc.readFromGraph(`
    @prefix ex: <http://example.com/> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix : <http://example.com/> .

    <> a :View; :table [
      :primaryType :T1;
      :link [:predicate :predLink; :rtype :T2 ] ] .
  `);
    expect(vc.tables[0].primary).toEqual(EX("T1"));
    expect(vc.tables[0].links).toEqual([{ pred: EX("predLink") }]);
  });
});