Something went wrong. Try again.
Bluesky app fork with some witchin' additions ๐ซ
Something went wrong. Try again.
3.5 kB ยท 93 lines
TypeScript
at build
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394import {renderHook} from '@testing-library/react-native'
import {useBadgePreference} from '#/state/preferences/badge-text'import { useChatsTabBadgeDisplay, useNotificationsTabBadgeDisplay,} from '#/state/preferences/metrics-display-preference'import {useUnreadMessageCount} from '#/state/queries/messages/list-conversations'import {useUnreadNotifications} from '#/state/queries/notifications/unread'import {useAgeAssurance} from '#/ageAssurance'import {useTitleUnreadCountLabel} from './useTitleUnreadCountLabel'
jest.mock('#/state/preferences/badge-text', () => ({ useBadgePreference: jest.fn(), badgeText: jest.requireActual< typeof import('#/state/preferences/badge-text') >('#/state/preferences/badge-text').badgeText,}))jest.mock('#/state/queries/messages/list-conversations', () => ({ useUnreadMessageCount: jest.fn(),}))jest.mock('#/state/queries/notifications/unread', () => ({ useUnreadNotifications: jest.fn(),}))jest.mock('#/ageAssurance', () => ({useAgeAssurance: jest.fn()}))
jest.mock('#/state/preferences/metrics-display-preference', () => ({ useChatsTabBadgeDisplay: jest.fn(), useNotificationsTabBadgeDisplay: jest.fn(),}))
const preferences: Record<string, string | undefined> = {}
beforeEach(() => { jest.mocked(useChatsTabBadgeDisplay).mockReturnValue('exact') jest.mocked(useNotificationsTabBadgeDisplay).mockReturnValue('exact') for (const key of Object.keys(preferences)) delete preferences[key] jest .mocked(useBadgePreference) .mockImplementation(key => [preferences[key], jest.fn()]) jest.mocked(useUnreadNotifications).mockReturnValue('3') jest .mocked(useUnreadMessageCount) .mockReturnValue({count: 2, numUnread: '2', hasNew: false}) jest .mocked(useAgeAssurance) .mockReturnValue({flags: {chatDisabled: false}} as ReturnType< typeof useAgeAssurance >)})
it('defaults to notification counts independently of navigation badge settings', () => { expect(renderHook(useTitleUnreadCountLabel).result.current).toBe('3')})
it('switches to chats and uses custom text', () => { preferences.tabTitleSource = 'chats' preferences.chatsBadgeText = '๐ฌ' jest.mocked(useChatsTabBadgeDisplay).mockReturnValue('text') expect(renderHook(useTitleUnreadCountLabel).result.current).toBe('๐ฌ')})
it('shows no title badge when none is selected', () => { preferences.tabTitleSource = 'none' expect(renderHook(useTitleUnreadCountLabel).result.current).toBeUndefined()})
it('does not show custom text without unread activity', () => { preferences.notificationsBadgeText = '๐' jest.mocked(useUnreadNotifications).mockReturnValue('') expect(renderHook(useTitleUnreadCountLabel).result.current).toBeUndefined()})
it('includes chat requests without an accepted conversation count', () => { preferences.tabTitleSource = 'chats' jest.mocked(useUnreadMessageCount).mockReturnValue({count: 1, hasNew: true}) expect(renderHook(useTitleUnreadCountLabel).result.current).toBe('โข')})
it('hides chat activity when chat is disabled', () => { preferences.tabTitleSource = 'chats' jest .mocked(useAgeAssurance) .mockReturnValue({flags: {chatDisabled: true}} as ReturnType< typeof useAgeAssurance >) expect(renderHook(useTitleUnreadCountLabel).result.current).toBeUndefined()})
it('keeps saved custom text inactive in number mode', () => { preferences.notificationsBadgeText = '๐' expect(renderHook(useTitleUnreadCountLabel).result.current).toBe('3')})