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