Mercurial > code > home > repos > streamed-graph
comparison 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 |
comparison
equal
deleted
inserted
replaced
121:3584f24becf4 | 122:2e8fa3fec0c8 |
---|---|
72 | 72 |
73 beforeAll(async () => { | 73 beforeAll(async () => { |
74 const vc = new ViewConfig(); | 74 const vc = new ViewConfig(); |
75 await vc.readFromGraph(` | 75 await vc.readFromGraph(` |
76 @prefix : <http://example.com/> . | 76 @prefix : <http://example.com/> . |
77 | 77 |
78 <> a :View; :table [ :primaryType :T1 ] .`); | 78 <> a :View; :table [ :primaryType :T1 ] .`); |
79 const layout = new Layout(vc); | 79 const layout = new Layout(vc); |
80 lr = layout.plan(await typedStatements()); | 80 lr = layout.plan(await typedStatements()); |
81 }); | 81 }); |
82 it("returns 2 sections", () => { | 82 it("returns 2 sections", () => { |
197 expect(section0.columnHeaders).toEqual([ | 197 expect(section0.columnHeaders).toEqual([ |
198 { rdfTypes: [EX("T1")], pred: EX("p1") }, | 198 { rdfTypes: [EX("T1")], pred: EX("p1") }, |
199 { rdfTypes: [EX("T1")], pred: EX("p3") }, | 199 { rdfTypes: [EX("T1")], pred: EX("p3") }, |
200 { rdfTypes: [EX("T2")], pred: EX("p2") }, | 200 { rdfTypes: [EX("T2")], pred: EX("p2") }, |
201 ]); | 201 ]); |
202 }) | 202 }); |
203 }); | 203 it("joins over an edge", async () => { |
204 const vc = new ViewConfig(); | |
205 await vc.readFromGraph(` | |
206 @prefix : <http://example.com/> . | |
207 | |
208 <> a :View; :table [ | |
209 :primaryType :T1; | |
210 :link [:predicate :predLink ] ] . | |
211 `); | |
212 const layout = new Layout(vc); | |
213 const lr = layout.plan( | |
214 await n3Graph(` | |
215 @prefix : <http://example.com/> . | |
216 :g1 { | |
217 :a a :T1; :color :red; :predLink :b . | |
218 :b a :T2; :size :big . | |
219 } | |
220 `) | |
221 ); | |
222 | |
223 expect(lr.sections).toHaveLength(1); // no loose statements | |
224 const section0 = lr.sections[0] as AlignedTable; | |
225 expect(section0.rowHeaders).toEqual([EX("a")]); | |
226 expect(section0.columnHeaders).toEqual([ | |
227 { rdfTypes: [EX("T1")], pred: EX("color") }, | |
228 // :predLink column is hidden | |
229 { rdfTypes: [EX("T2")], pred: EX("size") }, | |
230 ]); | |
231 }); | |
232 }); | |
233 it("joins 3 subjects into one", async () => { | |
234 const vc = new ViewConfig(); | |
235 await vc.readFromGraph(` | |
236 @prefix : <http://example.com/> . | |
237 | |
238 <> a :View; :table [ | |
239 :primaryType :T1; | |
240 :link | |
241 [:predicate :pred1Link ], | |
242 [:predicate :pred2Link ] | |
243 ] . | |
244 `); | |
245 const layout = new Layout(vc); | |
246 const lr = layout.plan( | |
247 await n3Graph(` | |
248 @prefix : <http://example.com/> . | |
249 :g1 { | |
250 :a a :T1; :color :red; :pred1Link :b; :pred2Link :c . | |
251 :b a :T2; :size :big . | |
252 :c a :T3; :bright 50 . | |
253 } | |
254 `) | |
255 ); | |
256 | |
257 expect(lr.sections).toHaveLength(1); // no loose statements | |
258 const section0 = lr.sections[0] as AlignedTable; | |
259 expect(section0.rowHeaders).toEqual([EX("a")]); | |
260 expect(section0.columnHeaders).toEqual([ | |
261 { rdfTypes: [EX("T1")], pred: EX("color") }, | |
262 { rdfTypes: [EX("T2")], pred: EX("size") }, | |
263 { rdfTypes: [EX("T3")], pred: EX("bright") }, | |
264 ]); | |
265 }); | |
266 it("links rows to predicate that themselves are linked in", async () => { | |
267 const vc = new ViewConfig(); | |
268 await vc.readFromGraph(` | |
269 @prefix : <http://example.com/> . | |
270 | |
271 <> a :View; :table [ | |
272 :primaryType :T1; | |
273 :link | |
274 [:predicate :pred1Link ], | |
275 [:predicate :pred2Link ] | |
276 ] . | |
277 `); | |
278 const layout = new Layout(vc); | |
279 const lr = layout.plan( | |
280 await n3Graph(` | |
281 @prefix : <http://example.com/> . | |
282 :g1 { | |
283 :a a :T1; :color :red; :pred1Link :b . | |
284 :b a :T2; :size :big; :pred2Link :c . | |
285 :c a :T3; :bright 50 . | |
286 } | |
287 `) | |
288 ); | |
289 console.log(JSON.stringify(lr.sections, null, " ")); | |
290 | |
291 expect(lr.sections).toHaveLength(1); // no loose statements | |
292 const section0 = lr.sections[0] as AlignedTable; | |
293 expect(section0.rowHeaders).toEqual([EX("a")]); | |
294 expect(section0.columnHeaders).toEqual([ | |
295 { rdfTypes: [EX("T1")], pred: EX("color") }, | |
296 { rdfTypes: [EX("T2")], pred: EX("size") }, | |
297 { rdfTypes: [EX("T3")], pred: EX("bright") }, | |
298 ]); | |
299 }); | |
300 | |
204 it.skip("makes a table out of ungrouped triples with the same type", async () => {}); | 301 it.skip("makes a table out of ungrouped triples with the same type", async () => {}); |
205 }); | 302 }); |