import React from 'react';
import { render } from '@testing-library/react-native';
import { theme as defaultTheme } from '../../theme';
import { NativeBaseProvider } from '../../core/NativeBaseProvider';
import {
Box,
Button,
Pressable,
// Select,
Image,
Spinner,
Text,
Input,
Checkbox,
Slider,
// Icon,
HStack,
Heading,
} from '../../components/primitives';
// import { Ionicons } from '@expo/vector-icons';
import { FormControl, Menu } from '../../components/composites';
import { Platform } from 'react-native';
import { extendTheme } from '../../core/extendTheme';
import { fireEvent } from '@testing-library/react-native';
// import { InfoIcon } from '../../components/primitives/Icon/Icons';
const inset = {
frame: { x: 0, y: 0, width: 0, height: 0 },
insets: { top: 0, left: 0, right: 0, bottom: 0 },
};
const Provider = ({ children, theme = defaultTheme }: any) => {
return (
{children}
);
};
function CheckBoxGroup() {
const [groupValue, setGroupValue] = React.useState(['Item 1 ', 'Item 3 ']);
return (
{
setGroupValue(values || []);
}}
>
Item 1
Item 2
Item 3
Indeterminate Item
);
}
describe('props resolution', () => {
it('tests simple resolution', () => {
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style.paddingLeft).toBe(defaultTheme.space['2']);
expect(box.props.style.paddingRight).toBe(defaultTheme.space['2']);
expect(box.props.style.paddingTop).toBe(defaultTheme.space['2']);
expect(box.props.style.paddingBottom).toBe(defaultTheme.space['2']);
});
it('tests simple resolution with responsive props', () => {
const { getByTestId } = render(
hello world
hello world
);
const box = getByTestId('test');
expect(box.props.style.paddingLeft).toBe(defaultTheme.space['4']);
expect(box.props.style.paddingRight).toBe(defaultTheme.space['4']);
expect(box.props.style.paddingTop).toBe(defaultTheme.space['4']);
expect(box.props.style.paddingBottom).toBe(defaultTheme.space['4']);
const box2 = getByTestId('test2');
expect(box2.props.style.paddingLeft).toBe(defaultTheme.space['5']);
expect(box2.props.style.paddingRight).toBe(defaultTheme.space['5']);
expect(box2.props.style.paddingTop).toBe(defaultTheme.space['5']);
expect(box2.props.style.paddingBottom).toBe(defaultTheme.space['5']);
});
it('resolves platform props', () => {
Platform.OS = 'android';
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style.paddingLeft).toBe(defaultTheme.space['10']);
expect(box.props.style.paddingRight).toBe(defaultTheme.space['10']);
expect(box.props.style.paddingTop).toBe(defaultTheme.space['10']);
expect(box.props.style.paddingBottom).toBe(defaultTheme.space['10']);
});
it('resolves base style with props', () => {
const newTheme = extendTheme({
components: {
Box: {
baseStyle: {
py: 10,
bg: 'cyan.500',
},
},
},
});
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style).toEqual({
paddingTop: newTheme.space['5'],
paddingBottom: newTheme.space['5'],
paddingLeft: newTheme.space['5'],
paddingRight: newTheme.space['5'],
backgroundColor: newTheme.colors.cyan['500'],
});
});
it('resolves base style and variants with props', () => {
const newTheme = extendTheme({
components: {
Box: {
baseStyle: {
py: 10,
bg: 'cyan.500',
},
variants: {
myBox: () => ({
mt: 10,
}),
},
},
},
});
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style).toEqual({
marginTop: newTheme.space['10'],
paddingTop: newTheme.space['5'],
paddingBottom: newTheme.space['5'],
paddingLeft: newTheme.space['5'],
paddingRight: newTheme.space['5'],
backgroundColor: newTheme.colors.cyan['500'],
});
});
it('resolves base style, variants and sizes with props', () => {
const newTheme = extendTheme({
components: {
Box: {
baseStyle: {
py: 10,
bg: 'cyan.500',
},
variants: {
myBox: () => ({
mt: 10,
}),
},
sizes: {
xs: {
height: 10,
},
},
},
},
});
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style).toEqual({
marginTop: newTheme.space['10'],
paddingTop: newTheme.space['5'],
paddingBottom: newTheme.space['5'],
paddingLeft: newTheme.space['5'],
paddingRight: newTheme.space['5'],
height: newTheme.sizes['10'],
backgroundColor: newTheme.colors.cyan['500'],
});
});
it('tests component sizes resolution', () => {
const { getByTestId } = render(
);
const image = getByTestId('image');
const spinner = getByTestId('spinner');
expect(image.props.style).toEqual({
height: defaultTheme.space['20'],
maxWidth: '100%',
width: defaultTheme.space['20'],
});
expect(spinner.props.style).toEqual([[{}, { dataSet: {} }], undefined]);
});
it('resolves base style and variants, sizes and default props with props', () => {
const newTheme = extendTheme({
components: {
Box: {
baseStyle: {
py: 10,
bg: 'cyan.500',
},
variants: {
myBox: () => ({
mt: 10,
}),
},
sizes: {
xs: {
height: 10,
},
},
defaultProps: {
size: 'xs',
},
},
},
});
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style).toEqual({
marginTop: newTheme.space['10'],
paddingTop: newTheme.space['5'],
paddingBottom: newTheme.space['5'],
paddingLeft: newTheme.space['5'],
paddingRight: newTheme.space['5'],
height: newTheme.sizes['10'],
backgroundColor: newTheme.colors.cyan['500'],
});
});
it('tests alpha opacity resolution', () => {
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style.backgroundColor).toBe(
'rgba(34, 211, 238, ' + defaultTheme.opacity['50'] + ')'
);
});
it('resolves negative margins', () => {
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style).toEqual({
marginTop: -defaultTheme.space['10'],
marginRight: -defaultTheme.space['5'],
marginBottom: -defaultTheme.space['5'],
marginLeft: -defaultTheme.space['5'],
});
});
it('resolves shadow from theme', () => {
const { getByTestId } = render(
hello world
);
const box = getByTestId('test');
expect(box.props.style).toEqual(defaultTheme.shadows[9]);
});
it('FormControl: pseudo props test ', () => {
const { getByTestId } = render(
);
const formControl = getByTestId('test');
expect(formControl.props.style).toEqual({
borderLeftWidth: 1,
marginTop: defaultTheme.space['1'],
paddingLeft: defaultTheme.space['2'],
paddingRight: defaultTheme.space['1'],
borderColor: defaultTheme.colors.gray['400'],
});
});
it('Menu: style props test', () => {
const { getByTestId } = render(
);
const triggerElement = getByTestId('pressableTest');
fireEvent.press(triggerElement);
const menuItem = getByTestId('test');
const disabledMenuItem = getByTestId('test1');
expect(menuItem.props.style.backgroundColor).toBe(
defaultTheme.colors.blue['300']
);
expect(disabledMenuItem.props.style.backgroundColor).toBe(
defaultTheme.colors.pink['300']
);
});
it('Button: style props test', () => {
const { getByTestId } = render(
);
const buttonElement = getByTestId('test');
const buttonText = getByTestId('test1');
expect(buttonText.props.style.color).toBe(defaultTheme.colors.cyan['100']);
expect(buttonElement.props.style.backgroundColor).toBe(
defaultTheme.colors.pink['900']
);
});
it('Button: style props test on ios with dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
Platform.OS = 'ios';
const { getByTestId } = render(
);
const buttonElement = getByTestId('test');
const buttonText = getByTestId('test1');
expect(buttonText.props.style.color).toBe(defaultTheme.colors.cyan['100']);
expect(buttonElement.props.style.backgroundColor).toBe(
defaultTheme.colors.pink['900']
);
});
it('Button: style responsive props test on ios with dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
Platform.OS = 'ios';
const { getByTestId } = render(
);
const buttonElement = getByTestId('test');
const buttonText = getByTestId('test1');
expect(buttonText.props.style.color).toBe(defaultTheme.colors.cyan['100']);
expect(buttonElement.props.style.backgroundColor).toBe(
defaultTheme.colors.blue['900']
);
});
it('Image: style responsive props test on ios with dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
Platform.OS = 'ios';
const { getByTestId } = render(
);
const imageElement = getByTestId('test');
expect(imageElement.props.style).toEqual({
height: defaultTheme.space['20'],
maxWidth: '100%',
width: defaultTheme.space['20'],
});
});
it('Input: Basic check', () => {
const { getByTestId } = render(
);
const inputElement = getByTestId('test');
const inputElementStack = getByTestId('StackTest');
expect(inputElement.props.style.width).toBe('100%');
expect(inputElement.props.placeholderTextColor).toBe(
defaultTheme.colors.blueGray['400']
);
expect(inputElementStack.props.style.marginLeft).toBe(
defaultTheme.space['3']
);
expect(inputElementStack.props.style.marginRight).toBe(
defaultTheme.space['3']
);
});
it('Input: color mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
const { getByTestId } = render(
);
const inputElement = getByTestId('test');
expect(inputElement.props.placeholderTextColor).toBe(
defaultTheme.colors.blueGray['50']
);
});
it('Input: size', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
const { getByTestId } = render(
);
const inputElement = getByTestId('test');
expect(inputElement.props.style.fontSize).toBe(defaultTheme.fontSizes.sm);
});
it('Input: variant', () => {
const { getByTestId } = render(
);
const inputElement = getByTestId('test');
expect(inputElement.props.style.borderBottomWidth).toBe(1);
});
// it('Input: inputElements', () => {
// const { getByTestId } = render(
//
// leftIcon}
// placeholder="Input"
// />
//
// );
// const inputElement = getByTestId('test1');
// const iconElement = getByTestId('test2');
// console.log(inputElement, '!!!!!');
// console.log('===========');
// console.log(inputElement.props, '!!!!!');
// expect(inputElement.props.InputLeftElement).toBe(iconElement);
// });
it('Input: style props test on ios with dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
Platform.OS = 'ios';
const { getByTestId } = render(
);
const inputElement = getByTestId('test');
const inputElementStack = getByTestId('stackTest');
expect(inputElementStack.props.style.borderBottomWidth).toBe(1);
// as input of 'sm' size is mapped to 'xs' fontsize
expect(inputElement.props.style.fontSize).toBe(defaultTheme.fontSizes.xs);
});
// it('Input: inputElemets', () => {
// const { getByTestId } = render(
//
// leftIcon}
// placeholder="Input"
// />
//
// );
// const inputElement = getByTestId('test1');
// const iconElement = getByTestId('test2');
// console.log(inputElement, '!!!!!');
// console.log('===========');
// console.log(inputElement.props, '!!!!!');
// expect(inputElement.props.InputLeftElement).toBe(iconElement);
// });
it('Input: disabled', () => {
const { getByTestId } = render(
);
const inputElement = getByTestId('test');
expect(inputElement.props.disabled).toBe(true);
expect(inputElement.props.required).toBe(true);
});
// ==========================================
it('handles defaults and onChange on checkBoxGroup', () => {
const { getAllByRole } = render(
);
const checkbox = getAllByRole('checkbox');
expect(checkbox.length).toBe(4);
expect(checkbox[0].props.accessibilityState.checked).toBe(true);
expect(checkbox[1].props.accessibilityState.checked).toBe(false);
expect(checkbox[2].props.accessibilityState.checked).toBe(true);
expect(checkbox[3].props.accessibilityState.checked).toBe(false);
fireEvent.press(checkbox[1]);
expect(checkbox[1].props.accessibilityState.checked).toBe(true);
});
it('checkBox: disabled, checked', () => {
const { getAllByRole } = render(
Item 1
Item 2
Item 3
Indeterminate Item
);
const checkbox = getAllByRole('checkbox');
expect(checkbox.length).toBe(4);
expect(checkbox[1].props.accessibilityState.disabled).toBe(true);
expect(checkbox[2].props.accessibilityState.checked).toBe(true);
// expect(checkbox[3].props.accessibilityState.invalid).toBe(true);
});
// it('Checkbox: style props test with dark mode', () => {
// const newTheme = extendTheme({
// config: { initialColorMode: 'dark' },
// });
// const { getAllByRole } = render(
//
//
// Item 1
//
//
// );
// let checkbox = getAllByRole('checkbox');
// console.log(checkbox[0].props.accessibilityState, '@@@@');
// expect(checkbox[0].props.accessibilityState.checked).toBe(false);
// expect(checkbox[0].props.accessibilityState.disabled).toBe(true);
// });
// it('Checkbox: style props test on ios with dark mode', () => {
// const newTheme = extendTheme({
// config: { initialColorMode: 'dark' },
// });
// Platform.OS = 'ios';
// const { getAllByRole } = render(
//
//
// Item 1
//
//
// );
// let checkbox = getAllByRole('checkbox');
// console.log(checkbox[0].props.accessibilityState, '@@@@');
// expect(checkbox[0].props.accessibilityState.checked).toBe(false);
// expect(checkbox[0].props.accessibilityState.disabled).toBe(true);
// });
it('onChange on checkBox', () => {
const { getAllByRole } = render(
);
const checkbox = getAllByRole('checkbox');
expect(checkbox.length).toBe(1);
fireEvent.press(checkbox[0]);
expect(checkbox[0].props.accessibilityState.checked).toBe(true);
});
// it('CustomIcon checkBox', () => {
// let { getAllByRole, getByTestId } = render(
//
// } />}
// defaultIsChecked
// >
// Info
//
//
// );
// let checkbox = getAllByRole('checkbox');
// let nestedIcon = getByTestId('icon');
// expect(checkbox[0].props.icon).toBe(nestedIcon);
// });
// ==========================================
it('Slider: basic', () => {
const { getByTestId } = render(
);
const sliderElement = getByTestId('slider');
expect(sliderElement.props.minValue).toBe(0);
expect(sliderElement.props.maxValue).toBe(100);
expect(sliderElement.props.step).toBe(10);
expect(sliderElement.props.thumbSize).toBe(4);
expect(sliderElement.props.sliderSize).toBe(4);
expect(sliderElement.props.colorScheme).toBe('red');
});
// ==========================================
// it('Modal: size', () => {
// const { getByTestId } = render(
//
//
//
// Modal Title
//
// Sit nulla est ex deserunt exercitation anim occaecat. Nostrud
// ullamco deserunt aute id consequat veniam incididunt duis in sint
// irure nisi. Mollit officia cillum Lorem ullamco minim nostrud elit
// officia tempor esse quis. Sunt ad dolore quis aute consequat.
// Magna exercitation reprehenderit magna aute tempor cupidatat
// consequat elit dolor adipisicing. Mollit dolor eiusmod sunt ex
// incididunt cillum quis. Velit duis sit officia eiusmod Lorem
// aliqua enim laboris do dolor eiusmod. Et mollit incididunt nisi
// consectetur esse laborum eiusmod pariatur
//
//
//
//
// );
// const modalElement = getByTestId('size');
// // console.log(modalElement, 'jdj');
// expect(modalElement.props.style.width).toBe('60%');
// });
it('Slider: style props test with dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
const { getByTestId } = render(
);
const sliderElement = getByTestId('test');
expect(sliderElement.props.minValue).toBe(20);
expect(sliderElement.props.maxValue).toBe(120);
expect(sliderElement.props.step).toBe(25);
expect(sliderElement.props.thumbSize).toBe(5);
expect(sliderElement.props.sliderSize).toBe(5);
expect(sliderElement.props.colorScheme).toBe('blue');
});
it('tests lineHeight & letterspacing in text ', () => {
const { getByTestId } = render(
This is a text
);
const text = getByTestId('test');
expect(text.props.style.lineHeight).toBe(80);
expect(text.props.style.letterSpacing).toBe(1);
});
it('Slider: style props test on ios with dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
Platform.OS = 'ios';
const { getByTestId } = render(
);
const sliderElement = getByTestId('test');
expect(sliderElement.props.minValue).toBe(10);
expect(sliderElement.props.maxValue).toBe(110);
expect(sliderElement.props.step).toBe(15);
expect(sliderElement.props.thumbSize).toBe(5);
expect(sliderElement.props.sliderSize).toBe(5);
expect(sliderElement.props.colorScheme).toBe('green');
});
it('HStack: basic', () => {
const { getByTestId } = render(
1
2
3
);
const hstackElement = getByTestId('hstack');
expect(hstackElement.props.style.flexDirection).toBe('row');
});
it('HStack: direction', () => {
const { getByTestId } = render(
1
2
3
);
const hstackElement = getByTestId('test');
expect(hstackElement.props.style.flexDirection).toBe('column');
});
// it('Icon: basic', () => {
// const { getByTestId } = render(
//
// } />
//
// );
// const iconElement = getByTestId('test123');
// expect(iconElement.props.style.backgroundColor).toBe(
// defaultTheme.colors.red['200']
// );
// });
// it('Icon: Nativebase icons', () => {
// const { getByTestId } = render(
//
//
//
// );
// const iconElement = getByTestId('test');
// expect(pressableElement.props.style.backgroundColor).toBe(
// defaultTheme.colors.red['200']
// );
// });
it('Pressable: style props test', () => {
const { getByTestId } = render(
hello world
);
const pressableElement = getByTestId('test');
expect(pressableElement.props.style.backgroundColor).toBe(
defaultTheme.colors.red['200']
);
});
// it('Pressable: style props test on ios with dark mode', () => {
// const newTheme = extendTheme({
// config: { initialColorMode: 'dark' },
// });
// Platform.OS = 'ios';
// const { getByTestId } = render(
//
//
// PRIMARY
//
//
// );
// const buttonElement = getByTestId('test');
// expect(buttonElement.props.style.backgroundColor).toBe(
// defaultTheme.colors.pink['900']
// );
// });
// it('Pressable: style responsive props test on ios with dark mode', () => {
// const newTheme = extendTheme({
// config: { initialColorMode: 'dark' },
// });
// Platform.OS = 'ios';
// const { getByTestId } = render(
//
//
// PRIMARY
//
//
// );
// const buttonElement = getByTestId('test');
// expect(buttonElement.props.style.backgroundColor).toBe(
// defaultTheme.colors.blue['900']
// );
// });
// });
it('HStack: style props test with dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
const { getByTestId } = render(
1
2
3
);
const hstackElement = getByTestId('test');
expect(hstackElement.props.style.flexDirection).toBe('row');
});
it('HStack: style props test on ios & dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
const { getByTestId } = render(
This is a text
hello world
);
const text = getByTestId('test');
const responsiveLineHeight = getByTestId('responsiveLineHeight');
expect(text.props.style.lineHeight).toBe(37.5);
expect(text.props.style.letterSpacing).toBe(0.375);
expect(responsiveLineHeight.props.style.lineHeight).toBe(32.5);
});
it('Heading: style props test on ios with dark mode', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
});
Platform.OS = 'ios';
const { getByTestId } = render(
This is a Heading
);
const heading = getByTestId('test');
expect(heading.props.style.lineHeight).toBe(37.5);
expect(heading.props.style.letterSpacing).toBe(0.375);
});
it('Pseudo props test: importatnt on Button', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
components: {
Button: {
baseStyle: {
_important: {
bg: 'green.400',
},
},
},
},
});
const { getByTestId } = render(
);
const button = getByTestId('test');
expect(button.props.style.backgroundColor).toBe(
defaultTheme.colors.green['400']
);
});
it('Pseudo props test: normal prop on light and dark', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
components: {
Button: {
baseStyle: {
_light: {
bg: 'green.700',
},
_dark: {
bg: 'green.100',
},
},
},
},
});
const { getByTestId } = render(
);
const button = getByTestId('test');
expect(button.props.style.backgroundColor).toBe(
defaultTheme.colors.amber['500']
);
});
it('Pseudo props test: _important overrided', () => {
const newTheme = extendTheme({
config: { initialColorMode: 'dark' },
components: {
Button: {
baseStyle: {
_important: {
bg: 'green.400',
},
},
variants: {
solid: {
_important: {
bg: 'emerald.800',
_text: {
color: 'white',
},
},
},
},
},
},
});
const { getByTestId } = render(
);
const button = getByTestId('test');
expect(button.props.style.backgroundColor).toBe(
defaultTheme.colors.emerald['800']
);
});
});
// =========================================================
// it('Modal: size', () => {
// const { getByTestId } = render(
//
//
//
// Modal Title
//
// Sit nulla est ex deserunt exercitation anim occaecat. Nostrud
// ullamco deserunt aute id consequat veniam incididunt duis in sint
// irure nisi. Mollit officia cillum Lorem ullamco minim nostrud elit
// officia tempor esse quis. Sunt ad dolore quis aute consequat.
// Magna exercitation reprehenderit magna aute tempor cupidatat
// consequat elit dolor adipisicing. Mollit dolor eiusmod sunt ex
// incididunt cillum quis. Velit duis sit officia eiusmod Lorem
// aliqua enim laboris do dolor eiusmod. Et mollit incididunt nisi
// consectetur esse laborum eiusmod pariatur
//
//
//
//
// );
// const modalElement = getByTestId('size');
// expect(modalElement.props.style.width).toBe('60%');
// });