Skip to content

Commit

Permalink
Merge pull request #1262 from rainlanguage/2025-02-11-vault-id-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hardyjosh authored Feb 12, 2025
2 parents 5852d6e + 384683b commit 2f2f708
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
36 changes: 24 additions & 12 deletions packages/ui-components/src/__tests__/TokenIOInput.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,59 @@ describe('TokenInput', () => {
decimals: 18
};

const mockProps: TokenIOInputComponentProps = {
const inputMockProps: TokenIOInputComponentProps = {
i: 0,
isInput: true,
label: 'Input',
vault: mockInput,
vaultIds: ['vault1'],
gui: mockGui
} as unknown as TokenIOInputComponentProps;
const outputMockProps: TokenIOInputComponentProps = {
i: 0,
isInput: false,
label: 'Output',
vault: mockInput,
vaultIds: ['vault2'],
gui: mockGui
} as unknown as TokenIOInputComponentProps;

beforeEach(() => {
vi.clearAllMocks();
mockGui.getTokenInfo = vi.fn().mockResolvedValue(mockTokenInfo);
});

it('renders with correct label and no token symbol', () => {
const { getByText } = render(TokenIOInput, mockProps);
const { getByText } = render(TokenIOInput, inputMockProps);
expect(getByText('Input 1')).toBeInTheDocument();
});

it('renders input field with correct placeholder', () => {
const { getByPlaceholderText } = render(TokenIOInput, mockProps);
const { getByPlaceholderText } = render(TokenIOInput, inputMockProps);
const input = getByPlaceholderText('Enter vault ID');
expect(input).toBeInTheDocument();
});

it('displays the correct vault ID value', () => {
const { getByDisplayValue } = render(TokenIOInput, mockProps);
const { getByDisplayValue } = render(TokenIOInput, inputMockProps);
expect(getByDisplayValue('vault1')).toBeInTheDocument();
});

it('calls setVaultId when input changes', async () => {
const { getByPlaceholderText } = render(TokenIOInput, mockProps);
const input = getByPlaceholderText('Enter vault ID');

it('calls setVaultId on input vault when input changes', async () => {
const input = render(TokenIOInput, inputMockProps).getByPlaceholderText('Enter vault ID');
await fireEvent.change(input, { target: { value: 'vault1' } });

expect(mockGui.setVaultId).toHaveBeenCalledWith(true, 0, 'vault1');
});

it('calls setVaultId on output vault when input changes', async () => {
const input = render(TokenIOInput, outputMockProps).getByPlaceholderText('Enter vault ID');
await fireEvent.change(input, { target: { value: 'vault2' } });
expect(mockGui.setVaultId).toHaveBeenCalledWith(false, 0, 'vault2');
});

it('does not call setVaultId when gui is undefined', async () => {
const propsWithoutGui = {
...mockProps,
...inputMockProps,
gui: undefined
} as unknown as TokenIOInputComponentProps;
const { getByPlaceholderText } = render(TokenIOInput, propsWithoutGui);
Expand All @@ -76,7 +88,7 @@ describe('TokenInput', () => {

it('handles missing token info gracefully', () => {
const propsWithUnknownToken = {
...mockProps,
...inputMockProps,
vault: { token: { address: '0x789' } }
};
const { getByText } = render(
Expand All @@ -88,7 +100,7 @@ describe('TokenInput', () => {

it('fetches and displays token symbol when token key is present', async () => {
const propsWithTokenKey = {
...mockProps,
...inputMockProps,
vault: {
token: {
key: '0x456'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { CloseCircleSolid } from 'flowbite-svelte-icons';
import DeploymentSectionHeader from './DeploymentSectionHeader.svelte';
export let isInput: boolean;
export let i: number;
export let label: 'Input' | 'Output';
export let vault: OrderIO;
Expand Down Expand Up @@ -47,7 +48,7 @@
type="text"
placeholder="Enter vault ID"
bind:value={vaultIds[i]}
on:change={() => gui?.setVaultId(true, i, vaultIds[i])}
on:change={() => gui?.setVaultId(isInput, i, vaultIds[i])}
/>

{#if error}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,28 @@

{#if allTokenInputs.length > 0}
{#each allTokenInputs as input, i}
<TokenIOInput {i} label="Input" vault={input} vaultIds={inputVaultIds} {gui} {open} />
<TokenIOInput
isInput={true}
{i}
label="Input"
vault={input}
vaultIds={inputVaultIds}
{gui}
{open}
/>
{/each}
{/if}

{#if allTokenOutputs.length > 0}
{#each allTokenOutputs as output, i}
<TokenIOInput {i} label="Output" vault={output} vaultIds={outputVaultIds} {gui} {open} />
<TokenIOInput
isInput={false}
{i}
label="Output"
vault={output}
vaultIds={outputVaultIds}
{gui}
{open}
/>
{/each}
{/if}

0 comments on commit 2f2f708

Please sign in to comment.