Something went wrong. Try again.
Convert CSV banking statements to hledger journals
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import assert from "assert";import { emptyRule, FIELDS, lineOf, shown, valueOf } from "./rule.js";
const fieldFor = (key) => FIELDS.find((field) => field.key === key);
Deno.test("M1-UI-008: a card has a box for each part of a rule, the condition last", () => { assert.deepEqual(FIELDS.map((field) => field.key), ["name", "targetAccount", "sourceAccount", "match"]);});
Deno.test("M1-UI-008: only the source account is optional, and only the condition completes", () => { assert.deepEqual(FIELDS.filter((field) => field.optional).map((field) => field.key), ["sourceAccount"]); assert.deepEqual(FIELDS.filter((field) => field.completes).map((field) => field.key), ["match"]);});
Deno.test("M1-UI-008: an empty source account box means no source account", () => { assert.equal(valueOf(fieldFor("sourceAccount"), ""), null); assert.equal(valueOf(fieldFor("sourceAccount"), "assets:cash"), "assets:cash");});
Deno.test("M1-UI-008: an empty box that is not optional is an empty value", () => { assert.equal(valueOf(fieldFor("targetAccount"), ""), ""); assert.equal(valueOf(fieldFor("name"), ""), "");});
Deno.test("M1-UI-008: no source account shows as an empty box", () => { assert.equal(shown(null), ""); assert.equal(shown("assets:cash"), "assets:cash");});
Deno.test("M1-UI-008: an empty rule has empty boxes and no source account", () => { assert.deepEqual(emptyRule(), { name: "", targetAccount: "", sourceAccount: null, match: "" });});
Deno.test("M1-UI-008: every empty rule is a new one", () => { assert.notEqual(emptyRule(), emptyRule());});
Deno.test("D10: a folded rule reads as its name, target account and condition", () => { const rule = { name: "rent", targetAccount: "expenses:rent", sourceAccount: null, match: 'text == "Miete"' }; assert.deepEqual(lineOf(rule), { name: "rent", target: "expenses:rent", match: 'text == "Miete"' });});
Deno.test("D10: a rule with no name says so", () => { assert.equal(lineOf(emptyRule()).name, "(unnamed rule)");});