mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
fix(spec): replace desc-parsing with text-based parseDollarCents extraction
This commit is contained in:
1 parent
1089f1a166
commit
b31997b9e4
1 file changed
+24
-21
@@ -20,20 +20,13 @@ interface LedgerRow {
|
|||||||
signed: number;
|
signed: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseAccount(desc: string | undefined): Account {
|
// Parses formatCents output like "$5.00", "-$1,234.56", "+$0.50" back to integer cents.
|
||||||
const parts = (desc ?? "").split(":");
|
// formatCents always uses $ prefix, . as decimal, , as thousands separator.
|
||||||
return { id: parts[1] ?? "", balance: Number(parts[2]) };
|
function parseDollarCents(text: string | undefined): number {
|
||||||
}
|
if (!text) return 0;
|
||||||
|
const sign = text.startsWith("-") ? -1 : 1;
|
||||||
function parseLedgerRow(desc: string | undefined): LedgerRow {
|
const digits = text.replace(/[^0-9]/g, "");
|
||||||
const parts = (desc ?? "").split(":");
|
return digits ? sign * parseInt(digits, 10) : 0;
|
||||||
return { id: parts[1] ?? "", signed: Number(parts[2]) };
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseCents(desc: string | null | undefined): number {
|
|
||||||
if (!desc) return 0;
|
|
||||||
const parts = desc.split(":");
|
|
||||||
return Number(parts[1]) || 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route and auth state derived from screen root nodes
|
// Route and auth state derived from screen root nodes
|
||||||
@@ -49,15 +42,25 @@ const route = extract<string | null>(s => {
|
|||||||
|
|
||||||
// All element lookups scoped through their screen root
|
// All element lookups scoped through their screen root
|
||||||
const accounts = extract(s =>
|
const accounts = extract(s =>
|
||||||
s.ax.find({ accessibilityText: "HomeScreen" })?.findAll("descPrefix:account:")
|
s.ax.find({ accessibilityText: "HomeScreen" })?.findAll("descPrefix:account_card:")
|
||||||
.map(el => parseAccount(el.desc)) ?? []);
|
.map(el => ({
|
||||||
|
id: el.desc?.split(":")[1] ?? "",
|
||||||
|
balance: parseDollarCents(el.find({ accessibilityText: "account_balance" })?.text),
|
||||||
|
})) ?? []);
|
||||||
const ledgerRows = extract(s =>
|
const ledgerRows = extract(s =>
|
||||||
s.ax.find({ accessibilityText: "LedgerScreen" })?.findAll("descPrefix:ledger_row:")
|
s.ax.find({ accessibilityText: "LedgerScreen" })?.findAll("descPrefix:ledger_row:")
|
||||||
.map(el => parseLedgerRow(el.desc)) ?? []);
|
.map(el => ({
|
||||||
|
id: el.desc?.split(":")[1] ?? "",
|
||||||
|
signed: parseDollarCents(el.find({ accessibilityText: "txn_amount" })?.text),
|
||||||
|
})) ?? []);
|
||||||
const ledgerBalance = extract(s =>
|
const ledgerBalance = extract(s =>
|
||||||
parseCents(s.ax.find({ accessibilityText: "LedgerScreen" })?.find("descPrefix:ledger_balance:")?.desc));
|
parseDollarCents(
|
||||||
const activeAccountId = extract(s =>
|
s.ax.find({ accessibilityText: "LedgerScreen" })?.find({ accessibilityText: "ledger_balance_display" })?.text
|
||||||
s.ax.find({ accessibilityText: "LedgerScreen" })?.find("descPrefix:active_account:")?.desc?.split(":")[1] ?? null);
|
));
|
||||||
|
const activeAccountId = extract(s => {
|
||||||
|
const desc = s.ax.find("descPrefix:LedgerScreen:")?.desc;
|
||||||
|
return desc ? (desc.split(":")[1] ?? null) : null;
|
||||||
|
});
|
||||||
|
|
||||||
// focusedInput lives in the app root (not inside any screen), so unscoped
|
// focusedInput lives in the app root (not inside any screen), so unscoped
|
||||||
const focusedInput = extract(s =>
|
const focusedInput = extract(s =>
|
||||||
@@ -82,7 +85,7 @@ const txnAmountField = extract(s =>
|
|||||||
const txnSubmit = extract(s =>
|
const txnSubmit = extract(s =>
|
||||||
s.ax.find({ accessibilityText: "AddTransactionScreen" })?.find({ accessibilityText: "txn_submit" }));
|
s.ax.find({ accessibilityText: "AddTransactionScreen" })?.find({ accessibilityText: "txn_submit" }));
|
||||||
const accountCards = extract(s =>
|
const accountCards = extract(s =>
|
||||||
s.ax.find({ accessibilityText: "HomeScreen" })?.findAll("descPrefix:account:") ?? []);
|
s.ax.find({ accessibilityText: "HomeScreen" })?.findAll("descPrefix:account_card:") ?? []);
|
||||||
const backButton = extract(s => s.ax.find("desc:Back"));
|
const backButton = extract(s => s.ax.find("desc:Back"));
|
||||||
|
|
||||||
// Property 1: every new account starts with balance === 0
|
// Property 1: every new account starts with balance === 0
|
||||||
|
|||||||
Reference in new issue
Block a user