From 77a79c2b3701cf04847da0abd002fe7e46385649 Mon Sep 17 00:00:00 2001 From: Sakariyah Abdulhazeem Date: Sat, 26 Sep 2026 20:46:23 +0100 Subject: [PATCH] test: cover self-freeze confirmation and balance guard --- .../__tests__/SelfFreezeDialog.test.tsx | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/components/common/__tests__/SelfFreezeDialog.test.tsx diff --git a/src/components/common/__tests__/SelfFreezeDialog.test.tsx b/src/components/common/__tests__/SelfFreezeDialog.test.tsx new file mode 100644 index 00000000..efe4c4fa --- /dev/null +++ b/src/components/common/__tests__/SelfFreezeDialog.test.tsx @@ -0,0 +1,55 @@ +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { describe, expect, it, vi } from 'vitest'; +import SelfFreezeDialog from '@/components/common/SelfFreezeDialog'; + +describe('SelfFreezeDialog', () => { + it('requires confirmation and submits the requested freeze amount', async () => { + const user = userEvent.setup(); + const onConfirm = vi.fn(); + + render( + + ); + + expect(screen.getByRole('dialog')).toHaveTextContent( + 'cannot be sold or transferred' + ); + await user.clear(screen.getByTestId('self-freeze-amount')); + await user.type(screen.getByTestId('self-freeze-amount'), '3'); + await user.click(screen.getByTestId('self-freeze-confirm')); + + expect(onConfirm).toHaveBeenCalledWith(3); + }); + + it('prevents freezing more than the liquid balance', async () => { + const user = userEvent.setup(); + + render( + + ); + + const amount = screen.getByTestId('self-freeze-amount'); + await user.clear(amount); + await user.type(amount, '3'); + + expect(screen.getByRole('alert')).toHaveTextContent( + "can't freeze more than your available balance" + ); + expect(screen.getByTestId('self-freeze-confirm')).toBeDisabled(); + }); +});