Mercurial > code > home > repos > streamed-graph
diff 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 |
line wrap: on
line diff
--- a/src/layout/Layout.test.ts Sat Mar 19 16:37:29 2022 -0700 +++ b/src/layout/Layout.test.ts Sat Mar 19 17:23:04 2022 -0700 @@ -41,6 +41,12 @@ const layout = new Layout(vc); const lr = layout.plan(await twoStatements()); }); + it("returns no sections for empty graph", () => { + const vc = new ViewConfig(); + const layout = new Layout(vc); + const lr = layout.plan(new Store()); + expect(lr.sections).toHaveLength(0); + }); it("defaults to putting all triples in the ungrouped list", async () => { const layout = new Layout(); const lr = layout.plan(await twoStatements()); @@ -106,71 +112,38 @@ }); }); }); + it("makes two tables", async () => { + const vc = new ViewConfig(); + await vc.readFromGraph(` + @prefix ex: <http://example.com/> . + @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + @prefix : <http://example.com/> . + + <> a :View; :table [ :primaryType :T1 ], [ :primaryType :T2 ] .`); + const layout = new Layout(vc); + const lr = layout.plan(await typedStatements()); + expect(lr.sections).toHaveLength(2); + expect(lr.sections[0]).toEqual({ + columnHeaders: [ + { rdfType: EX("T1"), pred: EX("color") }, + { rdfType: EX("T1"), pred: EX("size") }, + ], + rowHeaders: [EX("a"), EX("b"), EX("c"), EX("e")], + rows: [ + [[EX("red")], []], + [[EX("blue")], []], + [[], []], + [[], [EX("small")]], + ], + }); + expect(lr.sections[1]).toEqual({ + columnHeaders: [{ rdfType: EX("T2"), pred: EX("size") }], + rowHeaders: [EX("d"), EX("e")], + rows: [ + [[EX("big")]], // + [[EX("small")]], + ], + }); + }); it.skip("makes a table out of ungrouped triples with the same type", async () => {}); }); - -// describe("equality", () => { -// test("investigation of https://github.com/rdfjs/N3.js/issues/265", () => { -// const x = namedNode("x"); -// const x2 = namedNode("x"); -// // (NamedNode.prototype as any).hashCode = () => 0; -// // expect((x as any).hashCode()).toEqual((x2 as any).hashCode()) -// expect(x === x2).toBeFalsy(); -// expect(x == x2).toBeFalsy(); -// expect(x.equals(x2)).toBeTruthy(); -// let imap = Immutable.Map(); -// imap = imap.set(x, 11); -// imap = imap.set(x, 22); -// imap = imap.set(x2, 33); -// expect(imap.has(x)).toBeTruthy(); -// expect(imap.has(x2)).toBeTruthy(); -// expect(imap.size).toEqual(1); -// }); -// }); - -// describe("groupByRdfType", () => { -// test("finds multiple graphs", () => {}); -// test("works", async () => { -// const store = new Store(); - -// const parser = new Parser(); -// await new Promise((res, rej) => { -// parser.parse( -// `PREFIX : <urn:> -// :rs1 a :Foo; :pred1 "obj1" . -// :rs2 a :Foo; :pred1 "obj2" . -// :rs3 a :Bar . -// :rs4 :pred1 "obj4" . -// `, -// (error, quad: Quad, prefixes: Prefixes) => { -// if (quad) { -// store.addQuad(quad); -// } else { -// res(undefined); -// } -// } -// ); -// }); -// const grouped = groupByRdfType(store); -// expect(Array.from(grouped.byType.keys())).toHaveLength(2); -// expect(grouped.byType.get(namedNode("urn:Foo"))).toEqual( -// Immutable.Set([namedNode("urn:rs1"), namedNode("urn:rs2")]) -// ); -// expect(grouped.byType.get(namedNode("urn:Bar"))).toEqual( -// Immutable.Set([namedNode("urn:rs3")]) -// ); -// expect(grouped.untypedSubjs).toEqual([namedNode("urn:rs4")]); -// }); - -// describe("MultiSubjsTypeBlockLayout", () => { -// test("gathers subjs", () => { - -// }); -// test("gathers preds", () => { - -// }); -// test("cells reports filled cells", () => { - -// }); -// }); -// });