From a088258b3067f1a47d7c5d5ac5f3612773ece6b0 Mon Sep 17 00:00:00 2001 From: Oyinkans0la12 Date: Thu, 2 Jul 2026 22:35:24 +0100 Subject: [PATCH] . --- frontend/src/App.tsx | 1 - frontend/src/components/BridgeForm.test.tsx | 2 +- .../src/components/DiligenceSnapshot.test.tsx | 24 ++++++++++++++++--- frontend/src/components/DiligenceSnapshot.tsx | 12 ++++------ frontend/src/test/setup.ts | 2 +- frontend/src/types/vitest.d.ts | 11 +++++++++ frontend/tsconfig.json | 5 ++-- 7 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 frontend/src/types/vitest.d.ts diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index c513c86..0940bb3 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -4,7 +4,6 @@ import BridgeForm from './components/BridgeForm' import DarkVeil from './components/DarkVeil' import TransactionHistory from './components/TransactionHistory' -import DiligenceSnapshot from './components/DiligenceSnapshot' import { ToastContainer, useToast } from './components/Toast' import { useFreighter } from './hooks/useFreighter' diff --git a/frontend/src/components/BridgeForm.test.tsx b/frontend/src/components/BridgeForm.test.tsx index 62649e9..064ac00 100644 --- a/frontend/src/components/BridgeForm.test.tsx +++ b/frontend/src/components/BridgeForm.test.tsx @@ -219,7 +219,7 @@ describe('BridgeForm network mismatch guardrails', () => { hasAnyMismatch: true, }; - const alertSpy = vi.spyOn(window, 'alert').mockImplementation(() => {}); + vi.spyOn(window, 'alert').mockImplementation(() => {}); render( ({ })); // Mutable mock object for deployments -const mockDeployments = { +const mockDeployments = vi.hoisted(() => ({ ethereum: { contracts: { HTLCEscrow: '0xb352339BEb146f2699d28D736700B953988bB178', @@ -26,7 +27,7 @@ const mockDeployments = { ResolverRegistry: 'CBSR7Z4MHLPMLFFM5K3PK3YLZAVCOMJ4KPVRWO4VPL3FF64MSTIZ4WGF', }, }, -}; +})); vi.mock('../../../deployments.testnet.json', () => ({ default: mockDeployments, @@ -84,7 +85,7 @@ describe('DiligenceSnapshot', () => { (mockDeployments.ethereum.contracts as any).HTLCEscrow = ''; render(); - + // The mutated value should result in "Not configured" expect(screen.queryByText(originalEthHtlc)).not.toBeInTheDocument(); expect(screen.getByText('Sepolia HTLC contract').nextSibling).toHaveTextContent('Not configured'); @@ -93,6 +94,23 @@ describe('DiligenceSnapshot', () => { mockDeployments.ethereum.contracts.HTLCEscrow = originalEthHtlc; }); + test('renders coordinator status link when VITE_API_BASE_URL is set', () => { + vi.stubEnv('VITE_API_BASE_URL', 'https://api.test.oversync.com'); + render(); + const link = screen.getByText('Check Health'); + expect(link).toBeInTheDocument(); + expect(link).toHaveAttribute('href', 'https://api.test.oversync.com/health'); + vi.unstubAllEnvs(); + }); + + test('displays "Not configured" for coordinator status when VITE_API_BASE_URL is unset', () => { + vi.stubEnv('VITE_API_BASE_URL', ''); + render(); + expect(screen.queryByText('Check Health')).not.toBeInTheDocument(); + expect(screen.getByText('Coordinator status link').nextSibling).toHaveTextContent('Not configured'); + vi.unstubAllEnvs(); + }); + test('renders without wallet connection required', () => { const { container } = render(); expect(container.firstChild).toBeInTheDocument(); diff --git a/frontend/src/components/DiligenceSnapshot.tsx b/frontend/src/components/DiligenceSnapshot.tsx index b653c0f..5f045ab 100644 --- a/frontend/src/components/DiligenceSnapshot.tsx +++ b/frontend/src/components/DiligenceSnapshot.tsx @@ -1,4 +1,3 @@ -import React from 'react'; import { isMainnetEnabled, ETHEREUM_NETWORKS } from '../config/networks'; import deployments from '../../../deployments.testnet.json'; import { ExternalLink, ShieldAlert } from 'lucide-react'; @@ -13,13 +12,12 @@ export default function DiligenceSnapshot() { const stellarRegistry = deployments?.stellar?.contracts?.ResolverRegistry || null; // Coordinator status url - const apiBaseUrl = (import.meta as any).env?.VITE_API_BASE_URL; - const isProd = (import.meta as any).env?.PROD; - - const isCoordinatorConfigured = !!(apiBaseUrl || isProd); - const coordinatorStatusUrl = apiBaseUrl + const apiBaseUrl = import.meta.env.VITE_API_BASE_URL; + + const isCoordinatorConfigured = !!apiBaseUrl; + const coordinatorStatusUrl = apiBaseUrl ? `${apiBaseUrl.replace(/\/+$/, '')}/health` - : 'https://oversync-k36vx.ondigitalocean.app/health'; + : ''; const sepoliaExplorerBase = ETHEREUM_NETWORKS.sepolia?.explorerUrl || 'https://sepolia.etherscan.io'; diff --git a/frontend/src/test/setup.ts b/frontend/src/test/setup.ts index 010b0b5..e8ee517 100644 --- a/frontend/src/test/setup.ts +++ b/frontend/src/test/setup.ts @@ -1 +1 @@ -import '@testing-library/jest-dom' \ No newline at end of file +import '@testing-library/jest-dom/vitest' \ No newline at end of file diff --git a/frontend/src/types/vitest.d.ts b/frontend/src/types/vitest.d.ts new file mode 100644 index 0000000..9d0fb79 --- /dev/null +++ b/frontend/src/types/vitest.d.ts @@ -0,0 +1,11 @@ +import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers'; + +declare module 'vitest' { + interface Assertion extends TestingLibraryMatchers {} + interface AsymmetricMatchersContaining extends TestingLibraryMatchers {} +} + +declare module '@vitest/expect' { + interface Assertion extends TestingLibraryMatchers {} + interface AsymmetricMatchersContaining extends TestingLibraryMatchers {} +} diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 60c365f..4aed4a1 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -24,9 +24,10 @@ "baseUrl": ".", "paths": { "@/*": ["./src/*"] - } + }, + "types": ["vitest/globals"] }, "include": ["src", "src/types/**/*"], - "exclude": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/test"], + "exclude": [], "references": [{ "path": "./tsconfig.node.json" }] } \ No newline at end of file