|
| 1 | +import { DatabaseViewRenderer } from "./DatabaseViewRenderer"; |
| 2 | +import { RenderDatabaseEntryTask } from "./RenderDatabaseEntryTask"; |
| 3 | + |
| 4 | +describe("DatabaseViewRenderer", () => { |
| 5 | + test("renders with grouping", async () => { |
| 6 | + const linkRenderer = {}; |
| 7 | + const sut = new DatabaseViewRenderer(linkRenderer as any); |
| 8 | + |
| 9 | + const entries: RenderDatabaseEntryTask[] = [ |
| 10 | + { |
| 11 | + properties: { |
| 12 | + meta: { id: "a", title: " A", url: "http://a" }, |
| 13 | + properties: new Map([ |
| 14 | + ["Name", "A"], |
| 15 | + ["Foo", "Bar"], |
| 16 | + ]), |
| 17 | + }, |
| 18 | + }, |
| 19 | + { |
| 20 | + properties: { |
| 21 | + meta: { id: "b", title: " B", url: "http://b" }, |
| 22 | + properties: new Map([ |
| 23 | + ["Name", "B"], |
| 24 | + ["Foo", "Baz"], |
| 25 | + ]), |
| 26 | + }, |
| 27 | + }, |
| 28 | + ]; |
| 29 | + |
| 30 | + const result = sut.renderViews(entries, { |
| 31 | + entries: { emitToIndex: false }, |
| 32 | + renderAs: "table", |
| 33 | + views: [ |
| 34 | + { |
| 35 | + title: "By Foo", |
| 36 | + properties: { |
| 37 | + groupBy: "Foo", |
| 38 | + }, |
| 39 | + }, |
| 40 | + ], |
| 41 | + }); |
| 42 | + |
| 43 | + const expected = `## By Foo - Bar |
| 44 | +
|
| 45 | +| Name | Foo | |
| 46 | +| ---- | --- | |
| 47 | +| A | Bar | |
| 48 | +
|
| 49 | +## By Foo - Baz |
| 50 | +
|
| 51 | +| Name | Foo | |
| 52 | +| ---- | --- | |
| 53 | +| B | Baz |`; |
| 54 | + expect(result).toEqual(expected); |
| 55 | + }); |
| 56 | + |
| 57 | + test("filters columns", async () => { |
| 58 | + const linkRenderer = {}; |
| 59 | + const sut = new DatabaseViewRenderer(linkRenderer as any); |
| 60 | + |
| 61 | + const entries: RenderDatabaseEntryTask[] = [ |
| 62 | + { |
| 63 | + properties: { |
| 64 | + meta: { id: "a", title: " A", url: "http://a" }, |
| 65 | + properties: new Map([ |
| 66 | + ["Name", "A"], |
| 67 | + ["Foo", "Bar"], |
| 68 | + ["Alice", "Bob"], |
| 69 | + ]), |
| 70 | + }, |
| 71 | + }, |
| 72 | + ]; |
| 73 | + |
| 74 | + const result = sut.renderViews(entries, { |
| 75 | + entries: { emitToIndex: false }, |
| 76 | + renderAs: "table", |
| 77 | + views: [ |
| 78 | + { |
| 79 | + title: "By Foo", |
| 80 | + properties: { |
| 81 | + include: ["Name", "Foo"], |
| 82 | + }, |
| 83 | + }, |
| 84 | + ], |
| 85 | + }); |
| 86 | + |
| 87 | + const expected = `## By Foo |
| 88 | +
|
| 89 | +| Name | Foo | |
| 90 | +| ---- | --- | |
| 91 | +| A | Bar |`; |
| 92 | + expect(result).toEqual(expected); |
| 93 | + }); |
| 94 | +}); |
0 commit comments