From 57df510b70ea9de281d2ce7b940a2e1da123390d Mon Sep 17 00:00:00 2001 From: PJ Date: Sat, 25 Apr 2026 19:55:19 +0700 Subject: [PATCH] fix(folio): guard newAccountBalanceIsZero against navigation false positives Scoped selectors return [] when not on HomeScreen so accounts vanish and reappear as apparently-new on each visit. Skip the check when prev was empty. --- examples/folio/sanderling/spec.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/folio/sanderling/spec.ts b/examples/folio/sanderling/spec.ts index 7604768..cda5597 100644 --- a/examples/folio/sanderling/spec.ts +++ b/examples/folio/sanderling/spec.ts @@ -74,10 +74,16 @@ const accountCards = extract(s => s.ax.findAll("desc:HomeScreen > descPrefix:acc const backButton = extract(s => s.ax.find("desc:Back")); // Property 1: every new account starts with balance === 0 +// Guard: only check when accounts were visible in the previous step too. +// Without this, navigating away from HomeScreen (accounts=[]) then back +// makes every account look "new", causing false positives on pre-existing balances. const newAccountBalanceIsZero = always( next(() => { - const prevIds = new Set((accounts.previous ?? []).map(a => a.id)); - const newAccounts = accounts.current.filter(a => !prevIds.has(a.id)); + const prev = accounts.previous ?? []; + const curr = accounts.current; + if (prev.length === 0 || curr.length === 0) return true; + const prevIds = new Set(prev.map(a => a.id)); + const newAccounts = curr.filter(a => !prevIds.has(a.id)); return newAccounts.every(a => a.balance === 0); }) );