diff --git a/packages/ui-components/src/__tests__/InputRegistryUrl.test.ts b/packages/ui-components/src/__tests__/InputRegistryUrl.test.ts new file mode 100644 index 000000000..6656aeba9 --- /dev/null +++ b/packages/ui-components/src/__tests__/InputRegistryUrl.test.ts @@ -0,0 +1,91 @@ +import { render, screen, fireEvent } from '@testing-library/svelte'; +import { vi } from 'vitest'; +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'; + + 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', ''); + }); +}); \ No newline at end of file diff --git a/packages/ui-components/src/lib/components/input/InputRegistryUrl.svelte b/packages/ui-components/src/lib/components/input/InputRegistryUrl.svelte new file mode 100644 index 000000000..d22e147e8 --- /dev/null +++ b/packages/ui-components/src/lib/components/input/InputRegistryUrl.svelte @@ -0,0 +1,21 @@ + + +
+ + +
diff --git a/packages/ui-components/src/lib/index.ts b/packages/ui-components/src/lib/index.ts index fe4770bb1..8bd6d167f 100644 --- a/packages/ui-components/src/lib/index.ts +++ b/packages/ui-components/src/lib/index.ts @@ -63,7 +63,7 @@ export { default as InputTokenAmount } from './components/input/InputTokenAmount export { default as WalletConnect } from './components/wallet/WalletConnect.svelte'; export { default as StrategyShortTile } from './components/deployment/StrategyShortTile.svelte'; export { default as DisclaimerModal } from './components/deployment/DisclaimerModal.svelte'; - +export { default as InputRegistryUrl } from './components/input/InputRegistryUrl.svelte'; //Types export type { AppStoresInterface } from './types/appStores.ts'; export type { diff --git a/packages/webapp/src/routes/deploy/+page.svelte b/packages/webapp/src/routes/deploy/+page.svelte index bb35c3f3a..06cd77a24 100644 --- a/packages/webapp/src/routes/deploy/+page.svelte +++ b/packages/webapp/src/routes/deploy/+page.svelte @@ -1,24 +1,17 @@ - (advancedMode = !advancedMode)}> + (advancedMode = !advancedMode)}> Advanced mode @@ -27,22 +20,14 @@
{#if advancedMode}
-
- - -
+
{/if}
Strategies
-
+

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