Skip to content

Commit

Permalink
test: update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
kiner-tang committed Oct 3, 2024
1 parent 422872b commit 1acbdc3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/web3/src/crypto-input/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,19 @@ describe('CryptoInput component', () => {

it('should call onChange with selected token and amount input', () => {
const TestComponent = (props: CryptoInputProps) => {
const [crypto, setCrypto] = useState<CryptoInputProps['value']>();
const [crypto, setCrypto] = useState<CryptoInputProps['value']>({
inputString: '10',
amount: 0n,
token: undefined,
});

return (
<CryptoInput
options={mockTokens}
value={crypto}
onChange={(newCrypto) => {
setCrypto(newCrypto);

console.log('--->', newCrypto);
props.onChange?.(newCrypto);
}}
/>
Expand All @@ -99,6 +103,12 @@ describe('CryptoInput component', () => {

const { baseElement } = render(<TestComponent onChange={handleChange} />);

fireEvent.change(baseElement.querySelector('.ant-input-number-input') as Element, {
target: { value: '' },
});

expect(handleChange).toHaveBeenCalledWith({});

fireEvent.change(baseElement.querySelector('.ant-input-number-input') as Element, {
target: { value: '10' },
});
Expand All @@ -111,8 +121,6 @@ describe('CryptoInput component', () => {

fireEvent.click(selectOptions[0]);

expect(handleChange).toHaveBeenCalledWith({ token: mockTokens[0] });

expect(handleChange).toHaveBeenCalledWith({
token: mockTokens[0],
amount: 10000000000000000000n,
Expand Down

0 comments on commit 1acbdc3

Please sign in to comment.