Skip to content

Commit

Permalink
Merge branch 'master' into orphaned-payees
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-fidd authored Oct 9, 2024
2 parents f7dd313 + 6d122c8 commit 22c76e1
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 16 deletions.
42 changes: 40 additions & 2 deletions packages/desktop-client/e2e/accounts.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join } from 'path';

import { test, expect } from '@playwright/test';

import { ConfigurationPage } from './page-models/configuration-page';
Expand All @@ -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);
Expand All @@ -18,7 +20,7 @@ test.describe('Accounts', () => {
await configurationPage.createTestFile();
});

test.afterAll(async () => {
test.afterEach(async () => {
await page.close();
});

Expand Down Expand Up @@ -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);
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions packages/desktop-client/e2e/data/test.csv
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SectionLabel } from '../../forms';

import { SelectField } from './SelectField';
import { SubLabel } from './SubLabel';
import { stripCsvImportTransaction } from './utils';

export function FieldMappings({
transactions,
Expand All @@ -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 || {};

Expand All @@ -33,45 +33,41 @@ export function FieldMappings({
spacing={1}
style={{ marginTop: 5 }}
>
<View style={{ flex: 1 }}>
<View style={{ flex: 1, marginRight: 10 }}>
<SubLabel title="Date" />
<SelectField
options={options}
value={mappings.date}
style={{ marginRight: 5 }}
onChange={name => onChange('date', name)}
hasHeaderRow={hasHeaderRow}
firstTransaction={transactions[0]}
/>
</View>
<View style={{ flex: 1 }}>
<View style={{ flex: 1, marginRight: 10 }}>
<SubLabel title="Payee" />
<SelectField
options={options}
value={mappings.payee}
style={{ marginRight: 5 }}
onChange={name => onChange('payee', name)}
hasHeaderRow={hasHeaderRow}
firstTransaction={transactions[0]}
/>
</View>
<View style={{ flex: 1 }}>
<View style={{ flex: 1, marginRight: 10 }}>
<SubLabel title="Notes" />
<SelectField
options={options}
value={mappings.notes}
style={{ marginRight: 5 }}
onChange={name => onChange('notes', name)}
hasHeaderRow={hasHeaderRow}
firstTransaction={transactions[0]}
/>
</View>
<View style={{ flex: 1 }}>
<View style={{ flex: 1, marginRight: 10 }}>
<SubLabel title="Category" />
<SelectField
options={options}
value={mappings.category}
style={{ marginRight: 5 }}
onChange={name => onChange('category', name)}
hasHeaderRow={hasHeaderRow}
firstTransaction={transactions[0]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
dateFormats,
parseAmountFields,
parseDate,
stripCsvImportTransaction,
} from './utils';

function getFileType(filepath) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3499.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [UnderKoen]
---

E2E tests for CSV import dialog
6 changes: 6 additions & 0 deletions upcoming-release-notes/3605.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [UnderKoen]
---

Fixes CSV import when CSV contains only 3 columns

0 comments on commit 22c76e1

Please sign in to comment.