1
0
mirror of https://github.com/tooot-app/app synced 2024-12-25 00:53:09 +01:00
tooot/__tests__/components/Menu/Row.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-12-28 00:59:57 +01:00
import React from 'react'
import { toBeDisabled } from '@testing-library/jest-native'
import { cleanup, fireEvent, render } from '@testing-library/react-native'
import MenuRow from '@components/Menu/Row'
expect.extend({ toBeDisabled })
describe('Testing component menu row', () => {
afterEach(cleanup)
it('with title only', () => {
const { getByText, toJSON } = render(<MenuRow title='test title' />)
getByText('test title')
expect(toJSON()).toMatchSnapshot()
})
it('with title and content', () => {
const { getByText, toJSON } = render(
<MenuRow title='test title' content='test content' />
)
getByText('test title')
getByText('test content')
expect(toJSON()).toMatchSnapshot()
})
it('on press event', () => {
const onPress = jest.fn()
const { getByTestId, toJSON } = render(
<MenuRow title='test' onPress={onPress} />
)
fireEvent.press(getByTestId('base'))
expect(onPress).toHaveBeenCalled()
expect(onPress).toHaveBeenCalledTimes(1)
expect(toJSON()).toMatchSnapshot()
})
it('loading state', () => {
const onPress = jest.fn()
const { getByTestId, toJSON } = render(
<MenuRow title='test' loading onPress={onPress} />
)
fireEvent.press(getByTestId('base'))
expect(onPress).toHaveBeenCalledTimes(0)
expect(getByTestId('base')).toBeDisabled()
expect(toJSON()).toMatchSnapshot()
})
})