Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
5.9 kB · 215 lines
TSX
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216import {fireEvent, render, within} from '@testing-library/react-native'
import * as Menu from '#/components/Menu'import {RepostButtonMenu} from './RepostButtonMenu'
jest.mock('#/state/session', () => ({ useRequireAuth: () => (callback: () => void) => callback(), useSession: () => ({hasSession: true}),}))jest.mock('#/alf', () => ({ useTheme: () => ({palette: {positive_500: 'green'}}),}))jest.mock('#/components/Menu', () => { const {Pressable, Text, View} = require('react-native') const open = jest.fn() const unanchoredOpen = jest.fn()
return { __testOpen: open, __testUnanchoredOpen: unanchoredOpen, Root: ({children}: React.PropsWithChildren) => <View>{children}</View>, Trigger: ({ children, label, }: { children: (args: { control: {open: () => void} props: {accessibilityLabel: string; onPress: () => void} }) => React.ReactNode label: string }) => children({ control: {open: unanchoredOpen}, props: {accessibilityLabel: label, onPress: open}, }), Outer: ({children}: React.PropsWithChildren) => <View>{children}</View>, Group: ({children}: React.PropsWithChildren) => ( <View testID="menuGroup">{children}</View> ), Item: ({ children, disabled, label, onPress, testID, }: React.PropsWithChildren<{ disabled?: boolean label: string onPress: () => void testID: string }>) => ( <Pressable accessibilityHint="" accessibilityLabel={label} accessibilityState={{disabled}} disabled={disabled} onPress={onPress} testID={testID}> {children} </Pressable> ), ItemText: ({children}: React.PropsWithChildren) => <Text>{children}</Text>, ItemIcon: () => null, }})jest.mock('#/components/PostControls/util', () => ({ useFormatPostStatCount: () => String,}))jest.mock('./PostControlButton', () => { const {Pressable, Text} = require('react-native')
return { PostControlButton: ({ children, label, onLongPress, onPress, testID, }: React.PropsWithChildren<{ label?: string onLongPress?: () => void onPress?: () => void testID?: string }>) => ( <Pressable accessibilityHint="" accessibilityLabel={label} onLongPress={onLongPress} onPress={onPress} testID={testID}> {children} </Pressable> ), PostControlButtonIcon: () => null, PostControlButtonText: ({ children, testID, }: React.PropsWithChildren<{ testID?: string }>) => <Text testID={testID}>{children}</Text>, }})jest.mock('#/view/com/util/EventStopper', () => ({ EventStopper: ({children}: React.PropsWithChildren) => children,}))jest.mock('@lingui/react', () => ({ useLingui: () => ({ _: (message: {message?: string} | string) => typeof message === 'string' ? message : message.message, }),}))
const mockMenuOpen = (Menu as unknown as {__testOpen: jest.Mock}).__testOpenconst mockUnanchoredOpen = ( Menu as unknown as {__testUnanchoredOpen: jest.Mock}).__testUnanchoredOpen
afterEach(() => { jest.clearAllMocks()})
describe('RepostButtonMenu', () => { it('does not pass the press event into the quote account-picker option', () => { const onQuote = jest.fn() const screen = render( <RepostButtonMenu isReposted={false} onRepost={jest.fn()} onQuote={onQuote} embeddingDisabled={false} />, )
fireEvent.press(screen.getByTestId('repostDropdownQuoteBtn'), { nativeEvent: {}, })
expect(onQuote).toHaveBeenCalledTimes(1) expect(onQuote).toHaveBeenCalledWith() })
it('keeps repost and quote together in one group', () => { const screen = render( <RepostButtonMenu isReposted={false} onRepost={jest.fn()} onQuote={jest.fn()} embeddingDisabled={false} />, ) const group = within(screen.getByTestId('menuGroup'))
expect(group.getByTestId('repostDropdownRepostBtn')).toBeTruthy() expect(group.getByTestId('repostDropdownQuoteBtn')).toBeTruthy() })
it('keeps Undo repost available and disables quote when embedding is disabled', () => { const onRepost = jest.fn() const onQuote = jest.fn() const screen = render( <RepostButtonMenu isReposted onRepost={onRepost} onQuote={onQuote} embeddingDisabled />, )
const undoButton = screen.getByTestId('repostDropdownRepostBtn') const quoteButton = screen.getByTestId('repostDropdownQuoteBtn')
expect(undoButton.props.accessibilityLabel).toBe('Undo repost') fireEvent.press(undoButton) expect(onRepost).toHaveBeenCalledTimes(1)
expect(quoteButton.props.accessibilityLabel).toBe('Quote posts disabled') fireEvent.press(quoteButton) expect(onQuote).not.toHaveBeenCalled() })
it('opens the menu on long press when quote is disabled', () => { const screen = render( <RepostButtonMenu isReposted={false} onRepost={jest.fn()} onQuote={jest.fn()} embeddingDisabled longPressToQuote />, )
fireEvent(screen.getByTestId('repostBtn'), 'longPress')
expect(mockMenuOpen).toHaveBeenCalledTimes(1) expect(mockUnanchoredOpen).not.toHaveBeenCalled() })
it('keeps long press-to-quote when quote is enabled', () => { const onQuote = jest.fn() const screen = render( <RepostButtonMenu isReposted={false} onRepost={jest.fn()} onQuote={onQuote} embeddingDisabled={false} longPressToQuote />, )
fireEvent(screen.getByTestId('repostBtn'), 'longPress')
expect(onQuote).toHaveBeenCalledTimes(1) expect(mockMenuOpen).not.toHaveBeenCalled() })})