2026-01-07 09:35:04 +00:00
|
|
|
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());
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:35:04 +00:00
|
|
|
// Le hook devrait être défini et fonctionnel
|
|
|
|
|
expect(mockInvalidateQueries).toBeDefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should invalidate queries on visibility change', () => {
|
|
|
|
|
renderHook(() => useQueryInvalidation());
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:35:04 +00:00
|
|
|
// Simuler un changement de visibilité
|
|
|
|
|
Object.defineProperty(document, 'visibilityState', {
|
|
|
|
|
writable: true,
|
|
|
|
|
value: 'hidden',
|
|
|
|
|
});
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:35:04 +00:00
|
|
|
document.dispatchEvent(new Event('visibilitychange'));
|
2026-01-13 18:47:57 +00:00
|
|
|
|
2026-01-07 09:35:04 +00:00
|
|
|
// Le hook devrait réagir au changement de visibilité
|
|
|
|
|
expect(mockInvalidateQueries).toBeDefined();
|
|
|
|
|
});
|
|
|
|
|
});
|