mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 12:07:09 +00:00
feat(folio-spec): wire submitMovesBalanceByTypedAmount property
Adds lastAction and totalBalance extractors and uses them in the new property. Drops ledgerRows/ledgerBalance extractors since nothing else referenced them.
This commit is contained in:
1 parent
7a2f03e67f
commit
2397a65b9f
1 file changed
+26
-26
@@ -5,14 +5,12 @@ import {
|
|||||||
always,
|
always,
|
||||||
extract,
|
extract,
|
||||||
from,
|
from,
|
||||||
keyedBy,
|
|
||||||
next,
|
next,
|
||||||
now,
|
|
||||||
weighted,
|
weighted,
|
||||||
whenRoute,
|
whenRoute,
|
||||||
} from "@sanderling/spec";
|
} from "@sanderling/spec";
|
||||||
import { defaultActions } from "@sanderling/spec/defaults";
|
import { defaultActions } from "@sanderling/spec/defaults";
|
||||||
import { balanceMatchesAddedSum, type LedgerRow } from "./predicates";
|
import { submitChangesBalanceByTypedAmount } from "./predicates";
|
||||||
|
|
||||||
interface Account {
|
interface Account {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -45,15 +43,20 @@ const accounts = extract<Account[]>("accounts", s =>
|
|||||||
balance: parseDollarCents(card.find({ testTag: "AccountBalance" })?.text),
|
balance: parseDollarCents(card.find({ testTag: "AccountBalance" })?.text),
|
||||||
})));
|
})));
|
||||||
|
|
||||||
// Ledger rows: identity composed from the row's stable testTag'd cells.
|
// Total balance: sum of AccountCard balances visible on Home plus the
|
||||||
const ledgerRows = extract<LedgerRow[]>("ledgerRows", s =>
|
// LedgerBalance shown on Ledger. Both screens read the same DB, so summing
|
||||||
s.ax.findAll([{ testTag: "LedgerScreen" }, { testTag: "LedgerRow" }]).map(row => ({
|
// across whichever screen is visible gives the same authoritative number.
|
||||||
key: keyedBy(row, ["TxnDate", "TxnNote", "TxnAmount"]),
|
const totalBalance = extract("totalBalance", s => {
|
||||||
signed: parseDollarCents(row.find({ testTag: "TxnAmount" })?.text),
|
const cards = s.ax.findAll([{ testTag: "HomeScreen" }, { testTag: "AccountCard" }]);
|
||||||
})));
|
const cardSum = cards.reduce(
|
||||||
|
(sum, c) => sum + parseDollarCents(c.find({ testTag: "AccountBalance" })?.text),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
const ledgerBal = parseDollarCents(s.ax.find({ testTag: "LedgerBalance" })?.text);
|
||||||
|
return cardSum + ledgerBal;
|
||||||
|
});
|
||||||
|
|
||||||
const ledgerBalance = extract("ledgerBalance", s =>
|
const lastAction = extract("lastAction", s => s.lastAction);
|
||||||
parseDollarCents(s.ax.find({ testTag: "LedgerBalance" })?.text));
|
|
||||||
|
|
||||||
const loginEmailField = extract("loginEmailField", s =>
|
const loginEmailField = extract("loginEmailField", s =>
|
||||||
s.ax.find([{ testTag: "LoginScreen" }, { testTag: "LoginEmail" }]));
|
s.ax.find([{ testTag: "LoginScreen" }, { testTag: "LoginEmail" }]));
|
||||||
@@ -89,20 +92,17 @@ const newAccountBalanceIsZero = always(
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Property 2: when new ledger rows appear, the balance delta equals the SUM
|
// Property 2: a tap on TxnSubmit must move the total balance by exactly the
|
||||||
// of the new rows' signed amounts. Single-row and multi-row sums both must
|
// typed amount. A double-submit lands two transactions, so the balance shifts
|
||||||
// match; a double-submit lands two rows whose total is twice the balance
|
// by twice the typed amount and the check fires.
|
||||||
// change and trips the sum check.
|
const submitMovesBalanceByTypedAmount = always(
|
||||||
const balanceMatchesAddedTxn = always(
|
next(() =>
|
||||||
now(() => route.current === "ledger").implies(
|
submitChangesBalanceByTypedAmount({
|
||||||
next(() =>
|
lastAction: lastAction.current,
|
||||||
balanceMatchesAddedSum(
|
typedAmount: parseDollarCents(txnAmountField.previous?.text),
|
||||||
ledgerRows.previous ?? [],
|
prevTotalBalance: totalBalance.previous ?? 0,
|
||||||
ledgerRows.current,
|
currTotalBalance: totalBalance.current,
|
||||||
ledgerBalance.previous ?? 0,
|
}),
|
||||||
ledgerBalance.current,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ const addTxn = whenRoute(route, ["home", "ledger", "add-transaction"], () => {
|
|||||||
|
|
||||||
export const properties = {
|
export const properties = {
|
||||||
newAccountBalanceIsZero,
|
newAccountBalanceIsZero,
|
||||||
balanceMatchesAddedTxn,
|
submitMovesBalanceByTypedAmount,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setup = login;
|
export const setup = login;
|
||||||
|
|||||||
Reference in new issue
Block a user