Skip to content

Commit

Permalink
fix(button): set type as 'button' by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ej9x committed Mar 12, 2019
1 parent feb4b7a commit 0be3328
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Button extends Component<ButtonProps> {
variant: 'raised',
color: 'primary',
size: 'md',
type: 'button',
};

onClick = (event: *) => {
Expand All @@ -54,7 +55,7 @@ class Button extends Component<ButtonProps> {
type={ type }
loading={ loading }
onClick={ this.onClick }
aria-busy={ String(loading) }
aria-busy={ Boolean(loading).toString() }
>
{ React.Children.map(children, (child) => typeof child === 'string' ? <span>{ child }</span> : child) }
</ButtonTag>
Expand Down
40 changes: 30 additions & 10 deletions src/components/Button/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,36 @@ describe('<Button />', () => {
it('should render button with text', () => {
const wrapper = mount(
<EightBaseBoostProvider>
<Button squared variant="outlined">some-text</Button>
</EightBaseBoostProvider>);
<Button squared variant="outlined">
some-text
</Button>
</EightBaseBoostProvider>,
);

expect(wrapper.find('button').text()).toBe('some-text');
});

it('should render button with default props', () => {
const wrapper = shallow(<Button>some-text</Button>);

expect(wrapper).toMatchInlineSnapshot(`
<Boost(button)
aria-busy="false"
color="primary"
onClick={[Function]}
size="md"
tagName="button"
type="button"
variant="raised"
>
<span
key=".0"
>
some-text
</span>
</Boost(button)>
`);
});

it('should call onClick callback', () => {
const onClick = jest.fn();
Expand All @@ -21,7 +45,6 @@ describe('<Button />', () => {
expect(onClick).toHaveBeenCalled();
});


it('should pass children to the button body', () => {
const wrapper = mount(
<Button>
Expand All @@ -36,26 +59,21 @@ describe('<Button />', () => {
expect(wrapper.text()).toBe('some-text');
});


it('should pass custom tag to the button', () => {
const wrapper = mount(
<Button tagName="a" href="https://break-core.ch" />,
);
const wrapper = mount(<Button tagName="a" href="https://break-core.ch" />);

expect(wrapper.find('a')).toHaveLength(1);
expect(wrapper.find('a').props().href).toBe('https://break-core.ch');
});


it('shouldn\'c call onClick callback on disabled button', () => {
it('shouldn\'t call onClick callback on disabled button', () => {
const onClick = jest.fn();
const wrapper = shallow(<Button disabled onClick={ onClick } />);

wrapper.simulate('click');
expect(onClick).not.toHaveBeenCalled();
});


it('should not click on button while it loading', () => {
const onClick = jest.fn();
const wrapper = mount(
Expand All @@ -66,5 +84,7 @@ describe('<Button />', () => {

wrapper.simulate('click');
expect(onClick).not.toHaveBeenCalled();
expect(wrapper.find('button').prop('aria-busy')).toBe('true');
});
});

2 changes: 1 addition & 1 deletion src/components/Navigation/NavigationItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type NavigationItemProps = {
const NavigationItem = ({ icon, label, ...rest }: NavigationItemProps) => (
<NavigationItemTag { ...rest }>
<NavigationItemIcon modifiers={ rest }>
<If condition={ icon === undefined && typeof label === 'string' }>
<If condition={ icon === undefined && typeof label === 'string' && label.length > 0 }>
<NavigationItemLabelPreview>{ label && label.charAt(0).toUpperCase() }</NavigationItemLabelPreview>
</If>
<If condition={ typeof icon === 'string' }>
Expand Down

0 comments on commit 0be3328

Please sign in to comment.