diff options
author | Anike Arni <aarni@thoughtworks.com> | 2017-03-29 17:10:19 -0300 |
---|---|---|
committer | Anike Arni <aarni@thoughtworks.com> | 2017-03-30 15:10:57 -0300 |
commit | 9a2a9cf5f4d13e2bc9bb0bd997ecd22ec5241b4b (patch) | |
tree | 70e5175f723e9940eeb83373c1a41a9fc01e4fd9 /web-ui/src/common/back_link | |
parent | 26cb72e514a51d571e13dfd74e99f6b2499efe22 (diff) |
[#932] Makes back link a button
Diffstat (limited to 'web-ui/src/common/back_link')
-rw-r--r-- | web-ui/src/common/back_link/back_link.js | 15 | ||||
-rw-r--r-- | web-ui/src/common/back_link/back_link.scss | 4 | ||||
-rw-r--r-- | web-ui/src/common/back_link/back_link.spec.js | 37 |
3 files changed, 44 insertions, 12 deletions
diff --git a/web-ui/src/common/back_link/back_link.js b/web-ui/src/common/back_link/back_link.js index f3bdb2b5..bb5ffbea 100644 --- a/web-ui/src/common/back_link/back_link.js +++ b/web-ui/src/common/back_link/back_link.js @@ -19,12 +19,19 @@ import React from 'react'; import './back_link.scss'; +const icon = <i className='fa fa-angle-left' aria-hidden='true' />; + +const button = (text, options) => ( + <button className='link' {...options}>{icon}<span>{text}</span></button> +); + +const link = (text, options) => ( + <a className='link' {...options}>{icon}<span>{text}</span></a> +); + const BackLink = ({ text, ...other }) => ( <div className='link-content'> - <a className='link' tabIndex='0' {...other}> - <i className='fa fa-angle-left' aria-hidden='true' /> - <span>{text}</span> - </a> + { other.href ? link(text, other) : button(text, other) } </div> ); diff --git a/web-ui/src/common/back_link/back_link.scss b/web-ui/src/common/back_link/back_link.scss index a799a710..5541d9d9 100644 --- a/web-ui/src/common/back_link/back_link.scss +++ b/web-ui/src/common/back_link/back_link.scss @@ -21,6 +21,10 @@ color: $dark_blue; font-style: italic; font-size: 0.8em; + margin: 0; + padding: 0; + border: 0; + background: transparent; .fa { font-size: 1.6em; diff --git a/web-ui/src/common/back_link/back_link.spec.js b/web-ui/src/common/back_link/back_link.spec.js index ee659267..5f49a6f9 100644 --- a/web-ui/src/common/back_link/back_link.spec.js +++ b/web-ui/src/common/back_link/back_link.spec.js @@ -4,17 +4,38 @@ import React from 'react'; import BackLink from 'src/common/back_link/back_link'; describe('BackLink', () => { - let backLink; + context('as link', () => { + let backLink; - beforeEach(() => { - backLink = shallow(<BackLink text='Back to inbox' href='/' />); - }); + beforeEach(() => { + backLink = shallow(<BackLink text='Back to inbox' href='/' />); + }); + + it('renders link with text', () => { + expect(backLink.find('a').text()).toEqual('Back to inbox'); + }); - it('renders link with text', () => { - expect(backLink.find('a').text()).toEqual('Back to inbox'); + it('adds link action', () => { + expect(backLink.find('a').props().href).toEqual('/'); + }); }); - it('adds link action', () => { - expect(backLink.find('a').props().href).toEqual('/'); + context('as button', () => { + let backLink; + let mockClick; + + beforeEach(() => { + mockClick = expect.createSpy(); + backLink = shallow(<BackLink text='Back to inbox' onClick={mockClick} />); + }); + + it('renders button with text', () => { + expect(backLink.find('button').text()).toEqual('Back to inbox'); + }); + + it('adds button click event', () => { + backLink.find('button').simulate('click'); + expect(mockClick).toHaveBeenCalled(); + }); }); }); |