Avoid duplicate and stale report requests
This commit is contained in:
@@ -260,6 +260,8 @@ const transactionsReport = {
|
||||
acceptance("Hledger plugin", function (needs) {
|
||||
needs.settings({ hledger_enabled: true });
|
||||
|
||||
const requestCounts = { accounts: 0, equity: 0 };
|
||||
|
||||
needs.pretender((server, helper) => {
|
||||
server.get("/t/45.json", () => {
|
||||
const topic = cloneJSON(topicFixtures["/t/28830/1.json"]);
|
||||
@@ -267,12 +269,14 @@ acceptance("Hledger plugin", function (needs) {
|
||||
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)
|
||||
);
|
||||
server.get(`/hledger/topics/${TOPIC_ID}/reports/accounts`, () => {
|
||||
requestCounts.accounts++;
|
||||
return helper.response(accountsReport);
|
||||
});
|
||||
server.get(`/hledger/topics/${TOPIC_ID}/reports/equity`, () => {
|
||||
requestCounts.equity++;
|
||||
return helper.response(equityReport);
|
||||
});
|
||||
server.get(`/hledger/topics/${TOPIC_ID}/reports/balance_sheet`, () =>
|
||||
helper.response(balanceSheetReport)
|
||||
);
|
||||
@@ -452,6 +456,24 @@ acceptance("Hledger plugin", function (needs) {
|
||||
.hasText("Server");
|
||||
});
|
||||
|
||||
test("does not issue duplicate requests for the same report", async function (assert) {
|
||||
requestCounts.accounts = 0;
|
||||
requestCounts.equity = 0;
|
||||
|
||||
await visit("/t/-/45");
|
||||
|
||||
assert.strictEqual(requestCounts.accounts, 1, "loads accounts once");
|
||||
|
||||
await click(".hledger-dashboard__toolbar .btn:nth-of-type(4)");
|
||||
assert.strictEqual(requestCounts.equity, 1, "loads equity once");
|
||||
|
||||
await click(".hledger-dashboard__toolbar .btn:nth-of-type(4)");
|
||||
assert.strictEqual(requestCounts.equity, 1, "ignores the current report");
|
||||
|
||||
await click(".hledger-dashboard__toolbar .btn:nth-of-type(1)");
|
||||
assert.strictEqual(requestCounts.accounts, 2, "reloads on report change");
|
||||
});
|
||||
|
||||
test("shows the transaction log", async function (assert) {
|
||||
await visit("/t/-/45");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user