diff --git a/packages/desktop-client/e2e/page-models/account-page.js b/packages/desktop-client/e2e/page-models/account-page.js index 6edf858856038313f520340f0358fded24194775..c4fb469323d9d9373f74fd726afa5b12f1bc056a 100644 --- a/packages/desktop-client/e2e/page-models/account-page.js +++ b/packages/desktop-client/e2e/page-models/account-page.js @@ -141,6 +141,18 @@ export class AccountPage { } async _fillTransactionFields(transactionRow, transaction) { + if (transaction.debit) { + await transactionRow.getByTestId('debit').click(); + await this.page.keyboard.type(transaction.debit); + await this.page.keyboard.press('Tab'); + } + + if (transaction.credit) { + await transactionRow.getByTestId('credit').click(); + await this.page.keyboard.type(transaction.credit); + await this.page.keyboard.press('Tab'); + } + if (transaction.account) { await transactionRow.getByTestId('account').click(); await this.page.keyboard.type(transaction.account); @@ -169,18 +181,6 @@ export class AccountPage { await this.page.keyboard.press('Tab'); } } - - if (transaction.debit) { - await transactionRow.getByTestId('debit').click(); - await this.page.keyboard.type(transaction.debit); - await this.page.keyboard.press('Tab'); - } - - if (transaction.credit) { - await transactionRow.getByTestId('credit').click(); - await this.page.keyboard.type(transaction.credit); - await this.page.keyboard.press('Tab'); - } } } diff --git a/packages/desktop-client/e2e/page-models/rules-page.js b/packages/desktop-client/e2e/page-models/rules-page.js index c1228bbd0e14bf768fbe92c0e773bac1d0aed692..b8cee63d3434e94f51071c595d2af98032cef55f 100644 --- a/packages/desktop-client/e2e/page-models/rules-page.js +++ b/packages/desktop-client/e2e/page-models/rules-page.js @@ -61,6 +61,27 @@ export class RulesPage { this.page.getByTestId('action-list'), ); } + + if (data.splits) { + if (data.splits.beforeSplitActions) { + await this._fillEditorFields( + data.splits.beforeSplitActions, + this.page.getByTestId('action-list'), + ); + } + + if (data.splits.splitActions) { + let idx = data.splits?.beforeSplitActions.length ?? 0; + for (const splitActions of data.splits.splitActions) { + await this.page.getByTestId('add-split-transactions').click(); + await this._fillEditorFields( + splitActions, + this.page.getByTestId('action-list').nth(idx), + ); + idx++; + } + } + } } async _fillEditorFields(data, rootElement) { diff --git a/packages/desktop-client/e2e/page-models/settings-page.js b/packages/desktop-client/e2e/page-models/settings-page.js index b24bb18b09bb58e3c41700936baf1f967d307675..3b42dabbd31b6bc595f114b4cf74e8c9136ab14a 100644 --- a/packages/desktop-client/e2e/page-models/settings-page.js +++ b/packages/desktop-client/e2e/page-models/settings-page.js @@ -6,4 +6,10 @@ export class SettingsPage { async exportData() { await this.page.getByRole('button', { name: 'Export data' }).click(); } + + async enableExperimentalFeature(featureName) { + await this.page.getByTestId('advanced-settings').click(); + await this.page.getByTestId('experimental-settings').click(); + await this.page.getByLabel(featureName).check(); + } } diff --git a/packages/desktop-client/e2e/rules.test.js b/packages/desktop-client/e2e/rules.test.js index 4de98db6dfb2c25e16dce688397c2473e996b746..69f5238fbd1e80c098cfaf9cf71a8e84275fa6d7 100644 --- a/packages/desktop-client/e2e/rules.test.js +++ b/packages/desktop-client/e2e/rules.test.js @@ -67,4 +67,78 @@ test.describe('Rules', () => { await expect(transaction.debit).toHaveText('12.34'); await expect(page).toMatchThemeScreenshots(); }); + + test('creates a split transaction rule and makes sure it is applied when creating a transaction', async () => { + const settingsPage = await navigation.goToSettingsPage(); + await settingsPage.enableExperimentalFeature('splits in rules'); + + await expect(settingsPage.page.getByLabel('splits in rules')).toBeChecked(); + + rulesPage = await navigation.goToRulesPage(); + + await rulesPage.createRule({ + conditions: [ + { + field: 'payee', + op: 'is', + value: 'Ikea', + }, + ], + splits: { + beforeSplitActions: [ + { + field: 'notes', + value: 'food / entertainment', + }, + ], + splitActions: [ + [ + { + field: 'a fixed percent', + value: '90', + }, + { + field: 'category', + value: 'Entertainment', + }, + ], + [ + { + field: 'an equal portion of the remainder', + }, + { + field: 'category', + value: 'Food', + }, + ], + ], + }, + }); + + const accountPage = await navigation.goToAccountPage( + 'Capital One Checking', + ); + + await accountPage.createSingleTransaction({ + debit: '100.00', + payee: 'Ikea', + }); + + const transaction = accountPage.getNthTransaction(0); + await expect(transaction.payee).toHaveText('Ikea'); + await expect(transaction.notes).toHaveText('food / entertainment'); + await expect(transaction.category).toHaveText('Split'); + await expect(transaction.debit).toHaveText('100.00'); + await expect(page).toMatchThemeScreenshots(); + + const firstSplitTransaction = accountPage.getNthTransaction(1); + await expect(firstSplitTransaction.payee).toHaveText('Ikea'); + await expect(firstSplitTransaction.debit).toHaveText('90.00'); + await expect(firstSplitTransaction.category).toHaveText('Entertainment'); + + const secondSplitTransaction = accountPage.getNthTransaction(2); + await expect(secondSplitTransaction.payee).toHaveText('Ikea'); + await expect(secondSplitTransaction.debit).toHaveText('10.00'); + await expect(secondSplitTransaction.category).toHaveText('Food'); + }); }); diff --git a/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-1-chromium-linux.png b/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-1-chromium-linux.png new file mode 100644 index 0000000000000000000000000000000000000000..edf3dfbd4bdea94d2cef81b0149f6b715e1899c8 Binary files /dev/null and b/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-1-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-2-chromium-linux.png b/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-2-chromium-linux.png new file mode 100644 index 0000000000000000000000000000000000000000..889e2f34364ddfe384321b89f6ff051055978e0a Binary files /dev/null and b/packages/desktop-client/e2e/rules.test.js-snapshots/Rules-creates-a-split-transaction-rule-and-makes-sure-it-is-applied-when-creating-a-transaction-2-chromium-linux.png differ diff --git a/packages/desktop-client/src/components/modals/EditRule.jsx b/packages/desktop-client/src/components/modals/EditRule.jsx index 54b76c2cf589584ff4af7fa337fbb220f0215f47..bbd547ddf228e6067050df24f75b398238b69281 100644 --- a/packages/desktop-client/src/components/modals/EditRule.jsx +++ b/packages/desktop-client/src/components/modals/EditRule.jsx @@ -1085,6 +1085,7 @@ export function EditRule({ modalProps, defaultRule, onSave: originalOnSave }) { onClick={() => { addActionToSplitAfterIndex(actionSplits.length, -1); }} + data-testid="add-split-transactions" > {actionSplits.length > 1 ? 'Add another split' diff --git a/packages/desktop-client/src/components/settings/Experimental.tsx b/packages/desktop-client/src/components/settings/Experimental.tsx index 36da6b40c6298a303da62802ed696c22e480027e..ef0a99b1096735f18a34d9d933564ba2b4eca080 100644 --- a/packages/desktop-client/src/components/settings/Experimental.tsx +++ b/packages/desktop-client/src/components/settings/Experimental.tsx @@ -93,6 +93,7 @@ export function ExperimentalFeatures() { <Link variant="text" onClick={() => setExpanded(true)} + data-testid="experimental-settings" style={{ flexShrink: 0, alignSelf: 'flex-start', diff --git a/packages/desktop-client/src/components/settings/UI.tsx b/packages/desktop-client/src/components/settings/UI.tsx index c5c85830214e314102d5055fd3e72fe9189268ce..ad835e43c43a2696f0ce0dded309d1b11c3dfbf8 100644 --- a/packages/desktop-client/src/components/settings/UI.tsx +++ b/packages/desktop-client/src/components/settings/UI.tsx @@ -79,6 +79,7 @@ export const AdvancedToggle = ({ children }: AdvancedToggleProps) => { <Link variant="text" onClick={() => setExpanded(true)} + data-testid="advanced-settings" style={{ flexShrink: 0, alignSelf: 'flex-start', diff --git a/upcoming-release-notes/2604.md b/upcoming-release-notes/2604.md new file mode 100644 index 0000000000000000000000000000000000000000..95de28fdc84af410528925a5298ceaff02071677 --- /dev/null +++ b/upcoming-release-notes/2604.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [marethyu1] +--- + +Adds integration test for experimental split rules functionality