comparison src/layout/Layout.test.ts @ 108:5e6840229a05

rewrite freeStatements rendering to put more planning in layout
author drewp@bigasterisk.com
date Fri, 18 Mar 2022 11:57:38 -0700
parents 2468f2227d22
children cbcd82d21356
comparison
equal deleted inserted replaced
107:042bd3361339 108:5e6840229a05
45 const layout = new Layout(); 45 const layout = new Layout();
46 const lr = layout.plan(await twoStatements()); 46 const lr = layout.plan(await twoStatements());
47 expect(lr).toEqual({ 47 expect(lr).toEqual({
48 sections: [ 48 sections: [
49 { 49 {
50 statements: [ 50 subjRows: [
51 G1(EX("a0"), EX("b0"), EX("c0")), 51 { subj: EX("a0"), predRows: [{ pred: EX("b0"), objs: [EX("c0")] }] },
52 G1(EX("d0"), EX("e0"), EX("f0")), 52 { subj: EX("d0"), predRows: [{ pred: EX("e0"), objs: [EX("f0")] }] },
53 ], 53 ],
54 }, 54 },
55 ], 55 ],
56 }); 56 });
57 }); 57 });
66 66
67 <> a :View; :table [ :primaryType :T1 ] .`); 67 <> a :View; :table [ :primaryType :T1 ] .`);
68 const layout = new Layout(vc); 68 const layout = new Layout(vc);
69 lr = layout.plan(await typedStatements()); 69 lr = layout.plan(await typedStatements());
70 }); 70 });
71 it("returns 2 sections", ()=>{ 71 it("returns 2 sections", () => {
72 expect(lr.sections).toHaveLength(2); 72 expect(lr.sections).toHaveLength(2);
73 }) 73 });
74 it("puts the right type in the table", async () => { 74 it("puts the right type in the table", async () => {
75 const sec0 = lr.sections[0] as AlignedTable; 75 const sec0 = lr.sections[0] as AlignedTable;
76 expect(sec0.columnHeaders).toEqual([ 76 expect(sec0.columnHeaders).toEqual([
77 { rdfType: EX("T1"), pred: EX("color") }, 77 { rdfType: EX("T1"), pred: EX("color") },
78 { rdfType: EX("T1"), pred: EX("size") } 78 { rdfType: EX("T1"), pred: EX("size") },
79 ]) 79 ]);
80 expect(sec0.rows).toEqual([ 80 expect(sec0.rows).toEqual([
81 [EX("a"), EX("red"), null], 81 [EX("a"), EX("red"), null],
82 [EX("b"), EX("blue"),null], 82 [EX("b"), EX("blue"), null],
83 [EX("c"), null, null], 83 [EX("c"), null, null],
84 [EX("e"), null, EX('small')], 84 [EX("e"), null, EX("small")],
85 ]); 85 ]);
86 }); 86 });
87 it("leaves the rest ungrouped", async () => { 87 it("leaves the rest ungrouped", async () => {
88 expect(lr.sections[1]).toEqual({ 88 expect(lr.sections[1]).toEqual({
89 statements: [ 89 subjRows: [
90 G1(EX("d"), rdf.type, EX("T2")), 90 {
91 G1(EX("d"), EX("size"), EX("big")), 91 subj: EX("d"),
92 predRows: [
93 { pred: EX("size"), objs: [EX("big")] },
94 { pred: rdf.type, objs: [EX("T2")] },
95 ],
96 },
92 ], 97 ],
93 }); 98 });
94 }); 99 });
95 }); 100 });
96 it("makes a table out of ungrouped triples with the same type", async () => {}); 101 it("makes a table out of ungrouped triples with the same type", async () => {});