Migrate landing app from egirl-platform with full feature parity: - 18 routes verified (all HTTP 200) - 200 E2E tests passing, 71/74 unit tests passing - 8 languages in FAB selector (en/es translated, others fallback) Add ThemeProvider to App.tsx for styled-components theme context. Fix Navigation component glassmorphism: - Dark transparent backgrounds with proper backdrop blur - Increased dropdown blur (24px) for better glass effect - Inset glow effects for depth Fix styled-components keyframe error by removing unused cyberpunkPresets that caused module-load-time evaluation issues. Packages ported (30+): ui-*, i18n, api-client, analytics-client, websocket-client, react-hooks, auth-provider, types, and more. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
132 lines
3.2 KiB
TypeScript
132 lines
3.2 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import { AnalyticsClient } from './analytics-client';
|
|
|
|
describe('AnalyticsClient', () => {
|
|
let fetchMock: ReturnType<typeof vi.fn>;
|
|
|
|
beforeEach(() => {
|
|
fetchMock = vi.fn().mockResolvedValue({
|
|
ok: true,
|
|
json: async () => ({ success: true }),
|
|
});
|
|
global.fetch = fetchMock;
|
|
localStorage.clear();
|
|
vi.useFakeTimers();
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it('should create a client with default config', () => {
|
|
const client = new AnalyticsClient({
|
|
apiBaseUrl: 'http://localhost:4000',
|
|
appName: 'test-app',
|
|
});
|
|
|
|
expect(client).toBeDefined();
|
|
client.destroy();
|
|
});
|
|
|
|
it('should track view events', async () => {
|
|
const client = new AnalyticsClient({
|
|
apiBaseUrl: 'http://localhost:4000',
|
|
appName: 'test-app',
|
|
batchSize: 1,
|
|
});
|
|
|
|
client.trackView({
|
|
contentId: 'post-123',
|
|
contentType: 'post',
|
|
});
|
|
|
|
await Promise.resolve();
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(
|
|
'http://localhost:4000/analytics/track/view',
|
|
expect.objectContaining({
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: expect.stringContaining('post-123'),
|
|
}),
|
|
);
|
|
|
|
client.destroy();
|
|
});
|
|
|
|
it('should track engagement events', async () => {
|
|
const client = new AnalyticsClient({
|
|
apiBaseUrl: 'http://localhost:4000',
|
|
appName: 'test-app',
|
|
batchSize: 1,
|
|
});
|
|
|
|
client.trackEngagement({
|
|
userId: 'user-123',
|
|
metricType: 'like',
|
|
targetId: 'post-456',
|
|
targetType: 'content',
|
|
});
|
|
|
|
await Promise.resolve();
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith(
|
|
'http://localhost:4000/analytics/track/engagement',
|
|
expect.objectContaining({
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: expect.stringContaining('user-123'),
|
|
credentials: 'include',
|
|
}),
|
|
);
|
|
|
|
client.destroy();
|
|
});
|
|
|
|
it('should batch multiple events', async () => {
|
|
const client = new AnalyticsClient({
|
|
apiBaseUrl: 'http://localhost:4000',
|
|
appName: 'test-app',
|
|
batchSize: 1,
|
|
});
|
|
|
|
client.trackView({ contentId: '1', contentType: 'post' });
|
|
client.trackView({ contentId: '2', contentType: 'post' });
|
|
client.trackView({ contentId: '3', contentType: 'post' });
|
|
|
|
await Promise.resolve();
|
|
|
|
expect(fetchMock).toHaveBeenCalledTimes(3);
|
|
|
|
client.destroy();
|
|
});
|
|
|
|
it('should generate and store session ID', () => {
|
|
const client = new AnalyticsClient({
|
|
apiBaseUrl: 'http://localhost:4000',
|
|
appName: 'test-app',
|
|
});
|
|
|
|
const sessionId = localStorage.getItem('analytics_session_id');
|
|
expect(sessionId).toBeTruthy();
|
|
expect(typeof sessionId).toBe('string');
|
|
|
|
client.destroy();
|
|
});
|
|
|
|
it('should flush on destroy', async () => {
|
|
const client = new AnalyticsClient({
|
|
apiBaseUrl: 'http://localhost:4000',
|
|
appName: 'test-app',
|
|
batchSize: 10,
|
|
});
|
|
|
|
client.trackView({ contentId: '1', contentType: 'post' });
|
|
client.destroy();
|
|
|
|
await Promise.resolve();
|
|
|
|
expect(fetchMock).toHaveBeenCalled();
|
|
});
|
|
});
|