Ruview/ui/mobile/src/__tests__/utils/urlValidator.test.ts
rUv d4fb7d30d3
fix: complete sensing server API, WebSocket connectivity, and mobile tests (#125)
The web UI had persistent 404 errors on model, recording, and training
endpoints, and the sensing WebSocket never connected on Dashboard/Live
Demo tabs because sensingService.start() was only called lazily on
Sensing tab visit.

Server (main.rs):
- Add 14 fully-functional Axum handlers: model CRUD (7), recording
  lifecycle (4), training control (3)
- Scan data/models/ and data/recordings/ at startup
- Recording writes CSI frames to .jsonl via tokio background task
- Model load/unload lifecycle with state tracking

Web UI (app.js):
- Import and start sensingService early in initializeServices() so
  Dashboard and Live Demo tabs connect to /ws/sensing immediately

Mobile (ws.service.ts):
- Fix WebSocket URL builder to use same-origin port instead of
  hardcoded port 3001

Mobile (jest.config.js):
- Fix testPathIgnorePatterns that was ignoring the entire test directory

Mobile (25 test files):
- Replace all it.todo() placeholder tests with real implementations
  covering components, services, stores, hooks, screens, and utils

ADR-043 documents all changes.
2026-03-03 13:27:03 -05:00

76 lines
2.4 KiB
TypeScript

import { validateServerUrl } from '@/utils/urlValidator';
describe('validateServerUrl', () => {
it('accepts valid http URL', () => {
const result = validateServerUrl('http://localhost:3000');
expect(result.valid).toBe(true);
expect(result.error).toBeUndefined();
});
it('accepts valid https URL', () => {
const result = validateServerUrl('https://example.com');
expect(result.valid).toBe(true);
});
it('accepts valid ws URL', () => {
const result = validateServerUrl('ws://192.168.1.1:8080');
expect(result.valid).toBe(true);
});
it('accepts valid wss URL', () => {
const result = validateServerUrl('wss://example.com/ws');
expect(result.valid).toBe(true);
});
it('rejects empty string', () => {
const result = validateServerUrl('');
expect(result.valid).toBe(false);
expect(result.error).toBe('URL must be a non-empty string.');
});
it('rejects whitespace-only string', () => {
const result = validateServerUrl(' ');
expect(result.valid).toBe(false);
expect(result.error).toBe('URL must be a non-empty string.');
});
it('rejects null input', () => {
const result = validateServerUrl(null as unknown as string);
expect(result.valid).toBe(false);
expect(result.error).toBe('URL must be a non-empty string.');
});
it('rejects undefined input', () => {
const result = validateServerUrl(undefined as unknown as string);
expect(result.valid).toBe(false);
expect(result.error).toBe('URL must be a non-empty string.');
});
it('rejects numeric input', () => {
const result = validateServerUrl(123 as unknown as string);
expect(result.valid).toBe(false);
expect(result.error).toBe('URL must be a non-empty string.');
});
it('rejects ftp protocol', () => {
const result = validateServerUrl('ftp://files.example.com');
expect(result.valid).toBe(false);
expect(result.error).toBe('URL must use http, https, ws, or wss.');
});
it('rejects file protocol', () => {
const result = validateServerUrl('file:///etc/passwd');
expect(result.valid).toBe(false);
});
it('rejects malformed URL', () => {
const result = validateServerUrl('not-a-url');
expect(result.valid).toBe(false);
expect(result.error).toBe('Invalid URL format.');
});
it('rejects URL with no host', () => {
const result = validateServerUrl('http://');
expect(result.valid).toBe(false);
});
});