|
| 1 | +import DateTimeColumn from "../src/DateTimeColumn"; |
| 2 | +import TextColumn from "../src/TextColumn"; |
| 3 | +import IntColumn from "../src/IntColumn"; |
| 4 | +import BoolColumn from "../src/BoolColumn"; |
| 5 | +import { TFile, Vault } from "obsidian"; |
| 6 | +import fs from "fs"; |
| 7 | +import yaml from "js-yaml"; |
| 8 | + |
| 9 | +describe("GetUniq", () => { |
| 10 | + let column; |
| 11 | + let mockVault; |
| 12 | + let rows; |
| 13 | + |
| 14 | + beforeEach(() => { |
| 15 | + mockVault = new Vault(); |
| 16 | + rows = createMockTableRows(); |
| 17 | + }); |
| 18 | + |
| 19 | + it("getUnqDisplayDate", async () => { |
| 20 | + column = new DateTimeColumn("testProperty", { vault: mockVault }); |
| 21 | + column.setIndex(3); // Index of the date column |
| 22 | + column.setFilter(["2023-11-01", "2024-01-03"]); // Range for filtering |
| 23 | + let result = column.getUniqDisplayValuesFiltered(rows); |
| 24 | + expect(result.length).toBe(3); |
| 25 | + column.setFilter([]); // Range for filtering |
| 26 | + rows = createMockTableRows(); |
| 27 | + result = column.getUniqDisplayValuesFiltered(rows); |
| 28 | + expect(result.length).toBe(3); |
| 29 | + }); |
| 30 | + |
| 31 | + /* issue with mock |
| 32 | + it("getUnqDisplayText", async () => { |
| 33 | + column = new TextColumn("testProperty", { vault: mockVault }); |
| 34 | + column.setIndex(7); |
| 35 | + column.setFilter(["ampl"]); |
| 36 | + let result = column.getUniqDisplayValuesFiltered(rows); |
| 37 | + expect(result.length).toBe(1); |
| 38 | + column.setFilter([]); |
| 39 | + rows = createMockTableRows(); |
| 40 | + result = column.getUniqDisplayValuesFiltered(rows); |
| 41 | + expect(result.length).toBe(10); |
| 42 | + }); |
| 43 | +*/ |
| 44 | + |
| 45 | + it("getUnqDisplayInt", async () => { |
| 46 | + column = new IntColumn("testProperty", { vault: mockVault }); |
| 47 | + column.setIndex(5); // Index of the date column |
| 48 | + column.setFilter(["29"]); // Range for filtering |
| 49 | + let result = column.getUniqDisplayValuesFiltered(rows); |
| 50 | + expect(result.length).toBe(2); |
| 51 | + column.setFilter([]); // Range for filtering |
| 52 | + rows = createMockTableRows(); |
| 53 | + result = column.getUniqDisplayValuesFiltered(rows); |
| 54 | + expect(result.length).toBe(6); |
| 55 | + }); |
| 56 | + |
| 57 | + it("getUnqDisplayBool", async () => { |
| 58 | + column = new BoolColumn("testProperty", { vault: mockVault }); |
| 59 | + column.setIndex(4); // Index of the date column |
| 60 | + column.setFilter(["true"]); // Range for filtering |
| 61 | + let result = column.getUniqDisplayValuesFiltered(rows); |
| 62 | + expect(result.length).toBe(3); |
| 63 | + column.setFilter(["true", ""]); // Range for filtering |
| 64 | + result = column.getUniqDisplayValuesFiltered(rows); |
| 65 | + expect(result.length).toBe(3); |
| 66 | + column.setFilter([]); // Range for filtering |
| 67 | + rows = createMockTableRows(); |
| 68 | + result = column.getUniqDisplayValuesFiltered(rows); |
| 69 | + expect(result.length).toBe(3); |
| 70 | + }); |
| 71 | + |
| 72 | + function createMockTableRows() { |
| 73 | + const data = [ |
| 74 | + ["1", "flskdfj/lfksdjfslf/", "f1.md", "2023-10-01T00:00:00", true, 56, ["fdkj", "aaa", "fds"], "ffff", 34], |
| 75 | + ["2", "example/dir/", "file2.md", "2023-11-22T00:00:00", false, null, null, "sampleString", null], |
| 76 | + ["3", "sample/dir/", "file3.md", "2023-12-01T00:00:00", null, 42, ["item1", "item2"], null, 18], |
| 77 | + ["4", "another/path/", "file_four.md", null, null, null, ["one"], "text", 49], |
| 78 | + ["5", "just/path/", "fileV.md", null, true, null, ["another", "list"], "word", null], |
| 79 | + ["6", "dirName/", "lastFile.md", "2023-12-13T00:00:00", true, 29, null, null, 10], |
| 80 | + ["7", "test/dir7/", "file7.md", null, null, 77, ["alpha", "beta"], "testString", 23], |
| 81 | + ["8", "path8/", "theFile8.md", null, false, null, ["lambda"], "anotherString", null], |
| 82 | + ["9", "directory/nine/", "file_9.md", "2024-02-21T00:00:00", true, null, ["foo", "bar"], "random", 15], |
| 83 | + ["10", "sampleDir10/", "file10.md", "2024-03-05T00:00:00", false, 47, null, "lastString", 38] |
| 84 | + ]; |
| 85 | + |
| 86 | + return data.map(([id, dir, nomdefichier, datet, bool1, num1, list1, txt1, int2]) => { |
| 87 | + const createCellS = (textContent) => { |
| 88 | + const cell = document.createElement("td"); |
| 89 | + cell.textContent = textContent; |
| 90 | + return cell; |
| 91 | + }; |
| 92 | + const createCellD = (dt) => { |
| 93 | + const cell = document.createElement("td"); |
| 94 | + const input = document.createElement("input"); |
| 95 | + cell.appendChild(input); |
| 96 | + input.value = dt; |
| 97 | + return cell; |
| 98 | + }; |
| 99 | + |
| 100 | + const createCellB = (bl) => { |
| 101 | + const cell = document.createElement("td"); |
| 102 | + const input = document.createElement("input"); |
| 103 | + input.type = "checkbox"; |
| 104 | + input.checked = bl; |
| 105 | + cell.appendChild(input); |
| 106 | + return cell; |
| 107 | + }; |
| 108 | + |
| 109 | + const rows = document.createElement("div"); |
| 110 | + rows.style.display = ""; |
| 111 | + rows.appendChild(createCellS(id)); |
| 112 | + rows.appendChild(createCellS(dir)); |
| 113 | + rows.appendChild(createCellS(nomdefichier)); |
| 114 | + rows.appendChild(createCellD(datet)); |
| 115 | + rows.appendChild(createCellB(bool1)); |
| 116 | + rows.appendChild(createCellD(num1)); |
| 117 | + rows.appendChild(createCellS(list1)); |
| 118 | + rows.appendChild(createCellS(txt1)); |
| 119 | + rows.appendChild(createCellS(int2)); |
| 120 | + |
| 121 | + return rows; |
| 122 | + }); |
| 123 | + } |
| 124 | +}); |
0 commit comments