Skip to content

Commit

Permalink
test the deploymentStepsStore
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingjam committed Dec 27, 2024
1 parent 5763ea4 commit c8d56d2
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions packages/ui-components/src/__tests__/deploymentStepsStore.test.ts
Original file line number Diff line number Diff line change
@@ -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([]);
});
});

0 comments on commit c8d56d2

Please sign in to comment.