Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.0 KB
Raw Blame
import { act, fireEvent, render, screen } from '@testing-library/react-native'

import { track } from '@/lib/analytics'
import { useAppearanceStore } from '@/ui/appearanceStore'
import { AppearanceGroup } from './AppearanceGroup'

jest.mock('@/lib/analytics', () => ({ track: jest.fn() }))

describe('AppearanceGroup', () => {
    afterEach(() => {
        act(() => useAppearanceStore.setState({ appearance: 'system' }))
    })

    test('choosing Dark saves the override and reports the change', () => {
        render(<AppearanceGroup />)
        expect(screen.getByTestId('appearance-system').props.accessibilityState).toMatchObject({ checked: true })

        fireEvent.press(screen.getByTestId('appearance-dark'))

        expect(useAppearanceStore.getState().appearance).toBe('dark')
        expect(screen.getByTestId('appearance-dark').props.accessibilityState).toMatchObject({ checked: true })
        expect(track).toHaveBeenCalledWith('mobile_appearance_changed', {
            appearance: 'dark',
            previous_appearance: 'system',
        })
    })
})