import { click, visit } from "@ember/test-helpers"; import { test } from "qunit"; import { cloneJSON } from "discourse/lib/object"; import topicFixtures from "discourse/tests/fixtures/topic"; import { acceptance } from "discourse/tests/helpers/qunit-helpers"; const TOPIC_ID = 28830; const accountsReport = { report_type: "accounts", period: { begin: null, end: null }, sections: [ { title: null, rows: [ { account: "assets:bank", depth: 1, amounts: [ { commodity: "EUR", quantity: "1000.0", display: "1000.00 EUR" }, ], }, ], total: [{ commodity: "EUR", quantity: "1000.0", display: "1000.00 EUR" }], }, ], net: null, meta: { hledger_version: "1.52.1" }, }; const equityReport = { report_type: "equity", period: { begin: null, end: null }, groups: [ { commodity: "EUR", total: { commodity: "EUR", quantity: "1000.0", display: "1000.0 EUR" }, holders: [ { holder: "alice", amount: { commodity: "EUR", quantity: "600.0", display: "600.0 EUR" }, percentage: "60.00", }, { holder: "bob", amount: { commodity: "EUR", quantity: "400.0", display: "400.0 EUR" }, percentage: "40.00", }, ], }, ], meta: { hledger_version: "1.52.1" }, }; acceptance("Hledger plugin", function (needs) { needs.settings({ hledger_enabled: true }); needs.pretender((server, helper) => { server.get("/t/45.json", () => { const topic = cloneJSON(topicFixtures["/t/28830/1.json"]); topic.post_stream.posts[0].cooked = `
`; return helper.response(topic); }); server.get(`/hledger/topics/${TOPIC_ID}/reports/accounts`, () => helper.response(accountsReport) ); server.get(`/hledger/topics/${TOPIC_ID}/reports/equity`, () => helper.response(equityReport) ); }); test("renders the dashboard in place of the journal", async function (assert) { await visit("/t/-/45"); assert.dom(".hledger-dashboard__toolbar .btn").exists({ count: 4 }); assert .dom(".hledger-dashboard__toolbar .btn:nth-of-type(1)") .hasText("Accounts"); assert .dom(".hledger-dashboard__toolbar .btn:nth-of-type(2)") .hasText("Balance sheet"); assert .dom(".hledger-dashboard__toolbar .btn:nth-of-type(3)") .hasText("Income statement"); assert .dom(".hledger-dashboard__toolbar .btn:nth-of-type(4)") .hasText("Equity"); assert.dom(".hledger-dashboard__table").includesText("Total"); assert.dom(".hledger-dashboard__table").includesText("assets:bank"); assert.dom(".hledger-dashboard__table").includesText("1000.00 EUR"); }); test("switches to the equity distribution", async function (assert) { await visit("/t/-/45"); await click(".hledger-dashboard__toolbar .btn:nth-of-type(4)"); assert.dom(".hledger-dashboard__table").includesText("alice"); assert.dom(".hledger-dashboard__table").includesText("60.00%"); }); });