From b6336734b634583991efa85aa5f6a1e99f2cc490 Mon Sep 17 00:00:00 2001 From: Damian Morales Date: Tue, 16 Apr 2024 14:12:24 -0300 Subject: [PATCH] crear componente button - falta storybooks --- App.tsx | 1 + src/components/BaseButton/index.test.tsx | 2 +- src/components/Button/constants/index.ts | 8 +- src/components/Button/index.test.tsx | 81 ++++++++++++++++- src/components/Button/index.tsx | 9 +- src/components/Button/types/index.ts | 1 + src/components/Button/utils/index.test.ts | 88 +++++++++++++++++++ src/components/Button/utils/index.ts | 82 ++++++++++++----- .../Select/Components/Modal/index.tsx | 11 +-- 9 files changed, 246 insertions(+), 37 deletions(-) create mode 100644 src/components/Button/utils/index.test.ts diff --git a/App.tsx b/App.tsx index 74d3298..ce48de1 100644 --- a/App.tsx +++ b/App.tsx @@ -25,6 +25,7 @@ const App = () => ( iconPosition={IconPosition.Left} disabled={false} style={{marginLeft: 6}} + iconStyle={{color: 'red', fontSize: 30}} /> ); diff --git a/src/components/BaseButton/index.test.tsx b/src/components/BaseButton/index.test.tsx index eea8c3b..f6b6e15 100644 --- a/src/components/BaseButton/index.test.tsx +++ b/src/components/BaseButton/index.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import {create} from 'react-test-renderer'; -import {View, Text, Pressable} from 'react-native'; +import {View, Text} from 'react-native'; import BaseButton from './'; const validData = { diff --git a/src/components/Button/constants/index.ts b/src/components/Button/constants/index.ts index 3749844..b6148dd 100644 --- a/src/components/Button/constants/index.ts +++ b/src/components/Button/constants/index.ts @@ -1,4 +1,7 @@ const verticalHeights = ['top', 'bottom']; +const validTypes= ['main', 'secondary'] +const validVariants = ['contained', 'outlined', 'text']; +const validIconPositions = ['top', 'bottom', 'left', 'right']; const defaultColor = 'primary'; const defaultType = 'main'; const defaultVariant = 'contained'; @@ -6,8 +9,11 @@ const defaultIconPosition = 'left'; export { verticalHeights, + validTypes, + validVariants, + validIconPositions, defaultColor, defaultType, defaultVariant, - defaultIconPosition + defaultIconPosition, } \ No newline at end of file diff --git a/src/components/Button/index.test.tsx b/src/components/Button/index.test.tsx index 5568dfe..67ad043 100644 --- a/src/components/Button/index.test.tsx +++ b/src/components/Button/index.test.tsx @@ -1,3 +1,80 @@ -describe('Button', () => { - /* global expect */ +import React from 'react'; +import {create} from 'react-test-renderer'; +import {Text} from 'react-native'; +import Icon from '../Icon'; +import BaseButton from '../BaseButton'; +import Loading from '../Loading'; +import Button, { Color, IconPosition, Type, Variant } from './'; + +const validData = { + type: Type.Main, + variant: Variant.Contained, + color: Color.Primary, + isLoading: true, + value: 'Button Test', + icon: 'box', + iconPosition: IconPosition.Left, +}; + +const setIsPressed = jest.fn(); +const spyUseState = jest.spyOn(React, 'useState'); +jest.spyOn(React, 'useEffect').mockImplementation((f) => f()); +jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper'); + +describe('Button component', () => { + describe('returns null', () => { + it('when value and icon props are not passed to the Button component', () => { + const {toJSON} = create(