-
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
ab58f58
commit c435a4c
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
packages/ui-components/src/__tests__/DepositDropdown.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,95 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { render, fireEvent } from '@testing-library/svelte'; | ||
import DepositDropdown from '../lib/components/deployment/DepositDropdown.svelte'; | ||
import type { DotrainOrderGui, GuiDeposit } from '@rainlanguage/orderbook/js_api'; | ||
|
||
describe('DepositDropdown', () => { | ||
const mockTokenInfos = new Map(); | ||
mockTokenInfos.set('0x123', { name: 'Test Token' }); | ||
|
||
const mockDeposit: GuiDeposit = { | ||
token: { address: '0x123' }, | ||
token_name: 'TEST', | ||
presets: ['100', '200', '300'] | ||
} as unknown as GuiDeposit; | ||
|
||
const mockGui = { | ||
saveDeposit: vi.fn(), | ||
isDepositPreset: vi.fn() | ||
}; | ||
|
||
it('renders token name correctly', () => { | ||
const { getByText } = render(DepositDropdown, { | ||
props: { | ||
deposit: mockDeposit, | ||
gui: mockGui as unknown as DotrainOrderGui, | ||
tokenInfos: mockTokenInfos | ||
} | ||
}); | ||
|
||
expect(getByText('Test Token')).toBeTruthy(); | ||
}); | ||
|
||
it('shows "Choose deposit amount" by default', () => { | ||
const { getByText } = render(DepositDropdown, { | ||
props: { | ||
deposit: mockDeposit, | ||
gui: mockGui as unknown as DotrainOrderGui, | ||
tokenInfos: mockTokenInfos | ||
} | ||
}); | ||
|
||
expect(getByText('Choose deposit amount')).toBeTruthy(); | ||
}); | ||
|
||
it('calls saveDeposit when preset is selected', async () => { | ||
mockGui.isDepositPreset.mockReturnValue(true); | ||
|
||
const { getByText } = render(DepositDropdown, { | ||
props: { | ||
deposit: mockDeposit, | ||
gui: mockGui as unknown as DotrainOrderGui, | ||
tokenInfos: mockTokenInfos | ||
} | ||
}); | ||
|
||
await fireEvent.click(getByText('Choose deposit amount')); | ||
await fireEvent.click(getByText('100')); | ||
|
||
expect(mockGui.saveDeposit).toHaveBeenCalledWith('TEST', '100'); | ||
}); | ||
|
||
it('shows input field when custom value is selected', async () => { | ||
mockGui.isDepositPreset.mockReturnValue(false); | ||
|
||
const { getByText, getByPlaceholderText } = render(DepositDropdown, { | ||
props: { | ||
deposit: mockDeposit, | ||
gui: mockGui as unknown as DotrainOrderGui, | ||
tokenInfos: mockTokenInfos | ||
} | ||
}); | ||
|
||
await fireEvent.click(getByText('Choose deposit amount')); | ||
await fireEvent.click(getByText('Custom value')); | ||
|
||
expect(getByPlaceholderText('Enter deposit amount')).toBeTruthy(); | ||
}); | ||
|
||
it('calls saveDeposit when custom value is entered', async () => { | ||
mockGui.isDepositPreset.mockReturnValue(false); | ||
|
||
const { getByPlaceholderText } = render(DepositDropdown, { | ||
props: { | ||
deposit: mockDeposit, | ||
gui: mockGui as unknown as DotrainOrderGui, | ||
tokenInfos: mockTokenInfos | ||
} | ||
}); | ||
|
||
const input = getByPlaceholderText('Enter deposit amount'); | ||
await fireEvent.change(input, { target: { value: '150' } }); | ||
|
||
expect(mockGui.saveDeposit).toHaveBeenCalledWith('TEST', '150'); | ||
}); | ||
}); |