import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render } from '@testing-library/react';
import { PWAInitializer } from './PWAInitializer';
import { SyncManager } from '@/services/sync-manager';
import { InstallPromptService } from '@/services/install-prompt-service';

// Mock services
vi.mock('@/services/sync-manager', () => ({
    SyncManager: {
        startNetworkListener: vi.fn(),
        isOnline: vi.fn().mockReturnValue(true),
    },
}));

vi.mock('@/services/install-prompt-service', () => ({
    InstallPromptService: {
        initialize: vi.fn(),
    },
}));

// Mock store
vi.mock('@/lib/store/offline-store', () => ({
    useOfflineStore: {
        getState: () => ({
            setOnlineStatus: vi.fn(),
        }),
    },
}));

describe('PWAInitializer', () => {
    beforeEach(() => {
        vi.clearAllMocks();
    });

    it('initializes services on mount', () => {
        render(<PWAInitializer />);

        expect(SyncManager.startNetworkListener).toHaveBeenCalled();
        expect(InstallPromptService.initialize).toHaveBeenCalled();
    });
});
