diff --git a/pages/accountLists/[accountListId]/reports/financialAccounts/[[...financialAccount]].page.test.tsx b/pages/accountLists/[accountListId]/reports/financialAccounts/[[...financialAccount]].page.test.tsx index dd032cc244..d93066e796 100644 --- a/pages/accountLists/[accountListId]/reports/financialAccounts/[[...financialAccount]].page.test.tsx +++ b/pages/accountLists/[accountListId]/reports/financialAccounts/[[...financialAccount]].page.test.tsx @@ -26,6 +26,13 @@ const defaultRouter = { query: { accountListId }, isReady: true, }; +const entriesRouter = { + query: { + accountListId, + financialAccount: [financialAccountId, 'entries'], + }, + isReady: true, +}; const Components = ({ router = defaultRouter }: { router?: object }) => ( @@ -85,17 +92,7 @@ describe('Financial Accounts Page', () => { it('should show the transactions page for a financial account', async () => { const { findByText, findByRole, getByText, queryByText, queryByRole } = - render( - , - ); + render(); expect(await findByText('Account 1')).toBeInTheDocument(); @@ -112,17 +109,7 @@ describe('Financial Accounts Page', () => { }); it('should open filters on load and set initial date Range filter', async () => { - const { findByRole } = render( - , - ); + const { findByRole } = render(); expect( await findByRole('heading', { name: 'Filter (1)' }), @@ -131,15 +118,7 @@ describe('Financial Accounts Page', () => { it('should open and close filters and menu', async () => { const { findByRole, getByRole, queryByRole } = render( - , + , ); // Filters diff --git a/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.test.tsx b/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.test.tsx index 08ac0fb3e8..0b2936960f 100644 --- a/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.test.tsx +++ b/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.test.tsx @@ -3,6 +3,7 @@ import { ThemeProvider } from '@mui/material/styles'; import { LocalizationProvider } from '@mui/x-date-pickers'; import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon'; import { fireEvent, render, waitFor } from '@testing-library/react'; +import { Settings } from 'luxon'; import { SnackbarProvider } from 'notistack'; import { I18nextProvider } from 'react-i18next'; import TestRouter from '__tests__/util/TestRouter'; @@ -20,11 +21,7 @@ import { FinancialAccountContext, FinancialAccountType, } from '../Context/FinancialAccountsContext'; -import { - AccountTransactions, - defaultEndDate, - defaultStartDate, -} from './AccountTransactions'; +import { AccountTransactions } from './AccountTransactions'; import { financialAccountEntriesMock } from './AccountTransactionsMocks'; import { FinancialAccountEntriesQuery } from './financialAccountTransactions.generated'; @@ -96,6 +93,9 @@ const Components = ({ ); describe('Financial Account Transactions', () => { + beforeEach(() => { + Settings.now = () => new Date(2024, 7, 31).valueOf(); + }); describe('Resetting filters', () => { it('should reset the activeFilters with the filters from the url filters', () => { render( @@ -113,8 +113,8 @@ describe('Financial Account Transactions', () => { expect(setActiveFilters).not.toHaveBeenCalledWith({ dateRange: { - min: defaultStartDate, - max: defaultEndDate, + min: '2024-08-01', + max: '2024-08-31', }, }); @@ -129,8 +129,8 @@ describe('Financial Account Transactions', () => { expect(setActiveFilters).toHaveBeenCalledWith({ dateRange: { - min: defaultStartDate, - max: defaultEndDate, + min: '2024-08-01', + max: '2024-08-31', }, }); }); @@ -143,6 +143,7 @@ describe('Financial Account Transactions', () => { expect(getAllByText('category1Code')).toHaveLength(2); // Header + expect(getByText('8/31/2024')).toBeInTheDocument(); expect(getByText('Closing Balance')).toBeInTheDocument(); expect(getByText('UAH 280,414')).toBeInTheDocument(); @@ -165,6 +166,7 @@ describe('Financial Account Transactions', () => { expect(getByText('UAH 37')).toBeInTheDocument(); // Footer + expect(getByText('8/1/2024')).toBeInTheDocument(); expect(getByText('Opening Balance')).toBeInTheDocument(); expect(getByText('UAH 202,240')).toBeInTheDocument(); @@ -312,9 +314,9 @@ describe('Financial Account Transactions', () => { const csvContentArray = [ ['Date', 'Payee', 'Memo', 'Outflow', 'Inflow'], - ['8/9/2024', 'description1', 'category1Name', '', 'UAH 7,048'], - ['8/8/2024', 'description2', 'category1Name', 'UAH 15,008', ''], - ['8/7/2024', 'description3', 'category2Name', '', 'UAH 37'], + ['8/9/2024', 'description1', 'category1Name', '', '7047.28'], + ['8/8/2024', 'description2', 'category1Name', '15008', ''], + ['8/7/2024', 'description3', 'category2Name', '', '36.2'], ]; const csvContent = diff --git a/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.tsx b/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.tsx index 2d6f872c0e..ff161a4beb 100644 --- a/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.tsx +++ b/src/components/Reports/FinancialAccountsReport/AccountTransactions/AccountTransactions.tsx @@ -42,7 +42,7 @@ const formatAmountForExport = ( if (amount === '0' || isExpense) { return Number(amount); } - return amount?.[0] === '-' ? Number(amount.substring(1)) : -Number(amount); + return -Number(amount); }; const formatDateRange = (startDate?: DateTime, endDate?: DateTime) => { @@ -55,10 +55,6 @@ const formatDateRange = (startDate?: DateTime, endDate?: DateTime) => { return `${startDate.toISODate()}..${endDate.toISODate()}`; }; -const defaultDateRange = formatDateRange(); -export const defaultStartDate = defaultDateRange.split('..')[0]; -export const defaultEndDate = defaultDateRange.split('..')[1]; - export const AccountTransactions: React.FC = () => { const { query } = useRouter(); const { t } = useTranslation(); @@ -87,6 +83,10 @@ export const AccountTransactions: React.FC = () => { }; }, [query?.filters]); + const defaultDateRange = useMemo(() => formatDateRange(), []); + const defaultStartDate = defaultDateRange.split('..')[0]; + const defaultEndDate = defaultDateRange.split('..')[1]; + useEffect(() => { if (!hasActiveFilters && !query?.filters) { setActiveFilters({