Skip to content

Commit

Permalink
rm unused
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingjam committed Jan 6, 2025
1 parent 94e16db commit 252a2bf
Showing 1 changed file with 79 additions and 82 deletions.
161 changes: 79 additions & 82 deletions packages/ui-components/src/__tests__/DeploymentSteps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,114 +2,111 @@ import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/svelte';
import DeploymentSteps from '../lib/components/deployment/DeploymentSteps.svelte';
import { DotrainOrderGui } from '@rainlanguage/orderbook/js_api';
import testStrategy from '../lib/components/deployment/test-strategy.rain?raw';

vi.mock('@rainlanguage/orderbook/js_api', () => ({
DotrainOrderGui: {
getAvailableDeployments: vi.fn(),
chooseDeployment: vi.fn()
}
DotrainOrderGui: {
getAvailableDeployments: vi.fn(),
chooseDeployment: vi.fn()
}
}));

describe('DeploymentSteps', () => {
beforeEach(() => {
vi.clearAllMocks();
});
beforeEach(() => {
vi.clearAllMocks();
});

it('renders load strategy button', () => {
render(DeploymentSteps);
expect(screen.getByText('Load Strategy')).toBeInTheDocument();
});
it('renders load strategy button', () => {
render(DeploymentSteps);
expect(screen.getByText('Load Strategy')).toBeInTheDocument();
});

it('loads strategy when button is clicked', async () => {
render(DeploymentSteps);
const loadButton = screen.getByText('Load Strategy');
it('loads strategy when button is clicked', async () => {
render(DeploymentSteps);
const loadButton = screen.getByText('Load Strategy');

const mockDeployments = [
{ key: 'deployment1', label: 'Deployment 1' },
{ key: 'deployment2', label: 'Deployment 2' }
];

const mockDeployments = [
{ key: 'deployment1', label: 'Deployment 1' },
{ key: 'deployment2', label: 'Deployment 2' }
];
(DotrainOrderGui.getAvailableDeployments as Mock).mockResolvedValue(mockDeployments);

(DotrainOrderGui.getAvailableDeployments as Mock).mockResolvedValue(mockDeployments);
await fireEvent.click(loadButton);

await fireEvent.click(loadButton);
expect(DotrainOrderGui.getAvailableDeployments).toHaveBeenCalled();
});

it('shows deployments dropdown after strategy is loaded', async () => {
render(DeploymentSteps);
const loadButton = screen.getByText('Load Strategy');

expect(DotrainOrderGui.getAvailableDeployments).toHaveBeenCalled();
});
const mockDeployments = [
{ key: 'deployment1', label: 'Deployment 1' },
{ key: 'deployment2', label: 'Deployment 2' }
];

it('shows deployments dropdown after strategy is loaded', async () => {
render(DeploymentSteps);
const loadButton = screen.getByText('Load Strategy');
(DotrainOrderGui.getAvailableDeployments as Mock).mockResolvedValue(mockDeployments);

await fireEvent.click(loadButton);

const mockDeployments = [
{ key: 'deployment1', label: 'Deployment 1' },
{ key: 'deployment2', label: 'Deployment 2' }
];
expect(screen.getByText('Deployments')).toBeInTheDocument();
expect(screen.getByText('Select a deployment')).toBeInTheDocument();
});

(DotrainOrderGui.getAvailableDeployments as Mock).mockResolvedValue(mockDeployments);
it('initializes GUI when deployment is selected', async () => {
render(DeploymentSteps);

await fireEvent.click(loadButton);
const mockDeployments = [
{ key: 'deployment1', label: 'Deployment 1' },
{ key: 'deployment2', label: 'Deployment 2' }
];

expect(screen.getByText('Deployments')).toBeInTheDocument();
expect(screen.getByText('Select a deployment')).toBeInTheDocument();
});
const mockGui = {
getTokenInfos: vi.fn().mockReturnValue({}),
getCurrentDeployment: vi.fn().mockReturnValue({
deposits: [],
deployment: {
order: {
inputs: [],
outputs: []
}
}
}),
getAllFieldDefinitions: vi.fn().mockReturnValue([])
};
const loadButton = screen.getByText('Load Strategy');

it('initializes GUI when deployment is selected', async () => {
render(DeploymentSteps);
(DotrainOrderGui.getAvailableDeployments as Mock).mockResolvedValue(mockDeployments);

const mockDeployments = [
{ key: 'deployment1', label: 'Deployment 1' },
{ key: 'deployment2', label: 'Deployment 2' }
];
await fireEvent.click(loadButton);

expect(screen.getByText('Deployments')).toBeInTheDocument();
expect(screen.getByText('Select a deployment')).toBeInTheDocument();

const mockGui = {
getTokenInfos: vi.fn().mockReturnValue({}),
getCurrentDeployment: vi.fn().mockReturnValue({
deposits: [],
deployment: {
order: {
inputs: [],
outputs: []
}
}
}),
getAllFieldDefinitions: vi.fn().mockReturnValue([])
};
const loadButton = screen.getByText('Load Strategy');
(DotrainOrderGui.chooseDeployment as Mock).mockResolvedValue(mockGui);

(DotrainOrderGui.getAvailableDeployments as Mock).mockResolvedValue(mockDeployments);
const dropdownButton = screen.getByTestId('dropdown-button');
await fireEvent.click(dropdownButton);
const dropdown = screen.getByTestId('dropdown');
await fireEvent.click(dropdown);
const deploymentOption = screen.getByText('deployment1');
await fireEvent.click(deploymentOption);

await fireEvent.click(loadButton);
expect(DotrainOrderGui.chooseDeployment).toHaveBeenCalled();
});

expect(screen.getByText('Deployments')).toBeInTheDocument();
expect(screen.getByText('Select a deployment')).toBeInTheDocument();
it('handles errors during deployment initialization', async () => {
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});

(DotrainOrderGui.chooseDeployment as Mock).mockResolvedValue(mockGui);
(DotrainOrderGui.getAvailableDeployments as Mock).mockRejectedValue(
new Error('Failed to load')
);

const dropdownButton = screen.getByTestId('dropdown-button');
await fireEvent.click(dropdownButton);
const dropdown = screen.getByTestId('dropdown');
await fireEvent.click(dropdown);
const deploymentOption = screen.getByText('deployment1');
await fireEvent.click(deploymentOption);
render(DeploymentSteps);
const loadButton = screen.getByText('Load Strategy');
await fireEvent.click(loadButton);

expect(DotrainOrderGui.chooseDeployment).toHaveBeenCalled();
});

it('handles errors during deployment initialization', async () => {
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});

(DotrainOrderGui.getAvailableDeployments as Mock).mockRejectedValue(new Error('Failed to load'));

render(DeploymentSteps);
const loadButton = screen.getByText('Load Strategy');
await fireEvent.click(loadButton);

expect(consoleSpy).toHaveBeenCalledWith('Failed to load deployments:', expect.any(Error));
consoleSpy.mockRestore();
});
});
expect(consoleSpy).toHaveBeenCalledWith('Failed to load deployments:', expect.any(Error));
consoleSpy.mockRestore();
});
});

0 comments on commit 252a2bf

Please sign in to comment.