Mercurial > code > home > repos > streamed-graph
annotate 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 |
rev | line source |
---|---|
104
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
1 import { Quad, Store, Term } from "n3"; |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
2 import { n3Graph } from "./fetchAndParse"; |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
3 import { AlignedTable, Layout, LayoutResult } from "./Layout"; |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
4 import { EX, rdf } from "./namespaces"; |
103 | 5 import { ViewConfig } from "./ViewConfig"; |
88
ac7ad087d474
graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff
changeset
|
6 |
103 | 7 const twoStatements = async (): Promise<Store> => { |
8 return n3Graph(` | |
9 @prefix : <http://example.com/> . | |
10 :g1 { | |
104
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
11 :a0 :b0 :c0 . |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
12 :d0 :e0 :f0 . |
103 | 13 } |
14 `); | |
15 }; | |
16 | |
17 const typedStatements = async (): Promise<Store> => { | |
18 return n3Graph(` | |
19 @prefix : <http://example.com/> . | |
20 :g1 { | |
21 :a a :T1 ; :color :red . | |
22 :b a :T1 ; :color :blue . | |
23 :c a :T1 . | |
24 :d a :T2 ; :size :big . | |
25 :e a :T1,:T2; :size :small | |
26 } | |
27 `); | |
28 }; | |
29 function G1(s: Term, p: Term, o: Term): Quad { | |
30 return new Quad(s, p, o, EX("g1")); | |
31 } | |
32 | |
33 describe("Layout", () => { | |
34 it("accepts a ViewConfig", async () => { | |
35 const vc = new ViewConfig(); | |
36 await vc.readFromGraph(` | |
37 @prefix ex: <http://example.com/> . | |
38 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | |
39 | |
40 <> a ex:View; rdfs:label "repos" .`); | |
41 const layout = new Layout(vc); | |
42 const lr = layout.plan(await twoStatements()); | |
88
ac7ad087d474
graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff
changeset
|
43 }); |
103 | 44 it("defaults to putting all triples in the ungrouped list", async () => { |
45 const layout = new Layout(); | |
46 const lr = layout.plan(await twoStatements()); | |
47 expect(lr).toEqual({ | |
48 sections: [ | |
49 { | |
50 statements: [ | |
104
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
51 G1(EX("a0"), EX("b0"), EX("c0")), |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
52 G1(EX("d0"), EX("e0"), EX("f0")), |
103 | 53 ], |
54 }, | |
55 ], | |
56 }); | |
57 }); | |
58 describe("makes a table as requested by ViewConfig", () => { | |
59 let lr: LayoutResult; | |
60 | |
61 beforeAll(async () => { | |
62 const vc = new ViewConfig(); | |
63 await vc.readFromGraph(` | |
64 @prefix : <http://example.com/> . | |
65 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | |
66 | |
67 <> a :View; :table [ :primaryType :T1 ] .`); | |
68 const layout = new Layout(vc); | |
104
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
69 lr = layout.plan(await typedStatements()); |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
70 }); |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
71 it("returns 2 sections", ()=>{ |
103 | 72 expect(lr.sections).toHaveLength(2); |
104
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
73 }) |
103 | 74 it("puts the right type in the table", async () => { |
104
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
75 const sec0 = lr.sections[0] as AlignedTable; |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
76 expect(sec0.columnHeaders).toEqual([ |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
77 { rdfType: EX("T1"), pred: EX("color") }, |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
78 { rdfType: EX("T1"), pred: EX("size") } |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
79 ]) |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
80 expect(sec0.rows).toEqual([ |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
81 [EX("a"), EX("red"), null], |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
82 [EX("b"), EX("blue"),null], |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
83 [EX("c"), null, null], |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
84 [EX("e"), null, EX('small')], |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
85 ]); |
103 | 86 }); |
87 it("leaves the rest ungrouped", async () => { | |
88 expect(lr.sections[1]).toEqual({ | |
89 statements: [ | |
104
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
90 G1(EX("d"), rdf.type, EX("T2")), |
103 | 91 G1(EX("d"), EX("size"), EX("big")), |
92 ], | |
93 }); | |
94 }); | |
95 }); | |
96 it("makes a table out of ungrouped triples with the same type", async () => {}); | |
88
ac7ad087d474
graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff
changeset
|
97 }); |
ac7ad087d474
graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff
changeset
|
98 |
103 | 99 // describe("equality", () => { |
100 // test("investigation of https://github.com/rdfjs/N3.js/issues/265", () => { | |
101 // const x = namedNode("x"); | |
102 // const x2 = namedNode("x"); | |
103 // // (NamedNode.prototype as any).hashCode = () => 0; | |
104 // // expect((x as any).hashCode()).toEqual((x2 as any).hashCode()) | |
105 // expect(x === x2).toBeFalsy(); | |
106 // expect(x == x2).toBeFalsy(); | |
107 // expect(x.equals(x2)).toBeTruthy(); | |
108 // let imap = Immutable.Map(); | |
109 // imap = imap.set(x, 11); | |
110 // imap = imap.set(x, 22); | |
111 // imap = imap.set(x2, 33); | |
112 // expect(imap.has(x)).toBeTruthy(); | |
113 // expect(imap.has(x2)).toBeTruthy(); | |
114 // expect(imap.size).toEqual(1); | |
115 // }); | |
116 // }); | |
117 | |
118 // describe("groupByRdfType", () => { | |
119 // test("finds multiple graphs", () => {}); | |
120 // test("works", async () => { | |
121 // const store = new Store(); | |
88
ac7ad087d474
graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents:
diff
changeset
|
122 |
103 | 123 // const parser = new Parser(); |
124 // await new Promise((res, rej) => { | |
125 // parser.parse( | |
126 // `PREFIX : <urn:> | |
127 // :rs1 a :Foo; :pred1 "obj1" . | |
128 // :rs2 a :Foo; :pred1 "obj2" . | |
129 // :rs3 a :Bar . | |
130 // :rs4 :pred1 "obj4" . | |
131 // `, | |
132 // (error, quad: Quad, prefixes: Prefixes) => { | |
133 // if (quad) { | |
134 // store.addQuad(quad); | |
135 // } else { | |
136 // res(undefined); | |
137 // } | |
138 // } | |
139 // ); | |
140 // }); | |
141 // const grouped = groupByRdfType(store); | |
142 // expect(Array.from(grouped.byType.keys())).toHaveLength(2); | |
143 // expect(grouped.byType.get(namedNode("urn:Foo"))).toEqual( | |
144 // Immutable.Set([namedNode("urn:rs1"), namedNode("urn:rs2")]) | |
145 // ); | |
146 // expect(grouped.byType.get(namedNode("urn:Bar"))).toEqual( | |
147 // Immutable.Set([namedNode("urn:rs3")]) | |
148 // ); | |
149 // expect(grouped.untypedSubjs).toEqual([namedNode("urn:rs4")]); | |
150 // }); | |
151 | |
152 // describe("MultiSubjsTypeBlockLayout", () => { | |
153 // test("gathers subjs", () => { | |
154 | |
155 // }); | |
156 // test("gathers preds", () => { | |
157 | |
158 // }); | |
159 // test("cells reports filled cells", () => { | |
160 | |
161 // }); | |
162 // }); | |
163 // }); |