Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasheriques committed Jan 12, 2025
1 parent f4d26a0 commit 176fb32
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/app/gerador-de-invoice/invoice-generator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ const localStorageMock = (() => {
};
})();

// Mock ResizeObserver
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));

// Mock window.matchMedia
Object.defineProperty(window, "matchMedia", {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});

Object.defineProperty(window, "localStorage", { value: localStorageMock });

// Mock URL.createObjectURL
Expand Down
4 changes: 3 additions & 1 deletion src/app/gerador-de-invoice/invoice-generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ export default function InvoiceGenerator() {
</Select>
<div className="text-xl font-semibold flex gap-4 items-center">
<span className="text-slate-400">Total:</span>
<span data-testid="total">{formatCurrency(total, currency)}</span>
<span data-testid="total">
{formatCurrency(total, currency, "en-US")}
</span>
</div>
</div>

Expand Down
5 changes: 3 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ export function cn(...inputs: ClassValue[]) {

export function formatCurrency(
amount: number | string,
currency: CurrencyCode = "BRL"
currency: CurrencyCode = "BRL",
locale: string = "pt-BR"
) {
const value = typeof amount === "string" ? parseFloat(amount) : amount;
return new Intl.NumberFormat("pt-BR", {
return new Intl.NumberFormat(locale, {
style: "currency",
currency,
}).format(value);
Expand Down

0 comments on commit 176fb32

Please sign in to comment.