From c8d56d2d18f78a9918546441d36815ad7e582ac0 Mon Sep 17 00:00:00 2001 From: Jamie Harding Date: Fri, 27 Dec 2024 15:09:37 +0100 Subject: [PATCH] test the deploymentStepsStore --- .../__tests__/deploymentStepsStore.test.ts | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 packages/ui-components/src/__tests__/deploymentStepsStore.test.ts diff --git a/packages/ui-components/src/__tests__/deploymentStepsStore.test.ts b/packages/ui-components/src/__tests__/deploymentStepsStore.test.ts new file mode 100644 index 000000000..e51cd8828 --- /dev/null +++ b/packages/ui-components/src/__tests__/deploymentStepsStore.test.ts @@ -0,0 +1,106 @@ +import { get } from 'svelte/store'; +import deploymentStepsStore from '../lib/components/deployment/wizard/deploymentStepsStore' +import type { WizardStep, TokenInputStep, FieldStep } from '../lib/types/wizardSteps'; + +describe('deploymentStepsStore', () => { + beforeEach(() => { + deploymentStepsStore.reset(); + }); + + 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 + ]; + + deploymentStepsStore.populateDeploymentSteps(mockSteps); + const steps = get(deploymentStepsStore); + + 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 + ]; + + deploymentStepsStore.populateDeploymentSteps(initialSteps); + + const updatedStep: TokenInputStep = { + ...initialSteps[0], + inputVaultIds: ['vault1', 'vault2'] + } as unknown as TokenInputStep; + + deploymentStepsStore.updateDeploymentStep(0, 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 + ]; + + deploymentStepsStore.populateDeploymentSteps(mockSteps); + deploymentStepsStore.reset(); + + const steps = get(deploymentStepsStore); + expect(steps).toEqual([]); + }); +}); \ No newline at end of file