chore(MarketTransactions): Add some assertions to the component.

This commit is contained in:
a.bouhuolia 2022-06-05 16:41:49 +02:00
parent 48f8995e74
commit 66beba4235
5 changed files with 73 additions and 30 deletions

View file

@ -15,18 +15,19 @@
// ============================================================================= // =============================================================================
import { useMemo } from "react"; import { useMemo } from "react";
import type { FormatNumberOptions } from "react-intl";
import { useIntl } from "react-intl"; import { useIntl } from "react-intl";
type CurrencyFormatType = "symbol" | "code" | "name" | "narrowSymbol"; type CurrencyFormatType = "symbol" | "code" | "name" | "narrowSymbol";
interface CurrencyProps { interface CurrencyProps extends FormatNumberOptions {
currencyCode?: string; currencyCode?: string;
currentDisplay?: CurrencyFormatType; currentDisplay?: CurrencyFormatType;
value: number; value: number;
} }
export function Currency(props: CurrencyProps) { export function Currency(props: CurrencyProps) {
const { currencyCode, currentDisplay, value } = props; const { currencyCode, currentDisplay, value, ...formatNumberProps } = props;
const intl = useIntl(); const intl = useIntl();
const formattedNumber = useMemo( const formattedNumber = useMemo(
@ -43,6 +44,7 @@ export function Currency(props: CurrencyProps) {
minimumFractionDigits: 2, minimumFractionDigits: 2,
maximumFractionDigits: 12, maximumFractionDigits: 12,
}), }),
...formatNumberProps,
}), }),
[currencyCode, value] [currencyCode, value]
); );

View file

@ -63,8 +63,8 @@ describe("molecules::MarketTransactionsTable", () => {
<MarketTransactionsTable data={data} /> <MarketTransactionsTable data={data} />
</AppProviders> </AppProviders>
); );
expect(screen.queryByText("7,564.94 XMR")).toBeInTheDocument(); expect(screen.queryByText("XMR 7,564.94")).toBeInTheDocument();
expect(screen.queryByText("6,483.23 XMR")).toBeInTheDocument(); expect(screen.queryByText("XMR 6,483.23")).toBeInTheDocument();
unmount(); unmount();
}); });
@ -89,6 +89,16 @@ describe("molecules::MarketTransactionsTable", () => {
expect(screen.queryByText("1,212")).toBeInTheDocument(); expect(screen.queryByText("1,212")).toBeInTheDocument();
unmount(); unmount();
}); });
it("renders offer formatted payment method.", () => {
const { unmount } = render(
<AppProviders>
<MarketTransactionsTable data={data} />
</AppProviders>
);
expect(screen.queryByText("Cash by mail")).toBeInTheDocument();
unmount();
});
}); });
const data = [ const data = [
@ -112,7 +122,7 @@ const data = [
amountCurrency: "XMR", amountCurrency: "XMR",
cost: 983.32, cost: 983.32,
costCurrency: "USD", costCurrency: "USD",
paymentMethod: MarketTransactionPaymentMethod.CashByMail, paymentMethod: MarketTransactionPaymentMethod.Other,
accountAge: 12, accountAge: 12,
accountTrades: 3412, accountTrades: 3412,
}, },

View file

@ -90,7 +90,7 @@ export function MarketTransactionsAccountTradesCell({
}) { }) {
return ( return (
<BodyText heavy> <BodyText heavy>
<Currency value={row?.accountTrades || 0} /> <Currency value={row?.accountTrades || 0} minimumFractionDigits={0} />
</BodyText> </BodyText>
); );
} }

View file

