-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c435a4c
commit 33ba188
Showing
2 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
packages/ui-components/src/__tests__/DepositButtons.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DepositButtons>; | ||
|
||
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters