Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: tests #595

Merged
merged 17 commits into from
Oct 10, 2024
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"test:renderer": "vitest run -r packages/renderer --passWithNoTests",
"watch": "node scripts/watch.js",
"lint": "eslint . --ext js,mjs,cjs,ts,mts,cts,tsx",
"lint:fix": "eslint . --fix --ext js,mjs,cjs,ts,mts,cts,tsx",
"typecheck:main": "tsc --noEmit -p packages/main/tsconfig.json",
"typecheck:preload": "tsc --noEmit -p packages/preload/tsconfig.json",
"typecheck:renderer": "tsc --noEmit -p packages/renderer/tsconfig.json",
Expand Down Expand Up @@ -61,7 +62,8 @@
"typescript": "5.4.5",
"unplugin-auto-expose": "0.3.0",
"vite": "5.2.14",
"vitest": "^2.0.5"
"vite-tsconfig-paths": "^5.0.1",
"vitest": "^2.1.1"
},
"dependencies": {
"@puppeteer/browsers": "^2.2.3",
Expand Down Expand Up @@ -92,6 +94,8 @@
"react-bootstrap-table2-editor": "^1.4.0",
"react-bootstrap-typeahead": "^6.3.2",
"react-dom": "^18.3.1",
"svelte": "^4.2.19",
"vite-plugin-node-polyfills": "^0.22.0",
"web-vitals": "^4.2.0",
"ynab": "^1.19.0"
}
Expand Down
2 changes: 0 additions & 2 deletions packages/preload/src/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface JsonConfig extends OutputVendorConfigBase {
export interface GoogleSheetsConfig extends OutputVendorConfigBase {
options: {
credentials: Credentials;
// credentials: string;
spreadsheetId: string;
};
}
Expand All @@ -82,7 +81,6 @@ export interface YnabConfig extends OutputVendorConfigBase {

export interface AccountToScrapeConfig {
id: string;
// key: CompanyTypes;
key: string;
name: string;
loginFields: Record<string, string>;
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"env": {
"browser": true,
"node": false
"node": true
},
"extends": ["plugin:react-hooks/recommended"],
"parserOptions": {
Expand Down
6 changes: 3 additions & 3 deletions packages/renderer/src/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { render, screen } from '@testing-library/react';
import { expect, test } from 'vitest';
import App from './App';

test('renders learn react link', () => {
test('renders discord link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
const linkElement = screen.getByText(/ערוץ הדיסקורד שלנו/i);
expect(linkElement).to.exist;
});
2 changes: 1 addition & 1 deletion packages/renderer/src/components/accounts/Importers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../types';
import Account, { type ActionButton } from './Account';
import NewAccount from './NewAccount';
import { useConfigStore } from '/@/store/ConfigStore';
import { useConfigStore } from '../../store/ConfigStore';

interface ImportersProps {
accounts: AccountType[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { showSaveDialog } from '#preload';
import { observer } from 'mobx-react-lite';
import React, { useState } from 'react';
import { Button, Card, Form, Image } from 'react-bootstrap';
import { type Exporter } from '../../types';
import { type Exporter } from '/@/types';
import styles from './EditFileExporter.module.css';

interface EditFileExporterProps {
Expand Down
26 changes: 14 additions & 12 deletions packages/renderer/src/components/exporters/EditYnabExporter.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { toJS } from 'mobx';
import { observer } from 'mobx-react-lite';
import { useEffect, useState } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { Button, Card, Form, Image } from 'react-bootstrap';
import Spinner from 'react-bootstrap/Spinner';
import { type YnabConfig } from '../../types';
import styles from './EditYnabExporter.module.css';

import YnabAccountMappingTable from './YnabAccountMappingTable';
import { useStore } from '/@/store';
import { useStore } from '../../store';

interface EditYnabExporterProps {
handleSave: (exporterConfig: YnabConfig) => Promise<void>;
Expand Down Expand Up @@ -37,22 +37,24 @@ const EditYnabExporter = ({
if (!ynabOptions.budgetId && defaultBudgetId) {
updateOptionsState({ budgetId: defaultBudgetId });
}
}, [store.ynabAccountData, ynabOptions.budgetId]);
}, [store.ynabAccountData, ynabOptions.budgetId, updateOptionsState]);

useEffect(() => {
if (ynabOptions.accessToken) {
store.fetchYnabAccountData(ynabOptions);
}
}, [ynabOptions.budgetId, ynabOptions.accessToken, store]);
}, [ynabOptions, store]);

const updateOptionsState = useCallback(
(optionUpdates: Partial<YnabConfig['options']>) => {
setYnabOptions((prevYnabOptions) => ({
...prevYnabOptions,
...optionUpdates,
}));
},
[],
);

const updateOptionsState = (
optionUpdates: Partial<YnabConfig['options']>,
) => {
setYnabOptions({
...ynabOptions,
...optionUpdates,
});
};
const handleSaveClick = async () => {
await handleSave({
...exporterConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Button, Col, Form, Modal, Row, Stack } from 'react-bootstrap';
import { isValidEmail } from '../../utils/validations';
import { getZIndexes } from '../../utils/zIndexesManager';
import LogsCanvas from './LogsCanvas';
import { useAppInfoStore } from '/@/store';
import { useAppInfoStore } from '../../store';

const NUM_OF_LAST_LINES = 10;

Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/src/components/topBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import logo from '../../assets/logoFishOnly.svg';
import NavButton from './NavButton';
import ReportProblemModal from './ReportProblemModal';
import styles from './TopBar.module.css';
import { useAppInfoStore } from '/@/store';
import { useAppInfoStore } from '../../store';

function TopBar() {
const [show, setShow] = useState(false);
Expand Down
4 changes: 4 additions & 0 deletions packages/renderer/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const MOCK_ELECTRON = {
invoke: () => {},
send: () => {},
},
shell: {
openExternal: () => {},
openPath: () => {},
},
};

// @ts-expect-error - this is a mock
Expand Down
3 changes: 2 additions & 1 deletion packages/renderer/src/store/ConfigStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type Importer,
type Log,
type OutputVendorName,
type DownalodChromeEvent,
} from '../types';

interface AccountScrapingData {
Expand Down Expand Up @@ -68,7 +69,7 @@ const saveConfigIntoFile = (config?: Config) => {
updateConfig(toJS(config));
};

class ConfigStore {
export class ConfigStore {
config: Config;

chromeDownloadPercent = 0;
Expand Down
50 changes: 20 additions & 30 deletions packages/renderer/src/store/Store.test.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { dummyConfig } from '../test/testData';
import Store from './Store';
import { type ConfigStore, configStore } from './ConfigStore';
import {
AccountType,
CompanyTypes,
type Config,
type Credentials,
type Exporter,
type Importer,
} from './types';
} from '../types';
import { beforeEach, describe, test, expect } from 'vitest';

describe('Store', () => {
let store;
let store: ConfigStore;
beforeEach(() => {
store = new Store();
store.configuration = dummyConfig;
store = configStore;
store.config = dummyConfig;
});
describe('Properties and getters', () => {
test('basic', () => {
const basicStore = new Store();
expect(basicStore.config).not.toBeDefined();
const basicStore = configStore;

basicStore.configuration = dummyConfig;
basicStore.config = dummyConfig;

expect(basicStore.config).toMatchObject(dummyConfig);

Expand All @@ -30,12 +30,14 @@ describe('Store', () => {
expect(store.importers).toHaveLength(3);

const discountImporter = store.importers.find(
(i) => i.companyId === 'discount',
(i: Importer) => i.companyId === 'discount',
);
const visaCalImporter = store.importers.find(
(i) => i.companyId === 'visaCal',
(i: Importer) => i.companyId === 'visaCal',
);
const maxImporter = store.importers.find(
(i: Importer) => i.companyId === 'max',
);
const maxImporter = store.importers.find((i) => i.companyId === 'max');

expect(discountImporter).toMatchSnapshot();
expect(visaCalImporter).toMatchSnapshot();
Expand All @@ -47,15 +49,6 @@ describe('Store', () => {
expect(store.exporters).toMatchSnapshot();
});

test('allAccounts', () => {
expect(store.allAccounts).toHaveLength(
store.importers.length + store.exporters.length,
);
[...store.importers, ...store.exporters].forEach((account) =>
expect(store.allAccounts).toContainEqual(account),
);
});

test('settings', () => {
expect(store.settings.numDaysBack).toEqual(
dummyConfig.scraping.numDaysBack,
Expand All @@ -80,11 +73,9 @@ describe('Store', () => {
type: AccountType.IMPORTER,
active: false,
};
expect(store.allAccountsById.get(accountToAdd.id)).toBeFalsy();
const originalImportersLength = store.importers.length;
store.addImporter(accountToAdd);
expect(store.importers).toHaveLength(originalImportersLength + 1);
expect(store.allAccountsById.get(accountToAdd.id)).toMatchSnapshot();
});

test('updateImporter', () => {
Expand All @@ -95,7 +86,7 @@ describe('Store', () => {
};
store.updateImporter(importer.id, updatedImporter);
expect(
store.importers.find((i) => i.id === importer.id),
store.importers.find((i: Importer) => i.id === importer.id),
).toHaveProperty('active', updatedImporter.active);
});

Expand All @@ -104,10 +95,8 @@ describe('Store', () => {
const originalNumImporters =
dummyConfig.scraping.accountsToScrape.length;
expect(store.importers).toHaveLength(originalNumImporters);
expect(store.allAccountsById.get(importer.id)).toBeTruthy();
store.deleteImporter(importer.id);
expect(store.importers).toHaveLength(originalNumImporters - 1);
expect(store.allAccountsById.get(importer.id)).toBeFalsy();
});
});
describe('exporters', () => {
Expand All @@ -133,7 +122,7 @@ export const dummyConfig: Config = {
accountsToScrape: [
{
active: true,
key: 'discount',
key: CompanyTypes.DISCOUNT,
name: 'Discount Bank',
loginFields: {
id: '234234134',
Expand All @@ -144,7 +133,7 @@ export const dummyConfig: Config = {
},
{
active: true,
key: 'visaCal',
key: CompanyTypes.VISACAL,
name: 'Visa Cal',
loginFields: {
username: 'someUsername',
Expand All @@ -154,7 +143,7 @@ export const dummyConfig: Config = {
},
{
active: true,
key: 'max',
key: CompanyTypes.MAX,
name: 'Max',
loginFields: {
username: 'whatAUserName',
Expand All @@ -163,6 +152,7 @@ export const dummyConfig: Config = {
id: '9xve2485ac202f53f85bcdb4f795dssc',
},
],
timeout: 0,
},
outputVendors: {
csv: {
Expand Down Expand Up @@ -193,8 +183,8 @@ export const dummyConfig: Config = {
googleSheets: {
active: false,
options: {
credentials: '',
spreadsheetId: '',
credentials: {} as Credentials,
},
},
},
Expand Down
Loading
Loading