Skip to content

A local-first personal finance app

Add VRT test for validating that split transaction rules work as expected (#2604)

Stefan Hall464c9de6fb02
diff --git a/packages/desktop-client/e2e/page-models/account-page.js b/packages/desktop-client/e2e/page-models/account-page.js
index 6edf858856..c4fb469323 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 c1228bbd0e..b8cee63d34 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 b24bb18b09..3b42dabbd3 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 4de98db6df..69f5238fbd 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 0000000000..edf3dfbd4b
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 0000000000..889e2f3436
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 54b76c2cf5..bbd547ddf2 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 36da6b40c6..ef0a99b109 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 c5c8583021..ad835e43c4 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 0000000000..95de28fdc8
--- /dev/null
+++ b/upcoming-release-notes/2604.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [marethyu1]
+---
+
+Adds integration test for experimental split rules functionality