fix: default account charts to user currency (#271)
## Summary - default account charts to the user's currency when a currency toggle is available - reverse the account chart currency toggle order so the user currency appears first - add a focused frontend test covering the toggle order and selected state ## Testing - npm test -- chart-currency-toggle
This commit is contained in:
parent
0735ee6d69
commit
38cf672c8e
|
|
@ -359,8 +359,7 @@ export function AccountBalanceChart({
|
|||
const isLoan = account.type === 'loan';
|
||||
const isRealEstate = isRealEstateAccount(account);
|
||||
const [granularity, setGranularity] = useState<ChartGranularity>('monthly');
|
||||
const [currencyMode, setCurrencyMode] =
|
||||
useState<ChartCurrencyMode>('account');
|
||||
const [currencyMode, setCurrencyMode] = useState<ChartCurrencyMode>('user');
|
||||
const [balanceData, setBalanceData] = useState<AccountBalanceData | null>(
|
||||
null,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { ChartCurrencyToggle } from './chart-currency-toggle';
|
||||
|
||||
describe('ChartCurrencyToggle', () => {
|
||||
it('renders user currency before account currency', () => {
|
||||
render(
|
||||
<ChartCurrencyToggle
|
||||
value="user"
|
||||
onValueChange={vi.fn()}
|
||||
userCurrencyCode="USD"
|
||||
accountCurrencyCode="EUR"
|
||||
showTooltip={false}
|
||||
/>,
|
||||
);
|
||||
|
||||
const buttons = screen.getAllByRole('radio');
|
||||
|
||||
expect(buttons).toHaveLength(2);
|
||||
expect(buttons[0]).toHaveTextContent('USD');
|
||||
expect(buttons[1]).toHaveTextContent('EUR');
|
||||
expect(buttons[0]).toHaveAttribute('data-state', 'on');
|
||||
});
|
||||
});
|
||||
|
|
@ -31,13 +31,6 @@ export function ChartCurrencyToggle({
|
|||
label: string;
|
||||
tooltip: string;
|
||||
}> = [
|
||||
{
|
||||
mode: 'account',
|
||||
label: accountCurrencyCode,
|
||||
tooltip: __('Show in account currency (:currency)', {
|
||||
currency: accountCurrencyCode,
|
||||
}),
|
||||
},
|
||||
{
|
||||
mode: 'user',
|
||||
label: userCurrencyCode,
|
||||
|
|
@ -45,6 +38,13 @@ export function ChartCurrencyToggle({
|
|||
currency: userCurrencyCode,
|
||||
}),
|
||||
},
|
||||
{
|
||||
mode: 'account',
|
||||
label: accountCurrencyCode,
|
||||
tooltip: __('Show in account currency (:currency)', {
|
||||
currency: accountCurrencyCode,
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in New Issue