-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crear componente button - falta storybooks
- Loading branch information
Damian Morales
committed
Apr 16, 2024
1 parent
4d9f083
commit b633673
Showing
9 changed files
with
246 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
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'; | ||
const defaultIconPosition = 'left'; | ||
|
||
export { | ||
verticalHeights, | ||
validTypes, | ||
validVariants, | ||
validIconPositions, | ||
defaultColor, | ||
defaultType, | ||
defaultVariant, | ||
defaultIconPosition | ||
defaultIconPosition, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(<Button />); | ||
expect(toJSON()).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('it renders correctly', () => { | ||
it('when it has valie as minimum prop', () => { | ||
const {root} = create(<Button value={validData.value} />); | ||
const TitleComp = root.findByType(Text); | ||
const {children} = TitleComp.props; | ||
|
||
expect(children).toEqual(validData.value); | ||
}); | ||
|
||
|
||
it('when it has icon as minimum prop', () => { | ||
const {root} = create(<Button icon={validData.icon} />); | ||
const IconComp = root.findByType(Icon); | ||
const {name} = IconComp.props; | ||
|
||
expect(name).toEqual(validData.icon); | ||
}); | ||
|
||
it('when it is pressed', () => { | ||
spyUseState.mockReturnValueOnce([false, setIsPressed]); | ||
|
||
const {root} = create( | ||
<Button | ||
type={Type.Main} | ||
variant={Variant.Contained} | ||
color={Color.Primary} | ||
value="Button Test" | ||
icon="box" | ||
iconPosition={IconPosition.Left} | ||
/>); | ||
|
||
const ButtonComp = root.findByType(BaseButton) | ||
const {onPressIn, onPressOut} = ButtonComp.props; | ||
|
||
onPressIn(); | ||
onPressOut(); | ||
|
||
expect(setIsPressed).toBeCalledTimes(2); | ||
}); | ||
|
||
it('when isLoading is true, show an loading spinner', () => { | ||
const {root} = create(<Button icon={validData.icon} isLoading={validData.isLoading} />); | ||
const LoadingComp = root.findByType(Loading) | ||
const {isLoading} = LoadingComp.props; | ||
|
||
expect(isLoading).toEqual(validData.isLoading); | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { getMixedButtonStyles } from "."; | ||
import { Color, IconPosition, Type, Variant } from ".."; | ||
|
||
const props = { | ||
type: Type.Secondary, | ||
variant: Variant.Outlined, | ||
color: Color.Secondary, | ||
iconPosition: IconPosition.Top, | ||
isLoading: true, | ||
isPressed: true, | ||
disabled: true, | ||
hasIconAndText: true, | ||
} | ||
|
||
const failedProps = { | ||
type: undefined, | ||
variant: undefined, | ||
color: undefined, | ||
iconPosition: undefined, | ||
isLoading: false, | ||
isPressed: false, | ||
disabled: false, | ||
hasIconAndText: false, | ||
} | ||
|
||
describe('getMixedButtonStyles util', () => { | ||
it('return styles when params are passed correclty', () => { | ||
const response = getMixedButtonStyles(props); | ||
expect(response).toEqual( | ||
{ | ||
container: { | ||
borderWidth: 1, | ||
borderColor: '#C4C6CC', | ||
backgroundColor: '#DDDFE2', | ||
paddingHorizontal: 16.5, | ||
paddingVertical: 21, | ||
shadowColor: '#000', | ||
elevation: 5, | ||
shadowOpacity: 0.25, | ||
shadowRadius: 3.84, | ||
shadowOffset: { width: 0, height: 6.5 } | ||
}, | ||
direction: { | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
flexDirection: 'column' | ||
}, | ||
text: { | ||
fontWeight: '500', | ||
textAlign: 'center', | ||
color: '#C4C6CC', | ||
fontSize: 29 | ||
}, | ||
icon: { fontWeight: '500', textAlign: 'center', color: '#C4C6CC' }, | ||
loadingColor: '#2F2F2F' | ||
} | ||
) | ||
}); | ||
|
||
it('returns default styles when params is not correct or no exist', () => { | ||
// @ts-ignore | ||
const response = getMixedButtonStyles(failedProps); | ||
expect(response).toEqual( | ||
{ | ||
container: { | ||
borderWidth: 1, | ||
borderColor: 'transparent', | ||
backgroundColor: '#2979FF', | ||
paddingHorizontal: 16.5, | ||
height: 104 | ||
}, | ||
direction: { | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
flexDirection: 'row' | ||
}, | ||
text: { | ||
fontWeight: '500', | ||
textAlign: 'center', | ||
color: '#fff', | ||
fontSize: 29 | ||
}, | ||
icon: { fontWeight: '500', textAlign: 'center', color: '#fff' }, | ||
loadingColor: '#2979FF' | ||
} | ||
) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.