A local-first personal finance app
[AI] Learn category rules from transactions saved on mobile (#9192)
Kristián Valentín952aa2a67074
diff --git a/packages/desktop-client/e2e/transactions.mobile.test.ts b/packages/desktop-client/e2e/transactions.mobile.test.tsindex 4f70cfe0c5..f0a3f67998 100644--- a/packages/desktop-client/e2e/transactions.mobile.test.ts+++ b/packages/desktop-client/e2e/transactions.mobile.test.ts@@ -206,4 +206,36 @@ test.describe('Mobile Transactions', () => {);await expect(page).toMatchThemeScreenshots();});++ test('learns a category rule from new transactions', async () => {+ for (const amount of ['1.00', '2.00', '3.00']) {+ const transactionEntryPage = await navigation.goToTransactionEntryPage();+ await transactionEntryPage.fillAmount(amount);+ // Click anywhere to cancel active edit.+ await transactionEntryPage.header.click();+ await transactionEntryPage.fillField(+ page.getByTestId('payee-field'),+ 'Learned Payee',+ );+ await transactionEntryPage.fillField(+ page.getByTestId('category-field'),+ 'Clothing',+ );+ await transactionEntryPage.fillField(+ page.getByTestId('account-field'),+ 'Ally Savings',+ );+ await transactionEntryPage.createTransaction();+ }++ // The last save is not awaited and the rules page loads rules only on+ // mount, so reload the page until the learned rule shows.+ const rulesPage = await navigation.goToRulesPage();+ await expect(async () => {+ await page.reload();+ await rulesPage.searchFor('Learned Payee');+ await expect(rulesPage.getAllRules()).toHaveCount(1, { timeout: 1000 });+ }).toPass();+ await expect(rulesPage.getNthRule(0)).toContainText('Clothing');+ });});diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsxindex 981fe4997f..4bac7df428 100644--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx@@ -1609,6 +1609,8 @@ function TransactionEditUnconnected({>([]);const isAdding = useRef(false);const isDeleted = useRef(false);+ const [learnCategories = 'true'] = useSyncedPref('learn-categories');+ const isLearnCategoriesEnabled = String(learnCategories) === 'true';const searchParamCategory = useMemo(() => categories.find(c => c.name === searchParams.get('category'))?.id,@@ -1844,6 +1846,7 @@ function TransactionEditUnconnected({added: changes.added,deleted: changes.deleted,updated: changes.updated,+ learnCategories: isLearnCategoriesEnabled,});// if (onTransactionsChange) {@@ -1860,7 +1863,7 @@ function TransactionEditUnconnected({dispatch(setLastTransaction({ transaction: newTransactions[0] }));}},- [dispatch, fetchedTransactions],+ [dispatch, fetchedTransactions, isLearnCategoriesEnabled],);const onDelete = useCallback(diff --git a/upcoming-release-notes/fix-mobile-category-learning.md b/upcoming-release-notes/fix-mobile-category-learning.mdnew file mode 100644index 0000000000..8630d7d1aa--- /dev/null+++ b/upcoming-release-notes/fix-mobile-category-learning.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [kikoval]+---++Fix category learning for transactions entered or edited on mobile