useShowMultigresLogs.test.ts 1.8 KB

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