2022-12-22 16:32:39 +01:00
|
|
|
import React from 'react'
|
2023-01-17 17:06:00 +01:00
|
|
|
import {Animated, Share} from 'react-native'
|
2022-12-22 16:32:39 +01:00
|
|
|
import {TabsSelector} from '../../../../src/view/shell/mobile/TabsSelector'
|
2023-01-17 17:06:00 +01:00
|
|
|
import {cleanup, fireEvent, render} from '../../../../jest/test-utils'
|
|
|
|
import {mockedNavigationStore} from '../../../../__mocks__/state-mock'
|
2022-12-22 16:32:39 +01:00
|
|
|
|
|
|
|
describe('TabsSelector', () => {
|
2023-01-17 17:06:00 +01:00
|
|
|
const onCloseMock = jest.fn()
|
|
|
|
|
2022-12-22 16:32:39 +01:00
|
|
|
const mockedProps = {
|
|
|
|
active: true,
|
|
|
|
tabMenuInterp: new Animated.Value(0),
|
2023-01-17 17:06:00 +01:00
|
|
|
onClose: onCloseMock,
|
2022-12-22 16:32:39 +01:00
|
|
|
}
|
2023-01-17 17:06:00 +01:00
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
jest.clearAllMocks()
|
|
|
|
cleanup()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders tabs selector', () => {
|
|
|
|
const {getByTestId} = render(<TabsSelector {...mockedProps} />)
|
|
|
|
|
|
|
|
const tabsSelectorView = getByTestId('tabsSelectorView')
|
|
|
|
|
|
|
|
expect(tabsSelectorView).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders nothing if inactive', () => {
|
|
|
|
const {getByTestId} = render(
|
|
|
|
<TabsSelector {...{...mockedProps, active: false}} />,
|
|
|
|
)
|
|
|
|
|
|
|
|
const emptyView = getByTestId('emptyView')
|
|
|
|
|
|
|
|
expect(emptyView).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
2023-01-18 03:40:02 +01:00
|
|
|
// TODO - this throws currently, but the tabs selector isnt being used atm so I just disabled -prf
|
|
|
|
// it('presses share button', () => {
|
|
|
|
// const shareSpy = jest.spyOn(Share, 'share')
|
|
|
|
// const {getByTestId} = render(<TabsSelector {...mockedProps} />)
|
2023-01-17 17:06:00 +01:00
|
|
|
|
2023-01-18 03:40:02 +01:00
|
|
|
// const shareButton = getByTestId('shareButton')
|
|
|
|
// fireEvent.press(shareButton)
|
2023-01-17 17:06:00 +01:00
|
|
|
|
2023-01-18 03:40:02 +01:00
|
|
|
// expect(onCloseMock).toHaveBeenCalled()
|
|
|
|
// expect(shareSpy).toHaveBeenCalledWith({url: 'https://bsky.app/'})
|
|
|
|
// })
|
2023-01-17 17:06:00 +01:00
|
|
|
|
|
|
|
it('presses clone button', () => {
|
|
|
|
const {getByTestId} = render(<TabsSelector {...mockedProps} />)
|
|
|
|
|
|
|
|
const cloneButton = getByTestId('cloneButton')
|
|
|
|
fireEvent.press(cloneButton)
|
|
|
|
|
|
|
|
expect(onCloseMock).toHaveBeenCalled()
|
|
|
|
expect(mockedNavigationStore.newTab).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('presses new tab button', () => {
|
|
|
|
const {getByTestId} = render(<TabsSelector {...mockedProps} />)
|
|
|
|
|
|
|
|
const newTabButton = getByTestId('newTabButton')
|
|
|
|
fireEvent.press(newTabButton)
|
|
|
|
|
|
|
|
expect(onCloseMock).toHaveBeenCalled()
|
|
|
|
expect(mockedNavigationStore.newTab).toHaveBeenCalledWith('/')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('presses change tab button', () => {
|
|
|
|
const {getAllByTestId} = render(<TabsSelector {...mockedProps} />)
|
|
|
|
|
|
|
|
const changeTabButton = getAllByTestId('changeTabButton')
|
|
|
|
fireEvent.press(changeTabButton[0])
|
|
|
|
|
|
|
|
expect(onCloseMock).toHaveBeenCalled()
|
|
|
|
expect(mockedNavigationStore.newTab).toHaveBeenCalledWith('/')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('presses close tab button', () => {
|
|
|
|
const {getAllByTestId} = render(<TabsSelector {...mockedProps} />)
|
|
|
|
|
|
|
|
const closeTabButton = getAllByTestId('closeTabButton')
|
|
|
|
fireEvent.press(closeTabButton[0])
|
|
|
|
|
|
|
|
expect(onCloseMock).toHaveBeenCalled()
|
|
|
|
expect(mockedNavigationStore.setActiveTab).toHaveBeenCalledWith(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('presses swipes to close the tab', () => {
|
|
|
|
const {getByTestId} = render(<TabsSelector {...mockedProps} />)
|
|
|
|
|
|
|
|
const tabsSwipable = getByTestId('tabsSwipable')
|
|
|
|
fireEvent(tabsSwipable, 'swipeableRightOpen')
|
|
|
|
|
|
|
|
expect(onCloseMock).toHaveBeenCalled()
|
|
|
|
expect(mockedNavigationStore.setActiveTab).toHaveBeenCalledWith(0)
|
2022-12-22 16:32:39 +01:00
|
|
|
})
|
|
|
|
})
|