comparison src/Layout.test.ts @ 104:1aea03d306af

WIP Layout. tests are passing but they're a little wrong
author drewp@bigasterisk.com
date Sat, 12 Mar 2022 22:41:43 -0800
parents f12feced00ce
children
comparison
equal deleted inserted replaced
103:f12feced00ce 104:1aea03d306af
1 import { Layout, LayoutResult } from "./Layout"; 1 import { Quad, Store, Term } from "n3";
2 import { n3Graph } from "./fetchAndParse";
3 import { AlignedTable, Layout, LayoutResult } from "./Layout";
4 import { EX, rdf } from "./namespaces";
2 import { ViewConfig } from "./ViewConfig"; 5 import { ViewConfig } from "./ViewConfig";
3 import {
4 DataFactory,
5 Store,
6 Prefixes,
7 Parser,
8 Quad,
9 NamedNode,
10 Term,
11 } from "n3";
12 import { EX, rdf } from "./namespaces";
13 import Immutable from "immutable";
14 import { n3Graph } from "./fetchAndParse";
15 const { namedNode } = DataFactory;
16 6
17 const twoStatements = async (): Promise<Store> => { 7 const twoStatements = async (): Promise<Store> => {
18 return n3Graph(` 8 return n3Graph(`
19 @prefix : <http://example.com/> . 9 @prefix : <http://example.com/> .
20 :g1 { 10 :g1 {
21 :a :b :c . 11 :a0 :b0 :c0 .
22 :d :e :f . 12 :d0 :e0 :f0 .
23 } 13 }
24 `); 14 `);
25 }; 15 };
26 16
27 const typedStatements = async (): Promise<Store> => { 17 const typedStatements = async (): Promise<Store> => {
56 const lr = layout.plan(await twoStatements()); 46 const lr = layout.plan(await twoStatements());
57 expect(lr).toEqual({ 47 expect(lr).toEqual({
58 sections: [ 48 sections: [
59 { 49 {
60 statements: [ 50 statements: [
61 G1(EX("a"), EX("b"), EX("c")), 51 G1(EX("a0"), EX("b0"), EX("c0")),
62 G1(EX("d"), EX("e"), EX("f")), 52 G1(EX("d0"), EX("e0"), EX("f0")),
63 ], 53 ],
64 }, 54 },
65 ], 55 ],
66 }); 56 });
67 }); 57 });
74 @prefix : <http://example.com/> . 64 @prefix : <http://example.com/> .
75 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 65 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
76 66
77 <> a :View; :table [ :primaryType :T1 ] .`); 67 <> a :View; :table [ :primaryType :T1 ] .`);
78 const layout = new Layout(vc); 68 const layout = new Layout(vc);
79 const lr = layout.plan(await typedStatements()); 69 lr = layout.plan(await typedStatements());
70 });
71 it("returns 2 sections", ()=>{
80 expect(lr.sections).toHaveLength(2); 72 expect(lr.sections).toHaveLength(2);
81 }); 73 })
82 it("puts the right type in the table", async () => { 74 it("puts the right type in the table", async () => {
83 expect(lr.sections[0]).toEqual({ 75 const sec0 = lr.sections[0] as AlignedTable;
84 columnHeaders: [{ rdfType: EX("T1"), pred: EX("color") }], 76 expect(sec0.columnHeaders).toEqual([
85 rows: [ 77 { rdfType: EX("T1"), pred: EX("color") },
86 [EX("a"), EX("red")], 78 { rdfType: EX("T1"), pred: EX("size") }
87 [EX("b"), EX("blue")], 79 ])
88 [EX("c"), null], 80 expect(sec0.rows).toEqual([
89 [EX("e"), null], 81 [EX("a"), EX("red"), null],
90 ], 82 [EX("b"), EX("blue"),null],
91 }); 83 [EX("c"), null, null],
84 [EX("e"), null, EX('small')],
85 ]);
92 }); 86 });
93 it("leaves the rest ungrouped", async () => { 87 it("leaves the rest ungrouped", async () => {
94 expect(lr.sections[1]).toEqual({ 88 expect(lr.sections[1]).toEqual({
95 statements: [ 89 statements: [
96 G1(EX("d"), rdf.type, EX("T1")), 90 G1(EX("d"), rdf.type, EX("T2")),
97 G1(EX("d"), EX("size"), EX("big")), 91 G1(EX("d"), EX("size"), EX("big")),
98 ], 92 ],
99 }); 93 });
100 }); 94 });
101 }); 95 });