Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hardyjosh committed Feb 15, 2025
1 parent f04f389 commit 1d6076d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 75 deletions.
78 changes: 5 additions & 73 deletions packages/ui-components/src/__tests__/DisclaimerModal.test.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,25 @@
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/svelte';
import DisclaimerModal from '../lib/components/deployment/DisclaimerModal.svelte';
import { getDeploymentTransactionArgs } from '../lib/components/deployment/getDeploymentTransactionArgs';
import { writable } from 'svelte/store';
import type { DotrainOrderGui } from '@rainlanguage/orderbook/js_api';
import type { OrderIO } from '@rainlanguage/orderbook/js_api';
import type { DeploymentArgs } from '../lib/types/transaction';
vi.mock('../lib/components/deployment/getDeploymentTransactionArgs', () => ({
getDeploymentTransactionArgs: vi.fn()
}));

describe('DisclaimerModal', () => {
const mockGui = {} as DotrainOrderGui;
const mockOutputs = [] as OrderIO[];
const mockWagmiConfig = writable(undefined);
const mockHandleDeployModal = vi.fn() as unknown as (args: DeploymentArgs) => void;
const mockOnAccept = vi.fn();

beforeEach(() => {
vi.clearAllMocks();
});

it('calls getDeploymentTransactionArgs when opened', async () => {
const mockResult = {
approvals: {},
deploymentCalldata: {},
orderbookAddress: '0x123',
chainId: 1
};
(getDeploymentTransactionArgs as Mock).mockResolvedValue(mockResult);

render(DisclaimerModal, {
props: {
open: true,
gui: mockGui,
allTokenOutputs: mockOutputs,
wagmiConfig: mockWagmiConfig,
subgraphUrl: 'https://example.com',
handleDeployModal: mockHandleDeployModal
}
});

expect(getDeploymentTransactionArgs).toHaveBeenCalledWith(mockGui, undefined, mockOutputs);
});

it('shows error message when getDeploymentTransactionArgs fails', async () => {
const errorMessage = 'Test error message';
(getDeploymentTransactionArgs as Mock).mockRejectedValue(new Error(errorMessage));

render(DisclaimerModal, {
props: {
open: true,
gui: mockGui,
allTokenOutputs: mockOutputs,
wagmiConfig: mockWagmiConfig,
subgraphUrl: 'https://example.com',
handleDeployModal: mockHandleDeployModal
}
});

const errorText = await screen.findByText('Error getting deployment transaction data:');
const errorDetails = await screen.findByText(errorMessage);
expect(errorText).toBeInTheDocument();
expect(errorDetails).toBeInTheDocument();
});

it('calls handleDeployModal with result when accepting disclaimer', async () => {
const mockResult = {
approvals: {},
deploymentCalldata: {},
orderbookAddress: '0x123',
chainId: 1,
subgraphUrl: 'https://example.com'
};
(getDeploymentTransactionArgs as Mock).mockResolvedValue(mockResult);

it('calls onAccept when accepting disclaimer', async () => {
render(DisclaimerModal, {
props: {
open: true,
gui: mockGui,
allTokenOutputs: mockOutputs,
wagmiConfig: mockWagmiConfig,
subgraphUrl: 'https://example.com',
handleDeployModal: mockHandleDeployModal
onAccept: mockOnAccept
}
});

const deployButton = await screen.findByText('Deploy');
await fireEvent.click(deployButton);

expect(mockHandleDeployModal).toHaveBeenCalledWith(mockResult);
expect(mockOnAccept).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Alert, Modal, Button } from 'flowbite-svelte';
import { ExclamationCircleSolid } from 'flowbite-svelte-icons';
export let open: boolean = false;
export let onAccept: () => void;
export let onAccept: () => void = () => {};
async function handleAcceptDisclaimer() {
open = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/lib/components/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
{#if !sideBarHidden}
<CloseButton
data-testid="close-button"
class="absolute right-3 top-2 z-20 flex size-8 items-center border lg:hidden dark:border-gray-700"
class="absolute right-3 top-2 z-20 flex size-8 items-center border dark:border-gray-700 lg:hidden"
on:click={() => (sideBarHidden = true)}
/>
{/if}
Expand Down

0 comments on commit 1d6076d

Please sign in to comment.