view src/layout/ViewConfig.test.ts @ 122:2e8fa3fec0c8

support joining subjects into wider rows
author drewp@bigasterisk.com
date Sun, 20 Mar 2022 14:12:03 -0700
parents 2468f2227d22
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") }]);
  });
});