useShowMultigresLogs.test.ts60 lines · main
| 1 | import { renderHook } from '@testing-library/react' |
| 2 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 3 | |
| 4 | import { useShowMultigresLogs } from './useShowMultigresLogs' |
| 5 | |
| 6 | const mockUseFlag = vi.fn() |
| 7 | const mockUseIsHighAvailability = vi.fn() |
| 8 | |
| 9 | vi.mock('common', async (importOriginal) => ({ |
| 10 | ...(await importOriginal<typeof import('common')>()), |
| 11 | useFlag: (name: string) => mockUseFlag(name), |
| 12 | })) |
| 13 | |
| 14 | vi.mock('./useSelectedProject', () => ({ |
| 15 | useIsHighAvailability: () => mockUseIsHighAvailability(), |
| 16 | })) |
| 17 | |
| 18 | describe('useShowMultigresLogs', () => { |
| 19 | beforeEach(() => { |
| 20 | mockUseFlag.mockReset() |
| 21 | mockUseIsHighAvailability.mockReset() |
| 22 | }) |
| 23 | |
| 24 | it('returns true only when the multigresLogs flag and high availability are both enabled', () => { |
| 25 | mockUseFlag.mockReturnValue(true) |
| 26 | mockUseIsHighAvailability.mockReturnValue(true) |
| 27 | |
| 28 | const { result } = renderHook(() => useShowMultigresLogs()) |
| 29 | |
| 30 | expect(result.current).toBe(true) |
| 31 | expect(mockUseFlag).toHaveBeenCalledWith('multigresLogs') |
| 32 | }) |
| 33 | |
| 34 | it('returns false when the flag is off, even on a high availability project', () => { |
| 35 | mockUseFlag.mockReturnValue(false) |
| 36 | mockUseIsHighAvailability.mockReturnValue(true) |
| 37 | |
| 38 | const { result } = renderHook(() => useShowMultigresLogs()) |
| 39 | |
| 40 | expect(result.current).toBe(false) |
| 41 | }) |
| 42 | |
| 43 | it('returns false when the project is not high availability, even with the flag on', () => { |
| 44 | mockUseFlag.mockReturnValue(true) |
| 45 | mockUseIsHighAvailability.mockReturnValue(false) |
| 46 | |
| 47 | const { result } = renderHook(() => useShowMultigresLogs()) |
| 48 | |
| 49 | expect(result.current).toBe(false) |
| 50 | }) |
| 51 | |
| 52 | it('returns false when both the flag and high availability are off', () => { |
| 53 | mockUseFlag.mockReturnValue(false) |
| 54 | mockUseIsHighAvailability.mockReturnValue(false) |
| 55 | |
| 56 | const { result } = renderHook(() => useShowMultigresLogs()) |
| 57 | |
| 58 | expect(result.current).toBe(false) |
| 59 | }) |
| 60 | }) |