Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingjam committed Feb 26, 2025
1 parent 6b91953 commit 0e85c19
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 80 deletions.
150 changes: 71 additions & 79 deletions packages/ui-components/src/__tests__/InputRegistryUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,80 @@ import InputRegistryUrl from '../lib/components/input/InputRegistryUrl.svelte';
import userEvent from '@testing-library/user-event';

describe('InputRegistryUrl', () => {
const mockPushState = vi.fn();
const mockReload = vi.fn();
const mockLocalStorageSetItem = vi.fn();

beforeEach(() => {
vi.stubGlobal('localStorage', {
setItem: mockLocalStorageSetItem
});

Object.defineProperty(window, 'location', {
value: {
pathname: '/test-path',
reload: mockReload
},
writable: true
});

window.history.pushState = mockPushState;

mockPushState.mockClear();
mockReload.mockClear();
mockLocalStorageSetItem.mockClear();
});

afterEach(() => {
vi.unstubAllGlobals();
});

it('should render input and button', () => {
render(InputRegistryUrl, { props: { newRegistryUrl: '' } });
const input = screen.getByPlaceholderText('Enter URL to raw strategy registry file');
const button = screen.getByText('Load Registry URL');
expect(input).toBeInTheDocument();
expect(button).toBeInTheDocument();
});

it('should bind input value to newRegistryUrl prop', async () => {
const { component } = render(InputRegistryUrl, { props: { newRegistryUrl: '' } });
const input = screen.getByPlaceholderText('Enter URL to raw strategy registry file');
const testUrl = 'https://example.com/registry.json';
const mockPushState = vi.fn();
const mockReload = vi.fn();
const mockLocalStorageSetItem = vi.fn();

beforeEach(() => {
vi.stubGlobal('localStorage', {
setItem: mockLocalStorageSetItem
});

Object.defineProperty(window, 'location', {
value: {
pathname: '/test-path',
reload: mockReload
},
writable: true
});

window.history.pushState = mockPushState;

mockPushState.mockClear();
mockReload.mockClear();
mockLocalStorageSetItem.mockClear();
});

afterEach(() => {
vi.unstubAllGlobals();
});

it('should render input and button', () => {
render(InputRegistryUrl, { props: { newRegistryUrl: '' } });

const input = screen.getByPlaceholderText('Enter URL to raw strategy registry file');
const button = screen.getByText('Load Registry URL');

expect(input).toBeInTheDocument();
expect(button).toBeInTheDocument();
});

it('should bind input value to newRegistryUrl prop', async () => {
const { component } = render(InputRegistryUrl, { props: { newRegistryUrl: '' } });

const input = screen.getByPlaceholderText('Enter URL to raw strategy registry file');
const testUrl = 'https://example.com/registry.json';

await userEvent.type(input, testUrl);

expect(input).toHaveValue(testUrl);
});

it('should handle registry URL loading when button is clicked', async () => {
const testUrl = 'https://example.com/registry.json';
render(InputRegistryUrl, { props: { newRegistryUrl: testUrl } });

const button = screen.getByText('Load Registry URL');
await fireEvent.click(button);

// Verify URL update
expect(mockPushState).toHaveBeenCalledWith(
{},
'',
'/test-path?registry=' + testUrl
);

// Verify page reload
expect(mockReload).toHaveBeenCalled();

// Verify localStorage update
expect(mockLocalStorageSetItem).toHaveBeenCalledWith('registry', testUrl);
});

it('should handle empty URL', async () => {
render(InputRegistryUrl, { props: { newRegistryUrl: '' } });

const button = screen.getByText('Load Registry URL');
await fireEvent.click(button);

expect(mockPushState).toHaveBeenCalledWith(
{},
'',
'/test-path?registry='
);
expect(mockReload).toHaveBeenCalled();
expect(mockLocalStorageSetItem).toHaveBeenCalledWith('registry', '');
});
});
it('should handle registry URL loading when button is clicked', async () => {
const testUrl = 'https://example.com/registry.json';
render(InputRegistryUrl, { props: { newRegistryUrl: testUrl } });

const button = screen.getByText('Load Registry URL');
await fireEvent.click(button);

// Verify URL update
expect(mockPushState).toHaveBeenCalledWith({}, '', '/test-path?registry=' + testUrl);

// Verify page reload
expect(mockReload).toHaveBeenCalled();

// Verify localStorage update
expect(mockLocalStorageSetItem).toHaveBeenCalledWith('registry', testUrl);
});

it('should handle empty URL', async () => {
render(InputRegistryUrl, { props: { newRegistryUrl: '' } });

const button = screen.getByText('Load Registry URL');
await fireEvent.click(button);

expect(mockPushState).toHaveBeenCalledWith({}, '', '/test-path?registry=');
expect(mockReload).toHaveBeenCalled();
expect(mockLocalStorageSetItem).toHaveBeenCalledWith('registry', '');
});
});
2 changes: 1 addition & 1 deletion packages/webapp/src/routes/deploy/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<div class="flex w-full max-w-6xl flex-col gap-y-6">
<div class="text-4xl font-semibold text-gray-900 dark:text-white">Strategies</div>

<div class="bg-primary-100 dark:bg-primary-900 flex flex-col rounded-3xl p-12">
<div class="flex flex-col rounded-3xl bg-primary-100 p-12 dark:bg-primary-900">
<h1 class="text-xl font-semibold text-gray-900 dark:text-white">
Raindex empowers you to take full control of your trading strategies. All the strategies here
are non-custodial, perpetual, and automated strategies built with our open-source, DeFi-native
Expand Down

0 comments on commit 0e85c19

Please sign in to comment.