comparison src/layout/Layout.test.ts @ 116:dd3325cc023e

multiple table support in Layout
author drewp@bigasterisk.com
date Sat, 19 Mar 2022 17:23:04 -0700
parents 4b33a479dc2f
children c2923b20bf5c
comparison
equal deleted inserted replaced
115:84551452a9c9 116:dd3325cc023e
38 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 38 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
39 39
40 <> a ex:View; rdfs:label "repos" .`); 40 <> a ex:View; rdfs:label "repos" .`);
41 const layout = new Layout(vc); 41 const layout = new Layout(vc);
42 const lr = layout.plan(await twoStatements()); 42 const lr = layout.plan(await twoStatements());
43 });
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);
43 }); 49 });
44 it("defaults to putting all triples in the ungrouped list", async () => { 50 it("defaults to putting all triples in the ungrouped list", async () => {
45 const layout = new Layout(); 51 const layout = new Layout();
46 const lr = layout.plan(await twoStatements()); 52 const lr = layout.plan(await twoStatements());
47 expect(lr).toEqual({ 53 expect(lr).toEqual({
104 }, 110 },
105 ], 111 ],
106 }); 112 });
107 }); 113 });
108 }); 114 });
115 it("makes two tables", async () => {
116 const vc = new ViewConfig();
117 await vc.readFromGraph(`
118 @prefix ex: <http://example.com/> .
119 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
120 @prefix : <http://example.com/> .
121
122 <> a :View; :table [ :primaryType :T1 ], [ :primaryType :T2 ] .`);
123 const layout = new Layout(vc);
124 const lr = layout.plan(await typedStatements());
125 expect(lr.sections).toHaveLength(2);
126 expect(lr.sections[0]).toEqual({
127 columnHeaders: [
128 { rdfType: EX("T1"), pred: EX("color") },
129 { rdfType: EX("T1"), pred: EX("size") },
130 ],
131 rowHeaders: [EX("a"), EX("b"), EX("c"), EX("e")],
132 rows: [
133 [[EX("red")], []],
134 [[EX("blue")], []],
135 [[], []],
136 [[], [EX("small")]],
137 ],
138 });
139 expect(lr.sections[1]).toEqual({
140 columnHeaders: [{ rdfType: EX("T2"), pred: EX("size") }],
141 rowHeaders: [EX("d"), EX("e")],
142 rows: [
143 [[EX("big")]], //
144 [[EX("small")]],
145 ],
146 });
147 });
109 it.skip("makes a table out of ungrouped triples with the same type", async () => {}); 148 it.skip("makes a table out of ungrouped triples with the same type", async () => {});
110 }); 149 });
111
112 // describe("equality", () => {
113 // test("investigation of https://github.com/rdfjs/N3.js/issues/265", () => {
114 // const x = namedNode("x");
115 // const x2 = namedNode("x");
116 // // (NamedNode.prototype as any).hashCode = () => 0;
117 // // expect((x as any).hashCode()).toEqual((x2 as any).hashCode())
118 // expect(x === x2).toBeFalsy();
119 // expect(x == x2).toBeFalsy();
120 // expect(x.equals(x2)).toBeTruthy();
121 // let imap = Immutable.Map();
122 // imap = imap.set(x, 11);
123 // imap = imap.set(x, 22);
124 // imap = imap.set(x2, 33);
125 // expect(imap.has(x)).toBeTruthy();
126 // expect(imap.has(x2)).toBeTruthy();
127 // expect(imap.size).toEqual(1);
128 // });
129 // });
130
131 // describe("groupByRdfType", () => {
132 // test("finds multiple graphs", () => {});
133 // test("works", async () => {
134 // const store = new Store();
135
136 // const parser = new Parser();
137 // await new Promise((res, rej) => {
138 // parser.parse(
139 // `PREFIX : <urn:>
140 // :rs1 a :Foo; :pred1 "obj1" .
141 // :rs2 a :Foo; :pred1 "obj2" .
142 // :rs3 a :Bar .
143 // :rs4 :pred1 "obj4" .
144 // `,
145 // (error, quad: Quad, prefixes: Prefixes) => {
146 // if (quad) {
147 // store.addQuad(quad);
148 // } else {
149 // res(undefined);
150 // }
151 // }
152 // );
153 // });
154 // const grouped = groupByRdfType(store);
155 // expect(Array.from(grouped.byType.keys())).toHaveLength(2);
156 // expect(grouped.byType.get(namedNode("urn:Foo"))).toEqual(
157 // Immutable.Set([namedNode("urn:rs1"), namedNode("urn:rs2")])
158 // );
159 // expect(grouped.byType.get(namedNode("urn:Bar"))).toEqual(
160 // Immutable.Set([namedNode("urn:rs3")])
161 // );
162 // expect(grouped.untypedSubjs).toEqual([namedNode("urn:rs4")]);
163 // });
164
165 // describe("MultiSubjsTypeBlockLayout", () => {
166 // test("gathers subjs", () => {
167
168 // });
169 // test("gathers preds", () => {
170
171 // });
172 // test("cells reports filled cells", () => {
173
174 // });
175 // });
176 // });