diff --git a/packages/ui-components/src/__tests__/FIeldDefinitionDropdown.test.ts b/packages/ui-components/src/__tests__/FIeldDefinitionDropdown.test.ts index c68ace2a4..099c9020b 100644 --- a/packages/ui-components/src/__tests__/FIeldDefinitionDropdown.test.ts +++ b/packages/ui-components/src/__tests__/FIeldDefinitionDropdown.test.ts @@ -4,86 +4,85 @@ import FieldDefinitionDropdown from '../lib/components/deployment/FieldDefinitio import type { DotrainOrderGui, GuiFieldDefinition } from '@rainlanguage/orderbook/js_api'; import type { ComponentProps } from 'svelte'; - export type FieldDefinitionDropdownProps = ComponentProps; describe('FieldDefinitionDropdown', () => { - let mockGui: DotrainOrderGui; - let fieldDefinition: GuiFieldDefinition; - - beforeEach(() => { - mockGui = { - saveFieldValue: vi.fn(), - isFieldPreset: vi.fn(), - } as unknown as DotrainOrderGui; - - fieldDefinition = { - name: 'Test Field', - binding: 'test-binding', - presets: [ - { id: 'preset1', name: 'Preset 1', value:'' }, - { id: 'preset2', name: 'Preset 2', value:''} - ] - } as unknown as GuiFieldDefinition - }); - - it('renders field name correctly', () => { - render(FieldDefinitionDropdown, { props: { fieldDefinition, gui: mockGui } }); - expect(screen.getByText('Test Field')).toBeInTheDocument(); - }); - - it('shows presets in dropdown', async () => { - render(FieldDefinitionDropdown, { props: { fieldDefinition, gui: mockGui } }); - - // Open dropdown - const dropdown = screen.getByText('Select a preset'); - await fireEvent.click(dropdown); - - // Check if presets are rendered - expect(screen.getByText('Preset 1')).toBeInTheDocument(); - expect(screen.getByText('Preset 2')).toBeInTheDocument(); - expect(screen.getByText('Custom value')).toBeInTheDocument(); - }); - - it('calls saveFieldValue when preset is selected', async () => { - render(FieldDefinitionDropdown, { props: { fieldDefinition, gui: mockGui } }); - - // Open dropdown and select preset - const dropdown = screen.getByText('Select a preset'); - await fireEvent.click(dropdown); - await fireEvent.click(screen.getByText('Preset 1')); - - expect(mockGui.saveFieldValue).toHaveBeenCalledWith('test-binding', { - isPreset: true, - value: 'preset1' - }); - }); - - it('shows input field when custom value is selected', async () => { - (mockGui.isFieldPreset as Mock).mockReturnValue(false); - - render(FieldDefinitionDropdown, { props: { fieldDefinition, gui: mockGui } }); - - // Open dropdown and select custom - const dropdown = screen.getByText('Select a preset'); - await fireEvent.click(dropdown); - await fireEvent.click(screen.getByText('Custom value')); - - // Check if input field appears - const input = screen.getByPlaceholderText('Enter value'); - expect(input).toBeInTheDocument(); - - // Test input change - await fireEvent.change(input, { target: { value: 'custom input' } }); - expect(mockGui.saveFieldValue).toHaveBeenCalledWith('test-binding', { - isPreset: false, - value: 'custom input' - }); - }); - - it('handles case when gui is not provided', () => { - render(FieldDefinitionDropdown, { props: { fieldDefinition } as FieldDefinitionDropdownProps }); - expect(screen.getByText('Test Field')).toBeInTheDocument(); - // Should not throw any errors - }); -}); \ No newline at end of file + let mockGui: DotrainOrderGui; + let fieldDefinition: GuiFieldDefinition; + + beforeEach(() => { + mockGui = { + saveFieldValue: vi.fn(), + isFieldPreset: vi.fn() + } as unknown as DotrainOrderGui; + + fieldDefinition = { + name: 'Test Field', + binding: 'test-binding', + presets: [ + { id: 'preset1', name: 'Preset 1', value: '' }, + { id: 'preset2', name: 'Preset 2', value: '' } + ] + } as unknown as GuiFieldDefinition; + }); + + it('renders field name correctly', () => { + render(FieldDefinitionDropdown, { props: { fieldDefinition, gui: mockGui } }); + expect(screen.getByText('Test Field')).toBeInTheDocument(); + }); + + it('shows presets in dropdown', async () => { + render(FieldDefinitionDropdown, { props: { fieldDefinition, gui: mockGui } }); + + // Open dropdown + const dropdown = screen.getByText('Select a preset'); + await fireEvent.click(dropdown); + + // Check if presets are rendered + expect(screen.getByText('Preset 1')).toBeInTheDocument(); + expect(screen.getByText('Preset 2')).toBeInTheDocument(); + expect(screen.getByText('Custom value')).toBeInTheDocument(); + }); + + it('calls saveFieldValue when preset is selected', async () => { + render(FieldDefinitionDropdown, { props: { fieldDefinition, gui: mockGui } }); + + // Open dropdown and select preset + const dropdown = screen.getByText('Select a preset'); + await fireEvent.click(dropdown); + await fireEvent.click(screen.getByText('Preset 1')); + + expect(mockGui.saveFieldValue).toHaveBeenCalledWith('test-binding', { + isPreset: true, + value: 'preset1' + }); + }); + + it('shows input field when custom value is selected', async () => { + (mockGui.isFieldPreset as Mock).mockReturnValue(false); + + render(FieldDefinitionDropdown, { props: { fieldDefinition, gui: mockGui } }); + + // Open dropdown and select custom + const dropdown = screen.getByText('Select a preset'); + await fireEvent.click(dropdown); + await fireEvent.click(screen.getByText('Custom value')); + + // Check if input field appears + const input = screen.getByPlaceholderText('Enter value'); + expect(input).toBeInTheDocument(); + + // Test input change + await fireEvent.change(input, { target: { value: 'custom input' } }); + expect(mockGui.saveFieldValue).toHaveBeenCalledWith('test-binding', { + isPreset: false, + value: 'custom input' + }); + }); + + it('handles case when gui is not provided', () => { + render(FieldDefinitionDropdown, { props: { fieldDefinition } as FieldDefinitionDropdownProps }); + expect(screen.getByText('Test Field')).toBeInTheDocument(); + // Should not throw any errors + }); +}); diff --git a/packages/ui-components/src/__tests__/FieldDefinitionButtons.test.ts b/packages/ui-components/src/__tests__/FieldDefinitionButtons.test.ts index f8eb82e1c..acafd3066 100644 --- a/packages/ui-components/src/__tests__/FieldDefinitionButtons.test.ts +++ b/packages/ui-components/src/__tests__/FieldDefinitionButtons.test.ts @@ -6,122 +6,122 @@ import deploymentStepsStore from '../lib/components/deployment/wizard/deployment // Mock the DotrainOrderGui class vi.mock('@rainlanguage/orderbook/js_api', () => ({ - DotrainOrderGui: vi.fn().mockImplementation(() => ({ - saveFieldValue: vi.fn(), - getFieldValue: vi.fn(), - isFieldPreset: vi.fn() - })) + DotrainOrderGui: vi.fn().mockImplementation(() => ({ + saveFieldValue: vi.fn(), + getFieldValue: vi.fn(), + isFieldPreset: vi.fn() + })) })); describe('FieldDefinitionButtons', () => { - let mockGui: DotrainOrderGui; - const mockFieldDefinition = { - binding: 'test-binding', - name: 'Test Field', - description: 'Test Description', - presets: [ - { id: 'preset1', name: 'Preset 1', value: 'value1' }, - { id: 'preset2', name: 'Preset 2', value: 'value2' } - ] - }; - - beforeEach(() => { - mockGui = new DotrainOrderGui(); - vi.spyOn(deploymentStepsStore, 'updateDeploymentStep'); - }); - - it('renders field name and description', () => { - const { getByText } = render(FieldDefinitionButtons, { - props: { - fieldDefinition: mockFieldDefinition, - gui: mockGui, - currentStep: 0 - } - }); - - expect(getByText('Test Field')).toBeTruthy(); - expect(getByText('Test Description')).toBeTruthy(); - }); - - it('renders preset buttons', () => { - const { getByText } = render(FieldDefinitionButtons, { - props: { - fieldDefinition: mockFieldDefinition, - gui: mockGui, - currentStep: 0 - } - }); - - expect(getByText('Preset 1')).toBeTruthy(); - expect(getByText('Preset 2')).toBeTruthy(); - expect(getByText('Custom')).toBeTruthy(); - }); - - it('handles preset button clicks', async () => { - const { getByText } = render(FieldDefinitionButtons, { - props: { - fieldDefinition: mockFieldDefinition, - gui: mockGui, - currentStep: 0 - } - }); - - await fireEvent.click(getByText('Preset 1')); - - expect(mockGui.saveFieldValue).toHaveBeenCalledWith('test-binding', { - isPreset: true, - value: 'preset1' - }); - expect(deploymentStepsStore.updateDeploymentStep).toHaveBeenCalled(); - }); - - it('shows custom input when Custom button is clicked', async () => { - const { getByText, getByPlaceholderText } = render(FieldDefinitionButtons, { - props: { - fieldDefinition: mockFieldDefinition, - gui: mockGui, - currentStep: 0 - } - }); - - await fireEvent.click(getByText('Custom')); - expect(getByPlaceholderText('Enter custom value')).toBeTruthy(); - }); - - it('handles custom input changes', async () => { - const { getByText, getByPlaceholderText } = render(FieldDefinitionButtons, { - props: { - fieldDefinition: mockFieldDefinition, - gui: mockGui, - currentStep: 0 - } - }); - - await fireEvent.click(getByText('Custom')); - const input = getByPlaceholderText('Enter custom value'); - await fireEvent.input(input, { target: { value: 'custom value' } }); - - expect(mockGui.saveFieldValue).toHaveBeenCalledWith('test-binding', { - isPreset: false, - value: 'custom value' - }); - expect(deploymentStepsStore.updateDeploymentStep).toHaveBeenCalled(); - }); - - it('does not show Custom button for is-fast-exit binding', () => { - const fastExitFieldDef = { - ...mockFieldDefinition, - binding: 'is-fast-exit' - }; - - const { queryByText } = render(FieldDefinitionButtons, { - props: { - fieldDefinition: fastExitFieldDef, - gui: mockGui, - currentStep: 0 - } - }); - - expect(queryByText('Custom')).toBeNull(); - }); + let mockGui: DotrainOrderGui; + const mockFieldDefinition = { + binding: 'test-binding', + name: 'Test Field', + description: 'Test Description', + presets: [ + { id: 'preset1', name: 'Preset 1', value: 'value1' }, + { id: 'preset2', name: 'Preset 2', value: 'value2' } + ] + }; + + beforeEach(() => { + mockGui = new DotrainOrderGui(); + vi.spyOn(deploymentStepsStore, 'updateDeploymentStep'); + }); + + it('renders field name and description', () => { + const { getByText } = render(FieldDefinitionButtons, { + props: { + fieldDefinition: mockFieldDefinition, + gui: mockGui, + currentStep: 0 + } + }); + + expect(getByText('Test Field')).toBeTruthy(); + expect(getByText('Test Description')).toBeTruthy(); + }); + + it('renders preset buttons', () => { + const { getByText } = render(FieldDefinitionButtons, { + props: { + fieldDefinition: mockFieldDefinition, + gui: mockGui, + currentStep: 0 + } + }); + + expect(getByText('Preset 1')).toBeTruthy(); + expect(getByText('Preset 2')).toBeTruthy(); + expect(getByText('Custom')).toBeTruthy(); + }); + + it('handles preset button clicks', async () => { + const { getByText } = render(FieldDefinitionButtons, { + props: { + fieldDefinition: mockFieldDefinition, + gui: mockGui, + currentStep: 0 + } + }); + + await fireEvent.click(getByText('Preset 1')); + + expect(mockGui.saveFieldValue).toHaveBeenCalledWith('test-binding', { + isPreset: true, + value: 'preset1' + }); + expect(deploymentStepsStore.updateDeploymentStep).toHaveBeenCalled(); + }); + + it('shows custom input when Custom button is clicked', async () => { + const { getByText, getByPlaceholderText } = render(FieldDefinitionButtons, { + props: { + fieldDefinition: mockFieldDefinition, + gui: mockGui, + currentStep: 0 + } + }); + + await fireEvent.click(getByText('Custom')); + expect(getByPlaceholderText('Enter custom value')).toBeTruthy(); + }); + + it('handles custom input changes', async () => { + const { getByText, getByPlaceholderText } = render(FieldDefinitionButtons, { + props: { + fieldDefinition: mockFieldDefinition, + gui: mockGui, + currentStep: 0 + } + }); + + await fireEvent.click(getByText('Custom')); + const input = getByPlaceholderText('Enter custom value'); + await fireEvent.input(input, { target: { value: 'custom value' } }); + + expect(mockGui.saveFieldValue).toHaveBeenCalledWith('test-binding', { + isPreset: false, + value: 'custom value' + }); + expect(deploymentStepsStore.updateDeploymentStep).toHaveBeenCalled(); + }); + + it('does not show Custom button for is-fast-exit binding', () => { + const fastExitFieldDef = { + ...mockFieldDefinition, + binding: 'is-fast-exit' + }; + + const { queryByText } = render(FieldDefinitionButtons, { + props: { + fieldDefinition: fastExitFieldDef, + gui: mockGui, + currentStep: 0 + } + }); + + expect(queryByText('Custom')).toBeNull(); + }); }); diff --git a/packages/ui-components/src/__tests__/SelectToken.test.ts b/packages/ui-components/src/__tests__/SelectToken.test.ts new file mode 100644 index 000000000..86cab19cd --- /dev/null +++ b/packages/ui-components/src/__tests__/SelectToken.test.ts @@ -0,0 +1,56 @@ +import { render, fireEvent } from '@testing-library/svelte'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import SelectToken from '../lib/components/deployment/SelectToken.svelte'; +import type { ComponentProps } from 'svelte'; +import type { DotrainOrderGui } from '@rainlanguage/orderbook/js_api'; + +export type SelectTokenComponentProps = ComponentProps; +describe('SelectToken', () => { + const mockGui: DotrainOrderGui = { + saveSelectTokenAddress: vi.fn().mockResolvedValue(undefined), + getSelectTokens: vi.fn().mockReturnValue(new Map([['TOKEN1', '0x123']])) + } as unknown as DotrainOrderGui; + + const mockProps: SelectTokenComponentProps = { + token: 'TOKEN1', + gui: mockGui, + selectTokens: new Map([['TOKEN1', '0x123']]) + }; + + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('renders token label correctly', () => { + const { getByText } = render(SelectToken, mockProps); + expect(getByText('TOKEN1')).toBeInTheDocument(); + }); + + it('renders input field', () => { + const { getByRole } = render(SelectToken, mockProps); + expect(getByRole('textbox')).toBeInTheDocument(); + }); + + it('calls saveSelectTokenAddress when input changes', async () => { + const { getByRole } = render(SelectToken, mockProps); + const input = getByRole('textbox'); + + await fireEvent.change(input, { target: { value: '0x456' } }); + + expect(mockGui.saveSelectTokenAddress).toHaveBeenCalledWith('TOKEN1', '0x456'); + expect(mockGui.getSelectTokens).toHaveBeenCalled(); + }); + + it('does nothing if gui is not defined', async () => { + const { getByRole } = render(SelectToken, { + ...mockProps, + gui: undefined + } as unknown as SelectTokenComponentProps); + const input = getByRole('textbox'); + + await fireEvent.change(input, { target: { value: '0x456' } }); + + expect(mockGui.saveSelectTokenAddress).not.toHaveBeenCalled(); + expect(mockGui.getSelectTokens).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/ui-components/src/__tests__/TokenInput.test.ts b/packages/ui-components/src/__tests__/TokenInput.test.ts new file mode 100644 index 000000000..8bef2556d --- /dev/null +++ b/packages/ui-components/src/__tests__/TokenInput.test.ts @@ -0,0 +1,79 @@ +import { render, fireEvent } from '@testing-library/svelte'; +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import TokenInput from '../lib/components/deployment/TokenInput.svelte'; +import type { ComponentProps } from 'svelte'; + +export type TokenInputComponentProps = ComponentProps; + +describe('TokenInput', () => { + const mockTokenInfos = new Map([ + ['0x123', { symbol: 'ETH' }], + ['0x456', { symbol: 'USDC' }] + ]); + + const mockInput = { + token: { + address: '0x123' + } + }; + + const mockGui = { + setVaultId: vi.fn() + }; + + const mockProps: TokenInputComponentProps = { + i: 0, + input: mockInput, + tokenInfos: mockTokenInfos, + inputVaultIds: ['vault1'], + gui: mockGui + } as unknown as TokenInputComponentProps; + + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('renders with correct label and token symbol', () => { + const { getByText } = render(TokenInput, mockProps); + expect(getByText('Input 1 (ETH)')).toBeInTheDocument(); + }); + + it('renders input field with correct placeholder', () => { + const { getByPlaceholderText } = render(TokenInput, mockProps); + const input = getByPlaceholderText('Enter vault ID'); + expect(input).toBeInTheDocument(); + }); + + it('displays the correct vault ID value', () => { + const { getByDisplayValue } = render(TokenInput, mockProps); + expect(getByDisplayValue('vault1')).toBeInTheDocument(); + }); + + it('calls setVaultId when input changes', async () => { + const { getByPlaceholderText } = render(TokenInput, mockProps); + const input = getByPlaceholderText('Enter vault ID'); + + await fireEvent.change(input, { target: { value: 'vault1' } }); + + expect(mockGui.setVaultId).toHaveBeenCalledWith(true, 0, 'vault1'); + }); + + it('does not call setVaultId when gui is undefined', async () => { + const propsWithoutGui = { ...mockProps, gui: undefined } as unknown as TokenInputComponentProps; + const { getByPlaceholderText } = render(TokenInput, propsWithoutGui); + const input = getByPlaceholderText('Enter vault ID'); + + await fireEvent.change(input, { target: { value: 'newVault' } }); + + expect(mockGui.setVaultId).not.toHaveBeenCalled(); + }); + + it('handles missing token info gracefully', () => { + const propsWithUnknownToken = { + ...mockProps, + input: { token: { address: '0x789' } } + }; + const { getByText } = render(TokenInput, propsWithUnknownToken as unknown as TokenInputComponentProps); + expect(getByText('Input 1 ()')).toBeInTheDocument(); + }); +}); \ No newline at end of file diff --git a/packages/ui-components/src/__tests__/deploymentStepsStore.test.ts b/packages/ui-components/src/__tests__/deploymentStepsStore.test.ts index e51cd8828..7dc3844d9 100644 --- a/packages/ui-components/src/__tests__/deploymentStepsStore.test.ts +++ b/packages/ui-components/src/__tests__/deploymentStepsStore.test.ts @@ -1,106 +1,104 @@ import { get } from 'svelte/store'; -import deploymentStepsStore from '../lib/components/deployment/wizard/deploymentStepsStore' +import deploymentStepsStore from '../lib/components/deployment/wizard/deploymentStepsStore'; import type { WizardStep, TokenInputStep, FieldStep } from '../lib/types/wizardSteps'; describe('deploymentStepsStore', () => { - beforeEach(() => { - deploymentStepsStore.reset(); - }); + beforeEach(() => { + deploymentStepsStore.reset(); + }); - it('should initialize with empty array', () => { - const steps = get(deploymentStepsStore); - expect(steps).toEqual([]); - }); + it('should initialize with empty array', () => { + const steps = get(deploymentStepsStore); + expect(steps).toEqual([]); + }); - it('should populate steps correctly', () => { - const mockSteps: WizardStep[] = [ - { - type: 'tokenInput', - input: { - token: '0x123...', - decimals: 18, - symbol: 'TEST' - }, - gui: { - name: 'Test GUI', - description: 'Test Description', - }, - tokenInfos: { - }, - i: 0, - inputVaultIds: ['vault1', 'vault2'] - } as unknown as TokenInputStep, - { - type: 'fields', - fieldDefinition: { - name: 'Test Field', - type: 'uint256', - }, - gui: { - name: 'Test GUI', - description: 'Test Description', - } - } as unknown as FieldStep - ]; + it('should populate steps correctly', () => { + const mockSteps: WizardStep[] = [ + { + type: 'tokenInput', + input: { + token: '0x123...', + decimals: 18, + symbol: 'TEST' + }, + gui: { + name: 'Test GUI', + description: 'Test Description' + }, + tokenInfos: {}, + i: 0, + inputVaultIds: ['vault1', 'vault2'] + } as unknown as TokenInputStep, + { + type: 'fields', + fieldDefinition: { + name: 'Test Field', + type: 'uint256' + }, + gui: { + name: 'Test GUI', + description: 'Test Description' + } + } as unknown as FieldStep + ]; - deploymentStepsStore.populateDeploymentSteps(mockSteps); - const steps = get(deploymentStepsStore); + deploymentStepsStore.populateDeploymentSteps(mockSteps); + const steps = get(deploymentStepsStore); - expect(steps).toEqual(mockSteps); - }); + expect(steps).toEqual(mockSteps); + }); - it('should update a specific step correctly', () => { - const initialSteps: WizardStep[] = [ - { - type: 'tokenInput', - input: { - token: '0x123...', - decimals: 18, - symbol: 'TEST' - }, - gui: { - name: 'Test GUI', - description: 'Test Description' - }, - tokenInfos: { - }, - i: 0, - inputVaultIds: ['vault1'] - } as unknown as TokenInputStep - ]; + it('should update a specific step correctly', () => { + const initialSteps: WizardStep[] = [ + { + type: 'tokenInput', + input: { + token: '0x123...', + decimals: 18, + symbol: 'TEST' + }, + gui: { + name: 'Test GUI', + description: 'Test Description' + }, + tokenInfos: {}, + i: 0, + inputVaultIds: ['vault1'] + } as unknown as TokenInputStep + ]; - deploymentStepsStore.populateDeploymentSteps(initialSteps); + deploymentStepsStore.populateDeploymentSteps(initialSteps); - const updatedStep: TokenInputStep = { - ...initialSteps[0], - inputVaultIds: ['vault1', 'vault2'] - } as unknown as TokenInputStep; + const updatedStep: TokenInputStep = { + ...initialSteps[0], + inputVaultIds: ['vault1', 'vault2'] + } as unknown as TokenInputStep; - deploymentStepsStore.updateDeploymentStep(0, updatedStep); + deploymentStepsStore.updateDeploymentStep(0, updatedStep); - const steps = get(deploymentStepsStore); - expect(steps[0]).toEqual(updatedStep); - }); + const steps = get(deploymentStepsStore); + expect(steps[0]).toEqual(updatedStep); + }); - it('should reset store to initial state', () => { - const mockSteps: WizardStep[] = [ - { - type: 'fields', - fieldDefinition: { - name: 'Test Field', - type: 'uint256', - }, - gui: { - name: 'Test GUI', - description: 'Test Description', - } - } as unknown as FieldStep - ]; + it('should reset store to initial state', () => { + const mockSteps: WizardStep[] = [ + { + type: 'fields', + fieldDefinition: { + name: 'Test Field', + type: 'uint256' + }, + gui: { + name: 'Test GUI', + description: 'Test Description' + } + } as unknown as FieldStep + ]; - deploymentStepsStore.populateDeploymentSteps(mockSteps); - deploymentStepsStore.reset(); + deploymentStepsStore.populateDeploymentSteps(mockSteps); + deploymentStepsStore.reset(); - const steps = get(deploymentStepsStore); - expect(steps).toEqual([]); - }); -}); \ No newline at end of file + const steps = get(deploymentStepsStore); + expect(steps).toEqual([]); + }); +}); diff --git a/packages/ui-components/src/__tests__/getDeploymentSteps.test.ts b/packages/ui-components/src/__tests__/getDeploymentSteps.test.ts index c1b7fc9b0..a1d3b92ea 100644 --- a/packages/ui-components/src/__tests__/getDeploymentSteps.test.ts +++ b/packages/ui-components/src/__tests__/getDeploymentSteps.test.ts @@ -3,96 +3,96 @@ import { getDeploymentSteps } from '../lib/components/deployment/wizard/getDeplo import { describe, it, expect } from 'vitest'; describe('getDeploymentSteps', () => { - const mockGui = {} as any; - const mockTokenInfos = {} as any; + const mockGui = {} as any; + const mockTokenInfos = {} as any; - it('should return empty array when no inputs provided', () => { - const steps = getDeploymentSteps( - new Map(), - false, - [], - mockGui, - [], - [], - [], - [], - [], - mockTokenInfos - ); + it('should return empty array when no inputs provided', () => { + const steps = getDeploymentSteps( + new Map(), + false, + [], + mockGui, + [], + [], + [], + [], + [], + mockTokenInfos + ); - expect(steps).toEqual([]); - }); + expect(steps).toEqual([]); + }); - it('should include select token steps for limit strategy', () => { - const selectTokens = new Map([['TOKEN1', 'address1']]); + it('should include select token steps for limit strategy', () => { + const selectTokens = new Map([['TOKEN1', 'address1']]); - const steps = getDeploymentSteps( - selectTokens, - true, - [], - mockGui, - [], - [], - [], - [], - [], - mockTokenInfos - ); + const steps = getDeploymentSteps( + selectTokens, + true, + [], + mockGui, + [], + [], + [], + [], + [], + mockTokenInfos + ); - expect(steps[0]).toEqual({ - type: 'tokens', - token: 'TOKEN1', - gui: mockGui, - selectTokens - }); - }); + expect(steps[0]).toEqual({ + type: 'tokens', + token: 'TOKEN1', + gui: mockGui, + selectTokens + }); + }); - it('should not include select token steps when not limit strategy', () => { - const selectTokens = new Map([['TOKEN1', 'address1']]); + it('should not include select token steps when not limit strategy', () => { + const selectTokens = new Map([['TOKEN1', 'address1']]); - const steps = getDeploymentSteps( - selectTokens, - false, - [], - mockGui, - [], - [], - [], - [], - [], - mockTokenInfos - ); + const steps = getDeploymentSteps( + selectTokens, + false, + [], + mockGui, + [], + [], + [], + [], + [], + mockTokenInfos + ); - expect(steps).toEqual([]); - }); + expect(steps).toEqual([]); + }); - it('should include all step types in correct order', () => { - const selectTokens = new Map([['TOKEN1', 'address1']]); - const fieldDefinitions = [{ id: 'field1' }] as any; - const deposits = [{ id: 'deposit1' }] as any; - const inputs = [{ id: 'input1' }] as any; - const outputs = [{ id: 'output1' }] as any; - const inputVaultIds = ['vault1']; - const outputVaultIds = ['vault2']; + it('should include all step types in correct order', () => { + const selectTokens = new Map([['TOKEN1', 'address1']]); + const fieldDefinitions = [{ id: 'field1' }] as any; + const deposits = [{ id: 'deposit1' }] as any; + const inputs = [{ id: 'input1' }] as any; + const outputs = [{ id: 'output1' }] as any; + const inputVaultIds = ['vault1']; + const outputVaultIds = ['vault2']; - const steps = getDeploymentSteps( - selectTokens, - true, - fieldDefinitions, - mockGui, - deposits, - inputs, - outputs, - inputVaultIds, - outputVaultIds, - mockTokenInfos - ); + const steps = getDeploymentSteps( + selectTokens, + true, + fieldDefinitions, + mockGui, + deposits, + inputs, + outputs, + inputVaultIds, + outputVaultIds, + mockTokenInfos + ); - expect(steps).toHaveLength(5); - expect(steps[0].type).toBe('tokens'); - expect(steps[1].type).toBe('fields'); - expect(steps[2].type).toBe('deposits'); - expect(steps[3].type).toBe('tokenInput'); - expect(steps[4].type).toBe('tokenOutput'); - }); -}); \ No newline at end of file + expect(steps).toHaveLength(5); + expect(steps[0].type).toBe('tokens'); + expect(steps[1].type).toBe('fields'); + expect(steps[2].type).toBe('deposits'); + expect(steps[3].type).toBe('tokenInput'); + expect(steps[4].type).toBe('tokenOutput'); + }); +}); diff --git a/packages/ui-components/src/lib/components/deployment/TokenInput.svelte b/packages/ui-components/src/lib/components/deployment/TokenInput.svelte index 863e0291e..1e7e0c4b6 100644 --- a/packages/ui-components/src/lib/components/deployment/TokenInput.svelte +++ b/packages/ui-components/src/lib/components/deployment/TokenInput.svelte @@ -12,7 +12,7 @@
Input {i + 1} ({tokenInfos.get(input.token.address)?.symbol || ''})
diff --git a/packages/ui-components/src/lib/components/deployment/wizard/deploymentStepsStore.ts b/packages/ui-components/src/lib/components/deployment/wizard/deploymentStepsStore.ts index e857d41a6..9801f6857 100644 --- a/packages/ui-components/src/lib/components/deployment/wizard/deploymentStepsStore.ts +++ b/packages/ui-components/src/lib/components/deployment/wizard/deploymentStepsStore.ts @@ -1,24 +1,24 @@ import { writable } from 'svelte/store'; import type { WizardStep } from '../../../types/wizardSteps'; -const initialState: WizardStep[] = [] +const initialState: WizardStep[] = []; const deploymentStepsStore = () => { const { subscribe, set, update } = writable(initialState); - const reset = () => set(initialState); + const reset = () => set(initialState); - // For getting an array of steps from the various input types (deposit, token, vault) + // For getting an array of steps from the various input types (deposit, token, vault) const populateDeploymentSteps = (steps: WizardStep[]) => { - update(() => ( steps )); + update(() => steps); }; - // For adding a property (binding) to the current step + // For adding a property (binding) to the current step const updateDeploymentStep = (index: number, updatedStep: WizardStep) => { - update((state) => { - const newSteps = [...state]; - newSteps[index] = updatedStep; - return newSteps - }); + update((state) => { + const newSteps = [...state]; + newSteps[index] = updatedStep; + return newSteps; + }); }; return { diff --git a/packages/ui-components/src/lib/components/deployment/wizard/getDeploymentSteps.ts b/packages/ui-components/src/lib/components/deployment/wizard/getDeploymentSteps.ts index 5f55f31f4..b48b259ef 100644 --- a/packages/ui-components/src/lib/components/deployment/wizard/getDeploymentSteps.ts +++ b/packages/ui-components/src/lib/components/deployment/wizard/getDeploymentSteps.ts @@ -1,10 +1,16 @@ -import type { TokenOutputStep } from "$lib/types/wizardSteps"; +import type { TokenOutputStep } from '$lib/types/wizardSteps'; -import type { DepositStep, FieldStep, TokenInputStep } from "$lib/types/wizardSteps"; +import type { DepositStep, FieldStep, TokenInputStep } from '$lib/types/wizardSteps'; -import type { SelectTokenStep } from "$lib/types/wizardSteps"; +import type { SelectTokenStep } from '$lib/types/wizardSteps'; -import type { DotrainOrderGui, GuiFieldDefinition, TokenInfos, Vault, TokenDeposit} from '@rainlanguage/orderbook/js_api'; +import type { + DotrainOrderGui, + GuiFieldDefinition, + TokenInfos, + Vault, + TokenDeposit +} from '@rainlanguage/orderbook/js_api'; import type { WizardStep } from '../../../types/wizardSteps'; export const getDeploymentSteps = ( @@ -64,13 +70,12 @@ export const getDeploymentSteps = ( type: 'tokenOutput', output, gui, - tokenInfos, - i, - outputVaultIds + tokenInfos, + i, + outputVaultIds }) ) ]; return deploymentSteps; }; - diff --git a/packages/ui-components/src/lib/types/wizardSteps.ts b/packages/ui-components/src/lib/types/wizardSteps.ts index 0729e498e..6ff7f776d 100644 --- a/packages/ui-components/src/lib/types/wizardSteps.ts +++ b/packages/ui-components/src/lib/types/wizardSteps.ts @@ -51,4 +51,9 @@ export interface TokenOutputStep extends BaseWizardStep { outputVaultIds: string[]; } -export type WizardStep = SelectTokenStep | FieldStep | DepositStep | TokenInputStep | TokenOutputStep; +export type WizardStep = + | SelectTokenStep + | FieldStep + | DepositStep + | TokenInputStep + | TokenOutputStep;