-
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.
Merge pull request #94 from indec-it/feat/addWrapComponent
feat: add warp component
- Loading branch information
Showing
13 changed files
with
185 additions
and
41 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
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,99 @@ | ||
import React from 'react'; | ||
import {Menu} from '@chakra-ui/react'; | ||
import { | ||
fireEvent, getByTestId, getByText, queryByTestId | ||
} from '@testing-library/react'; | ||
|
||
import UserMenu from './UserMenu'; | ||
|
||
const Component = props => ( | ||
<Menu><UserMenu {...props}/></Menu> | ||
); | ||
|
||
describe('UserMenu', () => { | ||
let props; | ||
const getComponent = newProps => render(Component, newProps); | ||
beforeEach(() => { | ||
props = {}; | ||
}); | ||
afterEach(tearDown); | ||
|
||
it('should not render name and surname if not defined', () => { | ||
const {container} = getComponent(props); | ||
expect(queryByTestId(container, 'attribute-name')).toBeNull(); | ||
}); | ||
|
||
describe('when `user.name` and `user.surname` is defined', () => { | ||
beforeEach(() => { | ||
props.user = {name: 'John', surname: 'Doe'}; | ||
}); | ||
|
||
it('should display `Nombre:`', () => { | ||
const {container} = getComponent(props); | ||
expect(getByText(container, 'Nombre:')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display `user.name`', () => { | ||
const {container} = getComponent(props); | ||
expect(getByText(container, 'John')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display `user.surname`', () => { | ||
const {container} = getComponent(props); | ||
expect(getByText(container, 'Doe')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('when `props.onLogout` is defined', () => { | ||
beforeEach(() => { | ||
props.onLogout = jest.fn(); | ||
}); | ||
|
||
it('should display `Cerrar sesion`', () => { | ||
const {container} = getComponent(props); | ||
expect(getByText(container, 'Cerrar sesión')).toBeInTheDocument(); | ||
}); | ||
|
||
describe('when the button to sign out is clicked', () => { | ||
beforeEach(() => { | ||
const {container} = getComponent(props); | ||
const button = getByTestId(container, 'sign-out'); | ||
fireEvent.click(button); | ||
}); | ||
|
||
it('should fire `props.onLogout`', () => { | ||
expect(props.onLogout).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when `props.onLogout` is not defined', () => { | ||
beforeEach(() => { | ||
props.onLogout = undefined; | ||
}); | ||
|
||
it('should not render a button to sign out', () => { | ||
const {container} = getComponent(props); | ||
expect(queryByTestId(container, 'sign-out')).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('when `props.attributes` is defined', () => { | ||
beforeEach(() => { | ||
props.attributes = [ | ||
{key: 'username', label: 'Username'}, | ||
{key: 'documentId', label: 'DocumentId'}, | ||
{key: 'state', label: 'State'} | ||
]; | ||
props.user = {username: 'test', documentId: '12345678', state: 'Buenos Aires'}; | ||
}); | ||
|
||
it('should render the attributes list', () => { | ||
const {container} = getComponent(props); | ||
props.attributes.forEach(attribute => { | ||
expect(getByText(container, `${attribute.label}:`)).toBeInTheDocument(); | ||
expect(getByText(container, props.user[attribute.key])).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); | ||
}); |
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,22 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {Wrap as ChakraWrap, useStyleConfig} from '@chakra-ui/react'; | ||
|
||
import {childrenPropTypes} from '@/utils/propTypes'; | ||
|
||
const Wrap = ({variant, children, ...rest}) => { | ||
const styles = useStyleConfig('Wrap', {variant}); | ||
return <ChakraWrap data-testid="wrap" {...styles} {...rest}>{children}</ChakraWrap>; | ||
}; | ||
|
||
Wrap.propTypes = { | ||
variant: PropTypes.string, | ||
children: childrenPropTypes | ||
}; | ||
|
||
Wrap.defaultProps = { | ||
variant: undefined, | ||
children: undefined | ||
}; | ||
|
||
export default Wrap; |
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,14 @@ | ||
import {getByTestId} from '@testing-library/react'; | ||
|
||
import {Wrap} from '@/components'; | ||
|
||
describe('<Wrap>', () => { | ||
let props; | ||
const getComponent = () => render(Wrap, props); | ||
afterEach(tearDown); | ||
|
||
it('should render Wrap component', () => { | ||
const {container} = getComponent(); | ||
expect(getByTestId(container, 'wrap')).toBeInTheDocument(); | ||
}); | ||
}); |
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,3 @@ | ||
import Wrap from './Wrap'; | ||
|
||
export default Wrap; |
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,10 @@ | ||
const Wrap = { | ||
baseStyle: { | ||
overflow: 'initial', | ||
align: 'center', | ||
w: '100%', | ||
spacing: 3 | ||
} | ||
}; | ||
|
||
export default Wrap; |
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