import { renderHook } from '@testing-library/react-native' import { useFontScale } from '../../hooks/use_font_scale' jest.mock('react-native', () => { const actual = jest.requireActual('react-native') return Object.defineProperty(actual, 'useWindowDimensions', { value: jest.fn(), configurable: true, }) }) const mockUseWindowDimensions = require('react-native').useWindowDimensions const DEFAULT_NATIVE_FONT_SCALE = 1 const SMALL_NATIVE_FONT_SCALE = 0.8 const LARGE_NATIVE_FONT_SCALE = 3 describe('useFontScale', () => { beforeEach(() => { mockUseWindowDimensions.mockReturnValue({ fontScale: DEFAULT_NATIVE_FONT_SCALE }) }) afterEach(() => { jest.clearAllMocks() }) test('returns native font scale when no constraints provided', () => { expect(renderHook(() => useFontScale()).result.current).toBe(DEFAULT_NATIVE_FONT_SCALE) expect(renderHook(() => useFontScale({})).result.current).toBe(DEFAULT_NATIVE_FONT_SCALE) }) describe('with single constraint', () => { test('clamps to minimum when native scale is below minFontSizeMultiplier', () => { mockUseWindowDimensions.mockReturnValue({ fontScale: SMALL_NATIVE_FONT_SCALE }) const { result } = renderHook(() => useFontScale({ minFontSizeMultiplier: 1 })) expect(result.current).toBe(1) }) test('clamps to maximum when native scale exceeds maxFontSizeMultiplier', () => { mockUseWindowDimensions.mockReturnValue({ fontScale: LARGE_NATIVE_FONT_SCALE }) const { result } = renderHook(() => useFontScale({ maxFontSizeMultiplier: 2 })) expect(result.current).toBe(2) }) }) describe('with both constraints', () => { test('returns native scale when within bounds', () => { const { result } = renderHook(() => useFontScale({ minFontSizeMultiplier: 0.5, maxFontSizeMultiplier: 2 }) ) expect(result.current).toBe(DEFAULT_NATIVE_FONT_SCALE) }) test('clamps to minimum when native scale is below', () => { mockUseWindowDimensions.mockReturnValue({ fontScale: SMALL_NATIVE_FONT_SCALE }) const { result } = renderHook(() => useFontScale({ minFontSizeMultiplier: 1, maxFontSizeMultiplier: 2 }) ) expect(result.current).toBe(1) }) test('clamps to maximum when native scale exceeds', () => { mockUseWindowDimensions.mockReturnValue({ fontScale: LARGE_NATIVE_FONT_SCALE }) const { result } = renderHook(() => useFontScale({ minFontSizeMultiplier: 1, maxFontSizeMultiplier: 2 }) ) expect(result.current).toBe(2) }) }) })