mirror of
https://github.com/jacobtread/obsidian-timekeep.git
synced 2026-07-22 10:10:27 +00:00
tests: export test fixtures and tests for markdown table
This commit is contained in:
parent
d30a4d7e94
commit
73e6246755
18 changed files with 410 additions and 212 deletions
5
src/export/__fixtures__/csv/currentTimeForUnfinished.csv
Normal file
5
src/export/__fixtures__/csv/currentTimeForUnfinished.csv
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Block,Start Time,End time,Duration
|
||||
Test,20-01-01 13:00:00,20-01-01 14:00:00,1.00h
|
||||
Test 2,20-01-01 13:00:00,20-01-01 15:00:00,2.00h
|
||||
Test Group,,,2.00h
|
||||
Test 3,20-01-01 13:00:00,20-01-01 15:00:00,2.00h
|
||||
|
40
src/export/__fixtures__/csv/currentTimeForUnfinished.ts
Normal file
40
src/export/__fixtures__/csv/currentTimeForUnfinished.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import fs from "fs/promises";
|
||||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = await fs.readFile("src/export/__fixtures__/csv/tableRows.csv", "utf-8");
|
||||
|
||||
export const start = moment("2020-01-01T00:00:00Z");
|
||||
export const currentTime = moment(start).add(2, "hours");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(start),
|
||||
endTime: null,
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
5
src/export/__fixtures__/csv/flattenGroupEntries.csv
Normal file
5
src/export/__fixtures__/csv/flattenGroupEntries.csv
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Block,Start Time,End time,Duration
|
||||
Test,20-01-01 13:00:00,20-01-01 14:00:00,1.00h
|
||||
Test 2,20-01-01 13:00:00,20-01-01 15:00:00,2.00h
|
||||
Test Group,,,2.00h
|
||||
Test 3,20-01-01 13:00:00,20-01-01 15:00:00,2.00h
|
||||
|
42
src/export/__fixtures__/csv/flattenGroupEntries.ts
Normal file
42
src/export/__fixtures__/csv/flattenGroupEntries.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import fs from "fs/promises";
|
||||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = await fs.readFile(
|
||||
"src/export/__fixtures__/csv/flattenGroupEntries.csv",
|
||||
"utf-8"
|
||||
);
|
||||
|
||||
export const currentTime = moment("2020-01-01T00:00:00Z");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
3
src/export/__fixtures__/csv/tableRows.csv
Normal file
3
src/export/__fixtures__/csv/tableRows.csv
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Block,Start Time,End time,Duration
|
||||
Test,20-01-01 13:00:00,20-01-01 14:00:00,1.00h
|
||||
Test 2,20-01-01 13:00:00,20-01-01 15:00:00,2.00h
|
||||
|
24
src/export/__fixtures__/csv/tableRows.ts
Normal file
24
src/export/__fixtures__/csv/tableRows.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import fs from "fs/promises";
|
||||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = await fs.readFile("src/export/__fixtures__/csv/tableRows.csv", "utf-8");
|
||||
|
||||
export const currentTime = moment("2020-01-01T00:00:00Z");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
];
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
| Test | 20-01-01 13:00:00 | 20-01-01 14:00:00 | 1.00h |
|
||||
| Test 2 | 20-01-01 13:00:00 | 20-01-01 15:00:00 | 2.00h |
|
||||
| Test Group | | | 2.00h |
|
||||
| Test 3 | 20-01-01 13:00:00 | 20-01-01 15:00:00 | 2.00h |
|
||||
| **Total** | | | **5.00h** |
|
||||
40
src/export/__fixtures__/markdown/currentTimeForUnfinished.ts
Normal file
40
src/export/__fixtures__/markdown/currentTimeForUnfinished.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import fs from "fs/promises";
|
||||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = await fs.readFile("src/export/__fixtures__/markdown/tableRows.md", "utf-8");
|
||||
|
||||
export const start = moment("2020-01-01T00:00:00Z");
|
||||
export const currentTime = moment(start).add(2, "hours");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(start),
|
||||
endTime: null,
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
7
src/export/__fixtures__/markdown/flattenGroupEntries.md
Normal file
7
src/export/__fixtures__/markdown/flattenGroupEntries.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
| Block | Start Time | End time | Duration |
|
||||
| ---------- | ----------------- | ----------------- | --------- |
|
||||
| Test | 20-01-01 13:00:00 | 20-01-01 14:00:00 | 1.00h |
|
||||
| Test 2 | 20-01-01 13:00:00 | 20-01-01 15:00:00 | 2.00h |
|
||||
| Test Group | | | 2.00h |
|
||||
| Test 3 | 20-01-01 13:00:00 | 20-01-01 15:00:00 | 2.00h |
|
||||
| **Total** | | | **5.00h** |
|
||||
42
src/export/__fixtures__/markdown/flattenGroupEntries.ts
Normal file
42
src/export/__fixtures__/markdown/flattenGroupEntries.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import fs from "fs/promises";
|
||||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = await fs.readFile(
|
||||
"src/export/__fixtures__/markdown/flattenGroupEntries.md",
|
||||
"utf-8"
|
||||
);
|
||||
|
||||
export const currentTime = moment("2020-01-01T00:00:00Z");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
5
src/export/__fixtures__/markdown/tableRows.md
Normal file
5
src/export/__fixtures__/markdown/tableRows.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
| Block | Start Time | End time | Duration |
|
||||
| --------- | ----------------- | ----------------- | --------- |
|
||||
| Test | 20-01-01 13:00:00 | 20-01-01 14:00:00 | 1.00h |
|
||||
| Test 2 | 20-01-01 13:00:00 | 20-01-01 15:00:00 | 2.00h |
|
||||
| **Total** | | | **3.00h** |
|
||||
24
src/export/__fixtures__/markdown/tableRows.ts
Normal file
24
src/export/__fixtures__/markdown/tableRows.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import fs from "fs/promises";
|
||||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = await fs.readFile("src/export/__fixtures__/markdown/tableRows.md", "utf-8");
|
||||
|
||||
export const currentTime = moment("2020-01-01T00:00:00Z");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
];
|
||||
44
src/export/__fixtures__/raw/currentTimeForUnfinished.ts
Normal file
44
src/export/__fixtures__/raw/currentTimeForUnfinished.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = [
|
||||
["Test", "20-01-01 13:00:00", "20-01-01 14:00:00", "1.00h"],
|
||||
["Test 2", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
["Test Group", "", "", "2.00h"],
|
||||
["Test 3", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
];
|
||||
|
||||
export const start = moment("2020-01-01T00:00:00Z");
|
||||
export const currentTime = moment(start).add(2, "hours");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(start),
|
||||
endTime: null,
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
43
src/export/__fixtures__/raw/flattenGroupEntries.ts
Normal file
43
src/export/__fixtures__/raw/flattenGroupEntries.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = [
|
||||
["Test", "20-01-01 13:00:00", "20-01-01 14:00:00", "1.00h"],
|
||||
["Test 2", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
["Test Group", "", "", "2.00h"],
|
||||
["Test 3", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
];
|
||||
|
||||
export const currentTime = moment("2020-01-01T00:00:00Z");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
26
src/export/__fixtures__/raw/tableRows.ts
Normal file
26
src/export/__fixtures__/raw/tableRows.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export const output = [
|
||||
["Test", "20-01-01 13:00:00", "20-01-01 14:00:00", "1.00h"],
|
||||
["Test 2", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
];
|
||||
|
||||
export const currentTime = moment("2020-01-01T00:00:00Z");
|
||||
|
||||
export const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(currentTime),
|
||||
endTime: moment(currentTime).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
];
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { defaultSettings } from "@/settings";
|
||||
|
|
@ -7,113 +5,24 @@ import { defaultSettings } from "@/settings";
|
|||
import { createCSV } from "./csv";
|
||||
|
||||
describe("createCSV", () => {
|
||||
it("should create entry table rows", () => {
|
||||
const start = moment("2020-01-01T00:00:00Z");
|
||||
const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
];
|
||||
|
||||
const csv = createCSV({ entries }, defaultSettings, start);
|
||||
expect(csv).toEqual(`Block,Start Time,End time,Duration
|
||||
Test,20-01-01 13:00:00,20-01-01 14:00:00,1.00h
|
||||
Test 2,20-01-01 13:00:00,20-01-01 15:00:00,2.00h`);
|
||||
it("should create entry table rows", async () => {
|
||||
const { entries, currentTime, output } = await import("./__fixtures__/csv/tableRows");
|
||||
const csv = createCSV({ entries }, defaultSettings, currentTime);
|
||||
expect(csv).toEqual(output);
|
||||
});
|
||||
|
||||
it("should flatten group entries", () => {
|
||||
const start = moment("2020-01-01T00:00:00Z");
|
||||
const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const csv = createCSV({ entries }, defaultSettings, start);
|
||||
expect(csv).toEqual(`Block,Start Time,End time,Duration
|
||||
Test,20-01-01 13:00:00,20-01-01 14:00:00,1.00h
|
||||
Test 2,20-01-01 13:00:00,20-01-01 15:00:00,2.00h
|
||||
Test Group,,,2.00h
|
||||
Test 3,20-01-01 13:00:00,20-01-01 15:00:00,2.00h`);
|
||||
it("should flatten group entries", async () => {
|
||||
const { entries, currentTime, output } =
|
||||
await import("./__fixtures__/csv/flattenGroupEntries");
|
||||
const csv = createCSV({ entries }, defaultSettings, currentTime);
|
||||
expect(csv).toEqual(output);
|
||||
});
|
||||
|
||||
it("should use current time for unfinished entries", () => {
|
||||
const start = moment("2020-01-01T00:00:00Z");
|
||||
const currentTime = moment(start).add(2, "hour");
|
||||
const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(start),
|
||||
endTime: null,
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
it("should use current time for unfinished entries", async () => {
|
||||
const { entries, currentTime, output } =
|
||||
await import("./__fixtures__/csv/flattenGroupEntries");
|
||||
|
||||
const csv = createCSV({ entries }, defaultSettings, currentTime);
|
||||
expect(csv).toEqual(`Block,Start Time,End time,Duration
|
||||
Test,20-01-01 13:00:00,20-01-01 14:00:00,1.00h
|
||||
Test 2,20-01-01 13:00:00,20-01-01 15:00:00,2.00h
|
||||
Test Group,,,2.00h
|
||||
Test 3,20-01-01 13:00:00,20-01-01 15:00:00,2.00h`);
|
||||
expect(csv).toEqual(output);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import moment from "moment";
|
||||
import { v4 } from "uuid";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { defaultSettings } from "@/settings";
|
||||
|
|
@ -7,116 +5,24 @@ import { defaultSettings } from "@/settings";
|
|||
import { createRawTable } from ".";
|
||||
|
||||
describe("createRawTable", () => {
|
||||
it("should create entry table rows", () => {
|
||||
const start = moment("2020-01-01T00:00:00Z");
|
||||
const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
];
|
||||
|
||||
const rawTable = createRawTable(entries, defaultSettings, start);
|
||||
expect(rawTable).toEqual([
|
||||
["Test", "20-01-01 13:00:00", "20-01-01 14:00:00", "1.00h"],
|
||||
["Test 2", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
]);
|
||||
it("should create entry table rows", async () => {
|
||||
const { entries, currentTime, output } = await import("./__fixtures__/raw/tableRows");
|
||||
const tableRows = createRawTable(entries, defaultSettings, currentTime);
|
||||
expect(tableRows).toEqual(output);
|
||||
});
|
||||
|
||||
it("should flatten group entries", () => {
|
||||
const start = moment("2020-01-01T00:00:00Z");
|
||||
const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const rawTable = createRawTable(entries, defaultSettings, start);
|
||||
expect(rawTable).toEqual([
|
||||
["Test", "20-01-01 13:00:00", "20-01-01 14:00:00", "1.00h"],
|
||||
["Test 2", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
["Test Group", "", "", "2.00h"],
|
||||
["Test 3", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
]);
|
||||
it("should flatten group entries", async () => {
|
||||
const { entries, currentTime, output } =
|
||||
await import("./__fixtures__/raw/flattenGroupEntries");
|
||||
const tableRows = createRawTable(entries, defaultSettings, currentTime);
|
||||
expect(tableRows).toEqual(output);
|
||||
});
|
||||
|
||||
it("should use current time for unfinished entries", () => {
|
||||
const start = moment("2020-01-01T00:00:00Z");
|
||||
const currentTime = moment(start).add(2, "hour");
|
||||
const entries = [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(1, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 2",
|
||||
startTime: moment(start),
|
||||
endTime: moment(start).add(2, "hour"),
|
||||
subEntries: null,
|
||||
},
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test Group",
|
||||
startTime: null,
|
||||
endTime: null,
|
||||
subEntries: [
|
||||
{
|
||||
id: v4(),
|
||||
name: "Test 3",
|
||||
startTime: moment(start),
|
||||
endTime: null,
|
||||
subEntries: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
it("should use current time for unfinished entries", async () => {
|
||||
const { entries, currentTime, output } =
|
||||
await import("./__fixtures__/raw/flattenGroupEntries");
|
||||
|
||||
const rawTable = createRawTable(entries, defaultSettings, currentTime);
|
||||
expect(rawTable).toEqual([
|
||||
["Test", "20-01-01 13:00:00", "20-01-01 14:00:00", "1.00h"],
|
||||
["Test 2", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
["Test Group", "", "", "2.00h"],
|
||||
["Test 3", "20-01-01 13:00:00", "20-01-01 15:00:00", "2.00h"],
|
||||
]);
|
||||
const tableRows = createRawTable(entries, defaultSettings, currentTime);
|
||||
expect(tableRows).toEqual(output);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
28
src/export/markdown-table.test.ts
Normal file
28
src/export/markdown-table.test.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { defaultSettings } from "@/settings";
|
||||
|
||||
import { createMarkdownTable } from "./markdown-table";
|
||||
|
||||
describe("createMarkdownTable", () => {
|
||||
it("should create entry table rows", async () => {
|
||||
const { entries, currentTime, output } = await import("./__fixtures__/markdown/tableRows");
|
||||
const markdown = createMarkdownTable({ entries }, defaultSettings, currentTime);
|
||||
expect(markdown).toEqual(output);
|
||||
});
|
||||
|
||||
it("should flatten group entries", async () => {
|
||||
const { entries, currentTime, output } =
|
||||
await import("./__fixtures__/markdown/flattenGroupEntries");
|
||||
const markdown = createMarkdownTable({ entries }, defaultSettings, currentTime);
|
||||
expect(markdown).toEqual(output);
|
||||
});
|
||||
|
||||
it("should use current time for unfinished entries", async () => {
|
||||
const { entries, currentTime, output } =
|
||||
await import("./__fixtures__/markdown/flattenGroupEntries");
|
||||
|
||||
const markdown = createMarkdownTable({ entries }, defaultSettings, currentTime);
|
||||
expect(markdown).toEqual(output);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue