diff --git a/packages/desktop-client/e2e/accounts.test.js b/packages/desktop-client/e2e/accounts.test.js index c7e0d02219f..eb83edaf160 100644 --- a/packages/desktop-client/e2e/accounts.test.js +++ b/packages/desktop-client/e2e/accounts.test.js @@ -1,3 +1,5 @@ +import { join } from 'path'; + import { test, expect } from '@playwright/test'; import { ConfigurationPage } from './page-models/configuration-page'; @@ -9,7 +11,7 @@ test.describe('Accounts', () => { let configurationPage; let accountPage; - test.beforeAll(async ({ browser }) => { + test.beforeEach(async ({ browser }) => { page = await browser.newPage(); navigation = new Navigation(page); configurationPage = new ConfigurationPage(page); @@ -18,7 +20,7 @@ test.describe('Accounts', () => { await configurationPage.createTestFile(); }); - test.afterAll(async () => { + test.afterEach(async () => { await page.close(); }); @@ -99,4 +101,40 @@ test.describe('Accounts', () => { await expect(transaction.account).toHaveText('Ally Savings'); }); }); + + test.describe('Import Transactions', () => { + test.beforeEach(async () => { + accountPage = await navigation.createAccount({ + name: 'CSV import', + offBudget: false, + balance: 0, + }); + }); + + async function importCsv(screenshot = false) { + const fileChooserPromise = page.waitForEvent('filechooser'); + await accountPage.page.getByRole('button', { name: 'Import' }).click(); + + const fileChooser = await fileChooserPromise; + await fileChooser.setFiles(join(__dirname, 'data/test.csv')); + + if (screenshot) await expect(page).toMatchThemeScreenshots(); + + const importButton = accountPage.page.getByRole('button', { + name: /Import \d+ transactions/, + }); + await importButton.click(); + + await expect(importButton).not.toBeVisible(); + } + + test('imports transactions from a CSV file', async () => { + await importCsv(true); + }); + + test('import csv file twice', async () => { + await importCsv(false); + await importCsv(true); + }); + }); }); diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-1-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-1-chromium-linux.png new file mode 100644 index 00000000000..d6d043c53d4 Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-1-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-2-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-2-chromium-linux.png new file mode 100644 index 00000000000..ec7958f9acf Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-2-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-3-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-3-chromium-linux.png new file mode 100644 index 00000000000..95d28c64771 Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-import-csv-file-twice-3-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-1-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-1-chromium-linux.png new file mode 100644 index 00000000000..3fc95842ffc Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-1-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-2-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-2-chromium-linux.png new file mode 100644 index 00000000000..94332d6efe8 Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-2-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-3-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-3-chromium-linux.png new file mode 100644 index 00000000000..b82756952fa Binary files /dev/null and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-Import-Transactions-imports-transactions-from-a-CSV-file-3-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-1-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-1-chromium-linux.png index ff035988802..9a4c890ee5c 100644 Binary files a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-1-chromium-linux.png and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-1-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-2-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-2-chromium-linux.png index 8a51b293a72..8cc790234d6 100644 Binary files a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-2-chromium-linux.png and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-2-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-3-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-3-chromium-linux.png index d5b4b30c7f1..fcac4066d85 100644 Binary files a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-3-chromium-linux.png and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-3-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-4-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-4-chromium-linux.png index 8b0146d47af..481278c731d 100644 Binary files a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-4-chromium-linux.png and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-4-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-5-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-5-chromium-linux.png index fa10b0415bd..c021b255e95 100644 Binary files a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-5-chromium-linux.png and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-5-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-6-chromium-linux.png b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-6-chromium-linux.png index dfd30f5f2fd..e9588ed6384 100644 Binary files a/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-6-chromium-linux.png and b/packages/desktop-client/e2e/accounts.test.js-snapshots/Accounts-closes-an-account-6-chromium-linux.png differ diff --git a/packages/desktop-client/e2e/data/test.csv b/packages/desktop-client/e2e/data/test.csv new file mode 100644 index 00000000000..022d65f739f --- /dev/null +++ b/packages/desktop-client/e2e/data/test.csv @@ -0,0 +1,9 @@ +Date,Payee,Notes,Category,Amount +2024-08-02,Deposit,test 1,Income,1787.76 +2024-07-02,Deposit,test 2,Income,1787.76 +2024-06-02,Deposit,test 3,Income,1787.76 +2024-05-02,Deposit,test 4,Income,1787.76 +2024-04-02,Deposit,test 5,Income,1787.76 +2024-03-02,Deposit,test 6,Income,1787.76 +2024-02-02,Deposit,test 7,Income,1787.76 +2024-01-02,Starting Balance,test 8,Starting Balances,-330000 diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx index b4de3f32617..b57e651dce7 100644 --- a/packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/FieldMappings.jsx @@ -6,6 +6,7 @@ import { SectionLabel } from '../../forms'; import { SelectField } from './SelectField'; import { SubLabel } from './SubLabel'; +import { stripCsvImportTransaction } from './utils'; export function FieldMappings({ transactions, @@ -19,8 +20,7 @@ export function FieldMappings({ return null; } - const { existing, ignored, selected, selected_merge, trx_id, ...trans } = - transactions[0]; + const trans = stripCsvImportTransaction(transactions[0]); const options = Object.keys(trans); mappings = mappings || {}; @@ -33,45 +33,41 @@ export function FieldMappings({ spacing={1} style={{ marginTop: 5 }} > - + onChange('date', name)} hasHeaderRow={hasHeaderRow} firstTransaction={transactions[0]} /> - + onChange('payee', name)} hasHeaderRow={hasHeaderRow} firstTransaction={transactions[0]} /> - + onChange('notes', name)} hasHeaderRow={hasHeaderRow} firstTransaction={transactions[0]} /> - + onChange('category', name)} hasHeaderRow={hasHeaderRow} firstTransaction={transactions[0]} diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx b/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx index 903957ed4e8..d7325279b79 100644 --- a/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/ImportTransactionsModal.jsx @@ -29,6 +29,7 @@ import { dateFormats, parseAmountFields, parseDate, + stripCsvImportTransaction, } from './utils'; function getFileType(filepath) { @@ -59,7 +60,7 @@ function getInitialMappings(transactions) { return {}; } - const transaction = transactions[0]; + const transaction = stripCsvImportTransaction(transactions[0]); const fields = Object.entries(transaction); function key(entry) { diff --git a/packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js b/packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js index 094f862e5b2..da881f10bba 100644 --- a/packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js +++ b/packages/desktop-client/src/components/modals/ImportTransactionsModal/utils.js @@ -185,3 +185,10 @@ export function parseAmountFields( inflow: null, }; } + +export function stripCsvImportTransaction(transaction) { + const { existing, ignored, selected, selected_merge, trx_id, ...trans } = + transaction; + + return trans; +} diff --git a/packages/loot-core/src/server/accounts/rules.ts b/packages/loot-core/src/server/accounts/rules.ts index 2778f00cdf7..f67aa04b88c 100644 --- a/packages/loot-core/src/server/accounts/rules.ts +++ b/packages/loot-core/src/server/accounts/rules.ts @@ -443,12 +443,12 @@ export class Condition { if (fieldValue === null) { return false; } - return fieldValue.indexOf(this.value) !== -1; + return String(fieldValue).indexOf(this.value) !== -1; case 'doesNotContain': if (fieldValue === null) { return false; } - return fieldValue.indexOf(this.value) === -1; + return String(fieldValue).indexOf(this.value) === -1; case 'oneOf': if (fieldValue === null) { return false; @@ -459,7 +459,7 @@ export class Condition { if (fieldValue === null) { return false; } - return fieldValue.indexOf(this.value) !== -1; + return String(fieldValue).indexOf(this.value) !== -1; case 'notOneOf': if (fieldValue === null) { diff --git a/upcoming-release-notes/3499.md b/upcoming-release-notes/3499.md new file mode 100644 index 00000000000..ef1ecb26486 --- /dev/null +++ b/upcoming-release-notes/3499.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [UnderKoen] +--- + +E2E tests for CSV import dialog diff --git a/upcoming-release-notes/3605.md b/upcoming-release-notes/3605.md new file mode 100644 index 00000000000..7d6b6306a00 --- /dev/null +++ b/upcoming-release-notes/3605.md @@ -0,0 +1,6 @@ +--- +category: Bugfix +authors: [UnderKoen] +--- + +Fixes CSV import when CSV contains only 3 columns