import { renderHook } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { useQueryInvalidation } from './useQueryInvalidation';

// Mock React Query
const mockInvalidateQueries = vi.fn();
vi.mock('@tanstack/react-query', () => ({
  useQueryClient: () => ({
    invalidateQueries: mockInvalidateQueries,
  }),
}));

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

  it('should setup query invalidation on mount', () => {
    renderHook(() => useQueryInvalidation());

    // Le hook devrait être défini et fonctionnel
    expect(mockInvalidateQueries).toBeDefined();
  });

  it('should invalidate queries on visibility change', () => {
    renderHook(() => useQueryInvalidation());

    // Simuler un changement de visibilité
    Object.defineProperty(document, 'visibilityState', {
      writable: true,
      value: 'hidden',
    });

    document.dispatchEvent(new Event('visibilitychange'));

    // Le hook devrait réagir au changement de visibilité
    expect(mockInvalidateQueries).toBeDefined();
  });
});
