-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e692f0
commit ec62d04
Showing
5 changed files
with
163 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { action } from '@storybook/addon-actions' | ||
import React from 'react' | ||
import { IconButton, IconButtonProps, IconSizes } from './index' | ||
import { Meta, Story } from '@storybook/react/types-6-0' | ||
|
||
export default { | ||
argTypes: { | ||
icon: { control: { disable: true } }, | ||
onClick: { defaultValue: action('onClick') }, | ||
size: { | ||
control: { | ||
options: [IconSizes.xs, IconSizes.sm, IconSizes.lg], | ||
type: 'select' | ||
} | ||
} | ||
}, | ||
component: IconButton, | ||
title: 'IconButton' | ||
} as Meta | ||
|
||
const Template: Story<IconButtonProps> = args => <IconButton {...args} /> | ||
|
||
export const Default = Template.bind({}) |
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,53 @@ | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
import React from 'react' | ||
import { IconButton, IconSizes } from './index' | ||
import { mount, ReactWrapper } from 'enzyme' | ||
|
||
let wrapper: ReactWrapper | ||
let mockOnClick: jest.Mock<void> | ||
|
||
beforeEach(() => { | ||
mockOnClick = jest.fn() | ||
wrapper = mount(<IconButton />) | ||
}) | ||
|
||
afterEach(() => { | ||
wrapper.unmount() | ||
}) | ||
|
||
describe('IconButton', () => { | ||
it('renders', () => { | ||
const iconBtn = wrapper.find(IconButton) | ||
|
||
expect(iconBtn).toHaveLength(1) | ||
}) | ||
|
||
it('passes onClick props to FontAwesomeIcon if one is provided', () => { | ||
wrapper = mount(<IconButton onClick={mockOnClick} />) | ||
|
||
expect(wrapper.find(FontAwesomeIcon).props().onClick).toBeTruthy() | ||
}) | ||
|
||
it('runs onClick function when IconButton is clicked', () => { | ||
wrapper = mount(<IconButton onClick={mockOnClick} />) | ||
|
||
const fontAwesomeIcon = wrapper.find(FontAwesomeIcon) | ||
|
||
fontAwesomeIcon.simulate('click') | ||
expect(mockOnClick).toHaveBeenCalledTimes(1) | ||
}) | ||
|
||
it('inherits fontSize if size prop is not provided', () => { | ||
const styles = window.getComputedStyle(wrapper.find('svg').getDOMNode()) | ||
|
||
expect(styles.fontSize).toBe('inherit') | ||
}) | ||
|
||
it('renders IconButton with fontSize equal to size if size prop is provided', () => { | ||
wrapper = mount(<IconButton size={IconSizes.xs} />) | ||
|
||
const styles = window.getComputedStyle(wrapper.find('svg').getDOMNode()) | ||
|
||
expect(styles.fontSize).toBe(`${IconSizes.xs}px`) | ||
}) | ||
}) |
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.