diff --git a/packages/ui-components/src/__tests__/DepositButtons.test.ts b/packages/ui-components/src/__tests__/DepositButtons.test.ts new file mode 100644 index 000000000..cb67694fe --- /dev/null +++ b/packages/ui-components/src/__tests__/DepositButtons.test.ts @@ -0,0 +1,88 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { render, fireEvent } from '@testing-library/svelte'; +import DepositButtons from '../lib/components/deployment/wizard/DepositButtons.svelte'; +import type { GuiDeposit } from '@rainlanguage/orderbook/js_api'; +import type { ComponentProps } from 'svelte'; + +type DepositButtonsProps = ComponentProps; + +describe('DepositButtons', () => { + const mockGui = { + isDepositPreset: vi.fn(), + saveDeposit: vi.fn() + }; + + const mockTokenInfos = new Map([ + ['0x123', { name: 'Test Token', symbol: 'TEST' }] + ]); + + const mockDeposit: GuiDeposit = { + token: { address: '0x123' }, + token_name: 'TEST', + presets: ['100', '200', '300'] + } as unknown as GuiDeposit + + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('renders token name and presets', () => { + const { getByText } = render(DepositButtons, { + props: { + deposit: mockDeposit, + gui: mockGui, + tokenInfos: mockTokenInfos + } as unknown as DepositButtonsProps + }); + + expect(getByText('Test Token')).toBeTruthy(); + expect(getByText('100')).toBeTruthy(); + expect(getByText('200')).toBeTruthy(); + expect(getByText('300')).toBeTruthy(); + expect(getByText('Custom')).toBeTruthy(); + }); + + it('handles preset button clicks', async () => { + const { getByText } = render(DepositButtons, { + props: { + deposit: mockDeposit, + gui: mockGui, + tokenInfos: mockTokenInfos + } as unknown as DepositButtonsProps + }); + + await fireEvent.click(getByText('100')); + expect(mockGui.saveDeposit).toHaveBeenCalledWith('TEST', '100'); + }); + + it('shows custom input when Custom button is clicked', async () => { + const { getByText, getByPlaceholderText } = render(DepositButtons, { + props: { + deposit: mockDeposit, + gui: mockGui, + tokenInfos: mockTokenInfos + } as unknown as DepositButtonsProps + }); + + await fireEvent.click(getByText('Custom')); + expect(getByPlaceholderText('Enter deposit amount')).toBeTruthy(); + expect(mockGui.saveDeposit).toHaveBeenCalledWith('TEST', ''); + }); + + it('handles custom input changes', async () => { + mockGui.isDepositPreset.mockReturnValue(false); + + const { getByPlaceholderText } = render(DepositButtons, { + props: { + deposit: mockDeposit, + gui: mockGui, + tokenInfos: mockTokenInfos + } as unknown as DepositButtonsProps + }); + + const input = getByPlaceholderText('Enter deposit amount'); + await fireEvent.input(input, { target: { value: '150' } }); + + expect(mockGui.saveDeposit).toHaveBeenCalledWith('TEST', '150'); + }); +}); \ No newline at end of file diff --git a/packages/ui-components/src/lib/components/deployment/wizard/DeploymentSteps.svelte b/packages/ui-components/src/lib/components/deployment/wizard/DeploymentSteps.svelte index c03ea68c6..6616eac27 100644 --- a/packages/ui-components/src/lib/components/deployment/wizard/DeploymentSteps.svelte +++ b/packages/ui-components/src/lib/components/deployment/wizard/DeploymentSteps.svelte @@ -7,7 +7,7 @@ import type { DotrainOrderGui, - GuiDeposit, + TokenDeposit, GuiFieldDefinition, SelectTokens, TokenInfos, @@ -22,7 +22,7 @@ export let allFieldDefinitions: GuiFieldDefinition[]; export let allTokenInputs: Vault[]; export let allTokenOutputs: Vault[]; - export let allDeposits: GuiDeposit[]; + export let allDeposits: TokenDeposit[]; export let inputVaultIds: string[]; export let outputVaultIds: string[]; export let isLimitStrat: boolean;