Skip to content

Commit

Permalink
Minor fixes from version upgrade (#1093)
Browse files Browse the repository at this point in the history
  • Loading branch information
argaen authored Dec 19, 2024
1 parent 1617c0b commit 145b50e
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 22 deletions.
9 changes: 1 addition & 8 deletions src/__tests__/components/charts/Pie.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ describe('Pie', () => {
borderWidth: 0,
},
},
plugins: {
autocolors: {
mode: 'data',
},
},
plugins: {},
},
type: 'doughnut',
},
Expand Down Expand Up @@ -73,9 +69,6 @@ describe('Pie', () => {
title: {
display: true,
},
autocolors: {
mode: 'data',
},
},
},
type: 'doughnut',
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/components/charts/TotalsPie.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ describe('TotalsPie', () => {
label: expect.any(Function),
},
},
autocolors: {
mode: 'data',
enabled: false,
},
},
},
},
Expand Down Expand Up @@ -147,6 +151,14 @@ describe('TotalsPie', () => {
],
labels: ['Assets', 'Liabilities'],
},
options: expect.objectContaining({
plugins: expect.objectContaining({
autocolors: {
mode: 'data',
enabled: true,
},
}),
}),
}),
undefined,
);
Expand Down
19 changes: 12 additions & 7 deletions src/__tests__/components/pages/account/IEInfo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,38 +51,43 @@ describe('IEInfo', () => {
<IEInfo account={account} />,
);

expect(MonthlyTotalHistogram).toBeCalledWith(
expect(MonthlyTotalHistogram).toHaveBeenCalledWith(
{
guids: [account.guid],
title: '',
},
undefined,
);
expect(TotalWidget).toBeCalledWith(
expect(TotalWidget).toHaveBeenCalledWith(
{ account },
undefined,
);
expect(container).toMatchSnapshot();
});

it('renders as expected when placeholder', () => {
it.each([
['INCOME', 'Total earned'],
['EXPENSE', 'Total spent'],
['EQUITY', 'Total'],
])('renders as expected when placeholder with %s', (type, title) => {
account.placeholder = true;
account.childrenIds = ['1', '2'];
account.type = type;
const { container } = render(
<IEInfo account={account} />,
);

expect(AccountsTable).toBeCalledWith({ guids: ['1', '2'] }, undefined);
expect(TotalsPie).toBeCalledWith(
expect(AccountsTable).toHaveBeenCalledWith({ guids: ['1', '2'] }, undefined);
expect(TotalsPie).toHaveBeenCalledWith(
{
guids: ['1', '2'],
showDataLabels: false,
showTooltip: true,
title: 'Total spent',
title,
},
undefined,
);
expect(MonthlyTotalHistogram).toBeCalledWith(
expect(MonthlyTotalHistogram).toHaveBeenCalledWith(
{
guids: ['1', '2'],
title: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,95 @@ exports[`IEInfo renders as expected when not placeholder 1`] = `
</div>
`;

exports[`IEInfo renders as expected when placeholder 1`] = `
exports[`IEInfo renders as expected when placeholder with EQUITY 1`] = `
<div>
<div
class="grid md:grid-cols-12 items-start"
>
<div
class="grid md:grid-cols-12 auto-cols-fr items-start col-span-6"
>
<div
class="card md:col-span-6"
>
<div
data-testid="TotalsPie"
/>
<div
class="mt-4"
>
<div
data-testid="AccountsTable"
/>
</div>
</div>
<div
class="card md:col-span-6"
/>
</div>
<div
class="col-span-6"
>
<div
class="card"
>
<div
data-testid="MonthlyTotalHistogram"
/>
</div>
<div
class="col-span-12"
/>
</div>
</div>
</div>
`;

exports[`IEInfo renders as expected when placeholder with EXPENSE 1`] = `
<div>
<div
class="grid md:grid-cols-12 items-start"
>
<div
class="grid md:grid-cols-12 auto-cols-fr items-start col-span-6"
>
<div
class="card md:col-span-6"
>
<div
data-testid="TotalsPie"
/>
<div
class="mt-4"
>
<div
data-testid="AccountsTable"
/>
</div>
</div>
<div
class="card md:col-span-6"
/>
</div>
<div
class="col-span-6"
>
<div
class="card"
>
<div
data-testid="MonthlyTotalHistogram"
/>
</div>
<div
class="col-span-12"
/>
</div>
</div>
</div>
`;

exports[`IEInfo renders as expected when placeholder with INCOME 1`] = `
<div>
<div
class="grid md:grid-cols-12 items-start"
Expand Down
5 changes: 0 additions & 5 deletions src/components/charts/Pie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ export const OPTIONS: ChartOptions<'doughnut'> = {
borderWidth: 0,
},
},
plugins: {
autocolors: {
mode: 'data',
},
},
};

export default function Doughnut({
Expand Down
4 changes: 4 additions & 0 deletions src/components/charts/TotalsPie.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export default function TotalsPie({
),
padding: 6,
},
autocolors: {
mode: 'data',
enabled: (backgroundColor?.length || 0) > 0,
},
},
}}
/>
Expand Down
14 changes: 13 additions & 1 deletion src/components/pages/account/IEInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function IEInfo({
&& (
<>
<TotalsPie
title={account.type === 'EXPENSE' ? 'Total spent' : 'Total earned'}
title={getTitle(account.type)}
guids={account.childrenIds}
showTooltip
showDataLabels={false}
Expand Down Expand Up @@ -64,3 +64,15 @@ export default function IEInfo({
</div>
);
}

function getTitle(type: string): string {
if (type === 'INCOME') {
return 'Total earned';
}

if (type === 'EXPENSE') {
return 'Total spent';
}

return 'Total';
}

0 comments on commit 145b50e

Please sign in to comment.