-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(standalone-icon): Add interactivity to icon
- Loading branch information
Showing
5 changed files
with
119 additions
and
25 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
6 changes: 6 additions & 0 deletions
6
src/components/Icons/StandaloneIcon/StandaloneIcon.modules.scss
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,6 @@ | ||
.interactive { | ||
appearance: none; | ||
background: none; | ||
border: 0; | ||
cursor: pointer; | ||
} |
92 changes: 71 additions & 21 deletions
92
src/components/Icons/StandaloneIcon/__tests__/StandaloneIcon.spec.jsx
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,34 +1,84 @@ | ||
import React from 'react' | ||
import { shallow, render } from 'enzyme' | ||
import {shallow, render} from 'enzyme' | ||
import toJson from 'enzyme-to-json' | ||
|
||
import StandaloneIcon from '../StandaloneIcon' | ||
|
||
describe('StandaloneIcon', () => { | ||
const defaultProps = { | ||
symbol: 'spyglass', | ||
a11yText: 'Some text for the screen readers.' | ||
} | ||
const doShallow = (props = {}) => shallow(<StandaloneIcon {...defaultProps} {...props} />) | ||
|
||
it('renders', () => { | ||
const icon = render(<StandaloneIcon symbol="spyglass" a11yText="Some screen reader text." />) | ||
expect(toJson(icon)).toMatchSnapshot() | ||
}) | ||
describe('Plain StandaloneIcon', () => { | ||
const defaultProps = { | ||
symbol: 'spyglass', | ||
a11yText: 'Some text for the screen readers.', | ||
} | ||
const doShallow = (props = {}) => shallow(<StandaloneIcon {...defaultProps} {...props} />) | ||
|
||
it('renders', () => { | ||
const icon = render(<StandaloneIcon symbol="spyglass" a11yText="Some screen reader text." />) | ||
expect(toJson(icon)).toMatchSnapshot() | ||
}) | ||
|
||
it('passes attributes to the Icon component', () => { | ||
const icon = doShallow({symbol: 'checkmark', variant: 'secondary', size: 16, id: 'the-icon'}) | ||
|
||
it('passes attributes to the Icon component', () => { | ||
const icon = doShallow({ symbol: 'checkmark', variant: 'secondary', size: 16, id: 'the-icon' }) | ||
expect(icon).toHaveProp('symbol', 'checkmark') | ||
expect(icon).toHaveProp('variant', 'secondary') | ||
expect(icon).toHaveProp('size', 16) | ||
expect(icon).toHaveProp('id', 'the-icon') | ||
}) | ||
|
||
expect(icon).toHaveProp('symbol', 'checkmark') | ||
expect(icon).toHaveProp('variant', 'secondary') | ||
expect(icon).toHaveProp('size', 16) | ||
expect(icon).toHaveProp('id', 'the-icon') | ||
it('is accessible for screen readers', () => { | ||
const icon = doShallow({a11yText: 'Some screen reader text'}) | ||
|
||
expect(icon).not.toHaveProp('aria-hidden') | ||
expect(icon).toHaveProp('aria-label', 'Some screen reader text') | ||
}) | ||
}) | ||
|
||
it('is accessible for screen readers', () => { | ||
const icon = doShallow({ a11yText: 'Some screen reader text' }) | ||
describe('Interactive StandaloneIcon', () => { | ||
const onClickMock = jest.fn() | ||
|
||
const defaultProps = { | ||
symbol: 'spyglass', | ||
a11yText: 'Some text for the screen readers.', | ||
interactive: true, | ||
onClick: onClickMock, | ||
} | ||
const doShallow = (props = {}) => shallow(<StandaloneIcon {...defaultProps} {...props} />) | ||
|
||
it('renders an HTML button tag', () => { | ||
const interactiveIcon = doShallow({interactive: true, onClick: onClickMock}) | ||
|
||
expect(icon).not.toHaveProp('aria-hidden') | ||
expect(icon).toHaveProp('aria-label', 'Some screen reader text') | ||
expect(interactiveIcon).toHaveTagName('button') | ||
}) | ||
|
||
it('the aria-label attribute is applied to the button tag', () => {}) | ||
|
||
it('passes additional attributes to the button element', () => { | ||
const interactiveIcon = doShallow({ | ||
id: 'the-interactiveIcon', | ||
role: 'button', | ||
}) | ||
|
||
expect(interactiveIcon).toHaveProp('id', 'the-interactiveIcon') | ||
expect(interactiveIcon).toHaveProp('role', 'button') | ||
}) | ||
|
||
it('does not allow custom CSS', () => { | ||
const interactiveIcon = doShallow({ | ||
className: 'my-custom-class', | ||
style: {color: 'hotpink'}, | ||
}) | ||
|
||
expect(interactiveIcon).not.toHaveProp('className', 'my-custom-class') | ||
expect(interactiveIcon).not.toHaveProp('style') | ||
}) | ||
}) | ||
}) | ||
|
||
// Interactive | ||
// <button onClick="" aria-label="Search this site" id="button-id"> | ||
// <StandaloneIcon symbol="spyglass" size={48}/> | ||
// </button> | ||
// | ||
// Non-Interactive | ||
// <StandaloneIcon symbol="spyglass" size={48} a11yText="Search this site" data-blah="hi" /> |
2 changes: 1 addition & 1 deletion
2
src/components/Icons/StandaloneIcon/__tests__/__snapshots__/StandaloneIcon.spec.jsx.snap
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