import React from 'react';
import { StyleSheet, Text } from 'react-native';
import { render, renderHook } from '@testing-library/react-native';
import { useTheme } from '../../../theme';
import { Tab } from '..';
import { getThemedStyles } from '../styles';
import { getThemedStyles as getButtonThemedStyles } from '../../Button/styles';
const customStyles = StyleSheet.create({
tabStyle: {
backgroundColor: 'lavender',
borderTopColor: 'rebeccapurple',
},
});
describe('Tab', () => {
it('renders default Tab as expected', () => {
const { toJSON } = render(Default Tab);
expect(toJSON()).toMatchSnapshot();
});
it('renders as expected with a component passed as children', () => {
const { toJSON } = render(
Text component
);
expect(toJSON()).toMatchSnapshot();
});
it('renders as expected when Tab is selected', () => {
const { getByRole, toJSON } = render(Selected Tab);
expect(toJSON()).toMatchSnapshot();
const { result } = renderHook(() => useTheme());
const themedStyle = getThemedStyles(result.current);
const buttonThemedStyle = getButtonThemedStyles(result.current);
const tab = getByRole('tab');
expect(tab.props.style).toStrictEqual([
{ ...buttonThemedStyle.container, ...buttonThemedStyle.containerDefault },
undefined,
[
{
...themedStyle.tab,
...themedStyle.readonly,
...themedStyle.selected,
},
undefined,
undefined,
],
]);
});
it('can apply custom styling', () => {
const { getByRole, toJSON } = render(
Styled Tab
);
expect(toJSON()).toMatchSnapshot();
const { result } = renderHook(() => useTheme());
const themedStyle = getThemedStyles(result.current);
const buttonThemedStyle = getButtonThemedStyles(result.current);
const tab = getByRole('tab');
expect(tab.props.style).toStrictEqual([
{ ...buttonThemedStyle.container, ...buttonThemedStyle.containerDefault },
undefined,
[{ ...themedStyle.tab }, undefined, customStyles.tabStyle],
]);
});
});