@ -1,9 +1,9 @@
// Vitest Snapshot v1 // Vitest Snapshot v1
exports[`organisms::MarketTransactions > renders without exploding. 1`] = ` exports[`molecules::MarketTransactionsTable > renders without exploding. 1`] = `
<DocumentFragment> <DocumentFragment>
<table <table
class="mantine-Table-root mantine-ydlwhr" class="mantine-Table-root mantine-19hj5t7"
> >
<thead> <thead>
<tr> <tr>
@ -51,7 +51,7 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
style="width: 400px;" style="width: 400px;"
> >
<div <div
class="mantine-Group-root mantine-6y1794" class="mantine-Group-root mantine-1lumg83"
> >
<div <div
class="mantine-Text-root mantine-Group-child mantine-1h17kkk" class="mantine-Text-root mantine-Group-child mantine-1h17kkk"
@ -59,7 +59,7 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
€5,000.96 €5,000.96
</div> </div>
<div <div
class="mantine-Text-root mantine-Group-child mantine-zvhzrs" class="mantine-Text-root mantine-Group-child mantine-1qscdi2"
> >
-1% -1%
</div> </div>
@ -68,7 +68,11 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
<td <td
style="width: 400px;" style="width: 400px;"
> >
XMR 7,564.94 <div
class="mantine-Text-root mantine-ix3vgq"
>
XMR 7,564.94
</div>
</td> </td>
<td <td
style="width: 400px;" style="width: 400px;"
@ -82,21 +86,33 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
<td <td
style="width: 400px;" style="width: 400px;"
> >
ASD <div
class="mantine-Text-root mantine-ix3vgq"
>
Cash by mail
</div>
</td> </td>
<td <td
style="width: 400px;" style="width: 400px;"
> >
<div <div
class="mantine-Group-root mantine-6y1794" class="mantine-Group-root mantine-1lumg83"
> >
<div <svg
class="mantine-ThemeIcon-root mantine-Group-child mantine-11491oq" class="mantine-gnzaph mantine-Group-child"
fill="none"
height="15"
viewBox="0 0 15 15"
width="15"
xmlns="http://www.w3.org/2000/svg"
> >
X <path
</div> d="M7.5 0C3.36316 0 0 3.36316 0 7.5C0 11.6368 3.36316 15 7.5 15C11.6368 15 15 11.6368 15 7.5C15 3.36316 11.6368 0 7.5 0ZM11.1316 5.81053L6.82105 10.5632C6.71053 10.6895 6.50526 10.6895 6.37895 10.5789L3.69474 7.87895C3.56842 7.75263 3.56842 7.56316 3.69474 7.45263L4.48421 6.66316C4.61053 6.53684 4.8 6.53684 4.91053 6.66316L6.55263 8.32105L9.86842 4.65789C9.97895 4.53158 10.1684 4.53158 10.2947 4.64211L11.1158 5.38421C11.2421 5.49474 11.2421 5.68421 11.1316 5.81053Z"
fill="#0B65DA"
/>
</svg>
<div <div
class="mantine-Text-root mantine-Group-child mantine-1xtm85p" class="mantine-Text-root mantine-Group-child mantine-1h17kkk"
> >
65 Days 65 Days
</div> </div>
@ -108,7 +124,7 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
<div <div
class="mantine-Text-root mantine-ix3vgq" class="mantine-Text-root mantine-ix3vgq"
> >
1,212.00 1,212
</div> </div>
</td> </td>
</tr> </tr>
@ -117,7 +133,7 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
style="width: 400px;" style="width: 400px;"
> >
<div <div
class="mantine-Group-root mantine-6y1794" class="mantine-Group-root mantine-1lumg83"
> >
<div <div
class="mantine-Text-root mantine-Group-child mantine-1h17kkk" class="mantine-Text-root mantine-Group-child mantine-1h17kkk"
@ -125,7 +141,7 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
€9,637.41 €9,637.41
</div> </div>
<div <div
class="mantine-Text-root mantine-Group-child mantine-zvhzrs" class="mantine-Text-root mantine-Group-child mantine-1qscdi2"
> >
-1% -1%
</div> </div>
@ -134,7 +150,11 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
<td <td
style="width: 400px;" style="width: 400px;"
> >
XMR 6,483.23 <div
class="mantine-Text-root mantine-ix3vgq"
>
XMR 6,483.23
</div>
</td> </td>
<td <td
style="width: 400px;" style="width: 400px;"
@ -148,21 +168,31 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
<td <td
style="width: 400px;" style="width: 400px;"
> >
ASD <div
class="mantine-Text-root mantine-ix3vgq"
/>
</td> </td>
<td <td
style="width: 400px;" style="width: 400px;"
> >
<div <div
class="mantine-Group-root mantine-6y1794" class="mantine-Group-root mantine-1lumg83"
> >
<div <svg
class="mantine-ThemeIcon-root mantine-Group-child mantine-11491oq" class="mantine-gnzaph mantine-Group-child"
fill="none"
height="15"
viewBox="0 0 15 15"
width="15"
xmlns="http://www.w3.org/2000/svg"
> >
X <path
</div> d="M7.5 0C3.36316 0 0 3.36316 0 7.5C0 11.6368 3.36316 15 7.5 15C11.6368 15 15 11.6368 15 7.5C15 3.36316 11.6368 0 7.5 0ZM11.1316 5.81053L6.82105 10.5632C6.71053 10.6895 6.50526 10.6895 6.37895 10.5789L3.69474 7.87895C3.56842 7.75263 3.56842 7.56316 3.69474 7.45263L4.48421 6.66316C4.61053 6.53684 4.8 6.53684 4.91053 6.66316L6.55263 8.32105L9.86842 4.65789C9.97895 4.53158 10.1684 4.53158 10.2947 4.64211L11.1158 5.38421C11.2421 5.49474 11.2421 5.68421 11.1316 5.81053Z"
fill="#0B65DA"
/>
</svg>
<div <div
class="mantine-Text-root mantine-Group-child mantine-1xtm85p" class="mantine-Text-root mantine-Group-child mantine-1h17kkk"
> >
65 Days 65 Days
</div> </div>
@ -174,7 +204,7 @@ exports[`organisms::MarketTransactions > renders without exploding. 1`] = `
<div <div
class="mantine-Text-root mantine-ix3vgq" class="mantine-Text-root mantine-ix3vgq"
> >
3,412.00 3,412
</div> </div>
</td> </td>
</tr> </tr>

View file

@ -29,4 +29,5 @@ export interface MarketTransaction {
export enum MarketTransactionPaymentMethod { export enum MarketTransactionPaymentMethod {
CashByMail = "CashByMail", CashByMail = "CashByMail",
Other = "Other",
} }