Mercurial > code > home > repos > streamed-graph
annotate src/layout/Layout.test.ts @ 122:2e8fa3fec0c8
support joining subjects into wider rows
author | drewp@bigasterisk.com |
---|---|
date | Sun, 20 Mar 2022 14:12:03 -0700 |
parents | 3584f24becf4 |
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(` | |
121 | 37 @prefix : <http://example.com/> . |
103 | 38 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . |
39 | |
121 | 40 <> a :View; rdfs:label "repos" .`); |
103 | 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 }); |
116 | 44 it("returns no sections for empty graph", () => { |
45 const vc = new ViewConfig(); | |
46 const layout = new Layout(vc); | |
47 const lr = layout.plan(new Store()); | |
48 expect(lr.sections).toHaveLength(0); | |
49 }); | |
103 | 50 it("defaults to putting all triples in the ungrouped list", async () => { |
51 const layout = new Layout(); | |
52 const lr = layout.plan(await twoStatements()); | |
53 expect(lr).toEqual({ | |
54 sections: [ | |
55 { | |
108
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
56 subjRows: [ |
109 | 57 { |
58 subj: EX("a0"), | |
59 predRows: [{ pred: EX("b0"), objs: [EX("c0")] }], | |
60 }, | |
61 { | |
62 subj: EX("d0"), | |
63 predRows: [{ pred: EX("e0"), objs: [EX("f0")] }], | |
64 }, | |
103 | 65 ], |
66 }, | |
67 ], | |
68 }); | |
69 }); | |
70 describe("makes a table as requested by ViewConfig", () => { | |
71 let lr: LayoutResult; | |
72 | |
73 beforeAll(async () => { | |
74 const vc = new ViewConfig(); | |
75 await vc.readFromGraph(` | |
76 @prefix : <http://example.com/> . | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
77 |
103 | 78 <> a :View; :table [ :primaryType :T1 ] .`); |
79 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
|
80 lr = layout.plan(await typedStatements()); |
1aea03d306af
WIP Layout. tests are passing but they're a little wrong
drewp@bigasterisk.com
parents:
103
diff
changeset
|
81 }); |
108
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
82 it("returns 2 sections", () => { |
103 | 83 expect(lr.sections).toHaveLength(2); |
108
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
84 }); |
103 | 85 it("puts the right type in the table", async () => { |
118 | 86 const section0 = lr.sections[0] as AlignedTable; |
87 expect(section0.columnHeaders).toEqual([ | |
88 { rdfTypes: [EX("T1")], pred: EX("color") }, | |
89 { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, | |
114
4b33a479dc2f
fix layout test to match new layout return types. clean up UriPairMap
drewp@bigasterisk.com
parents:
109
diff
changeset
|
90 // and doesn't include rdf:type as a column header here |
108
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
91 ]); |
118 | 92 expect(section0.rowHeaders).toEqual([EX("a"), EX("b"), EX("c"), EX("e")]); |
93 expect(section0.rows).toEqual([ | |
114
4b33a479dc2f
fix layout test to match new layout return types. clean up UriPairMap
drewp@bigasterisk.com
parents:
109
diff
changeset
|
94 [[EX("red")], []], |
4b33a479dc2f
fix layout test to match new layout return types. clean up UriPairMap
drewp@bigasterisk.com
parents:
109
diff
changeset
|
95 [[EX("blue")], []], |
4b33a479dc2f
fix layout test to match new layout return types. clean up UriPairMap
drewp@bigasterisk.com
parents:
109
diff
changeset
|
96 [[], []], |
4b33a479dc2f
fix layout test to match new layout return types. clean up UriPairMap
drewp@bigasterisk.com
parents:
109
diff
changeset
|
97 [[], [EX("small")]], |
108
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
98 ]); |
103 | 99 }); |
100 it("leaves the rest ungrouped", async () => { | |
101 expect(lr.sections[1]).toEqual({ | |
108
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
102 subjRows: [ |
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
103 { |
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
104 subj: EX("d"), |
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
105 predRows: [ |
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
106 { pred: EX("size"), objs: [EX("big")] }, |
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
107 { pred: rdf.type, objs: [EX("T2")] }, |
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
108 ], |
5e6840229a05
rewrite freeStatements rendering to put more planning in layout
drewp@bigasterisk.com
parents:
106
diff
changeset
|
109 }, |
103 | 110 ], |
111 }); | |
112 }); | |
113 }); | |
116 | 114 it("makes two tables", async () => { |
115 const vc = new ViewConfig(); | |
116 await vc.readFromGraph(` | |
117 @prefix : <http://example.com/> . | |
118 | |
119 <> a :View; :table [ :primaryType :T1 ], [ :primaryType :T2 ] .`); | |
120 const layout = new Layout(vc); | |
121 const lr = layout.plan(await typedStatements()); | |
122 expect(lr.sections).toHaveLength(2); | |
118 | 123 const section0 = lr.sections[0] as AlignedTable; |
124 expect(section0.columnHeaders).toEqual([ | |
125 { rdfTypes: [EX("T1")], pred: EX("color") }, | |
126 { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, | |
127 ]); | |
128 expect(section0.rowHeaders).toEqual([EX("a"), EX("b"), EX("c"), EX("e")]); | |
129 expect(section0.rows).toEqual([ | |
130 [[EX("red")], []], | |
131 [[EX("blue")], []], | |
132 [[], []], | |
133 [[], [EX("small")]], | |
134 ]); | |
135 const section1 = lr.sections[1] as AlignedTable; | |
136 expect(section1.columnHeaders).toEqual([ | |
137 { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, | |
138 ]); | |
139 expect(section1.rowHeaders).toEqual([EX("d"), EX("e")]); | |
140 expect(section1.rows).toEqual([ | |
141 [[EX("big")]], // | |
142 [[EX("small")]], | |
143 ]); | |
144 }); | |
145 describe("joins multiple types into one table", () => { | |
121 | 146 it("can simply display multiple types merged together", async () => { |
118 | 147 const vc = new ViewConfig(); |
148 await vc.readFromGraph(` | |
149 @prefix ex: <http://example.com/> . | |
150 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | |
151 @prefix : <http://example.com/> . | |
152 | |
153 <> a :View; :table [ :primaryType :T1; :joinType :T2 ] . | |
154 `); | |
155 const layout = new Layout(vc); | |
156 const lr = layout.plan( | |
157 await n3Graph(` | |
158 @prefix : <http://example.com/> . | |
159 :g1 { | |
160 :a a :T1 ; :color :red . | |
161 :b a :T2 ; :size :big . | |
162 } | |
163 `) | |
164 ); | |
165 expect(lr.sections).toHaveLength(1); | |
166 const section0 = lr.sections[0] as AlignedTable; | |
167 expect(section0.columnHeaders).toEqual([ | |
168 { rdfTypes: [EX("T1")], pred: EX("color") }, | |
169 { rdfTypes: [EX("T2")], pred: EX("size") }, | |
170 ]); | |
171 expect(section0.rowHeaders).toEqual([EX("a"), EX("b")]); | |
172 expect(section0.rows).toEqual([ | |
116 | 173 [[EX("red")], []], |
118 | 174 [[], [EX("big")]], |
175 ]); | |
116 | 176 }); |
121 | 177 it("groups columns by type", async () => { |
119
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
178 const vc = new ViewConfig(); |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
179 await vc.readFromGraph(` |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
180 @prefix ex: <http://example.com/> . |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
181 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
182 @prefix : <http://example.com/> . |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
183 |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
184 <> a :View; :table [ :primaryType :T1; :joinType :T2, :T3 ] . |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
185 `); |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
186 const layout = new Layout(vc); |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
187 const lr = layout.plan( |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
188 await n3Graph(` |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
189 @prefix : <http://example.com/> . |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
190 :g1 { |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
191 :a a :T1; :p1 :red; :p3 :green . |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
192 :b a :T2; :p2 :blue . |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
193 } |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
194 `) |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
195 ); |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
196 const section0 = lr.sections[0] as AlignedTable; |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
197 expect(section0.columnHeaders).toEqual([ |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
198 { rdfTypes: [EX("T1")], pred: EX("p1") }, |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
199 { rdfTypes: [EX("T1")], pred: EX("p3") }, |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
200 { rdfTypes: [EX("T2")], pred: EX("p2") }, |
8715633f5213
fancier column sorting to bring preds from the same type together
drewp@bigasterisk.com
parents:
118
diff
changeset
|
201 ]); |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
202 }); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
203 it("joins over an edge", async () => { |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
204 const vc = new ViewConfig(); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
205 await vc.readFromGraph(` |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
206 @prefix : <http://example.com/> . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
207 |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
208 <> a :View; :table [ |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
209 :primaryType :T1; |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
210 :link [:predicate :predLink ] ] . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
211 `); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
212 const layout = new Layout(vc); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
213 const lr = layout.plan( |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
214 await n3Graph(` |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
215 @prefix : <http://example.com/> . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
216 :g1 { |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
217 :a a :T1; :color :red; :predLink :b . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
218 :b a :T2; :size :big . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
219 } |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
220 `) |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
221 ); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
222 |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
223 expect(lr.sections).toHaveLength(1); // no loose statements |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
224 const section0 = lr.sections[0] as AlignedTable; |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
225 expect(section0.rowHeaders).toEqual([EX("a")]); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
226 expect(section0.columnHeaders).toEqual([ |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
227 { rdfTypes: [EX("T1")], pred: EX("color") }, |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
228 // :predLink column is hidden |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
229 { rdfTypes: [EX("T2")], pred: EX("size") }, |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
230 ]); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
231 }); |
116 | 232 }); |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
233 it("joins 3 subjects into one", async () => { |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
234 const vc = new ViewConfig(); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
235 await vc.readFromGraph(` |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
236 @prefix : <http://example.com/> . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
237 |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
238 <> a :View; :table [ |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
239 :primaryType :T1; |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
240 :link |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
241 [:predicate :pred1Link ], |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
242 [:predicate :pred2Link ] |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
243 ] . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
244 `); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
245 const layout = new Layout(vc); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
246 const lr = layout.plan( |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
247 await n3Graph(` |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
248 @prefix : <http://example.com/> . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
249 :g1 { |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
250 :a a :T1; :color :red; :pred1Link :b; :pred2Link :c . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
251 :b a :T2; :size :big . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
252 :c a :T3; :bright 50 . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
253 } |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
254 `) |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
255 ); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
256 |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
257 expect(lr.sections).toHaveLength(1); // no loose statements |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
258 const section0 = lr.sections[0] as AlignedTable; |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
259 expect(section0.rowHeaders).toEqual([EX("a")]); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
260 expect(section0.columnHeaders).toEqual([ |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
261 { rdfTypes: [EX("T1")], pred: EX("color") }, |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
262 { rdfTypes: [EX("T2")], pred: EX("size") }, |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
263 { rdfTypes: [EX("T3")], pred: EX("bright") }, |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
264 ]); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
265 }); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
266 it("links rows to predicate that themselves are linked in", async () => { |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
267 const vc = new ViewConfig(); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
268 await vc.readFromGraph(` |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
269 @prefix : <http://example.com/> . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
270 |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
271 <> a :View; :table [ |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
272 :primaryType :T1; |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
273 :link |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
274 [:predicate :pred1Link ], |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
275 [:predicate :pred2Link ] |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
276 ] . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
277 `); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
278 const layout = new Layout(vc); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
279 const lr = layout.plan( |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
280 await n3Graph(` |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
281 @prefix : <http://example.com/> . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
282 :g1 { |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
283 :a a :T1; :color :red; :pred1Link :b . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
284 :b a :T2; :size :big; :pred2Link :c . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
285 :c a :T3; :bright 50 . |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
286 } |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
287 `) |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
288 ); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
289 console.log(JSON.stringify(lr.sections, null, " ")); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
290 |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
291 expect(lr.sections).toHaveLength(1); // no loose statements |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
292 const section0 = lr.sections[0] as AlignedTable; |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
293 expect(section0.rowHeaders).toEqual([EX("a")]); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
294 expect(section0.columnHeaders).toEqual([ |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
295 { rdfTypes: [EX("T1")], pred: EX("color") }, |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
296 { rdfTypes: [EX("T2")], pred: EX("size") }, |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
297 { rdfTypes: [EX("T3")], pred: EX("bright") }, |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
298 ]); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
299 }); |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
121
diff
changeset
|
300 |
114
4b33a479dc2f
fix layout test to match new layout return types. clean up UriPairMap
drewp@bigasterisk.com
parents:
109
diff
changeset
|
301 it.skip("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
|
302 }); |