File tree Expand file tree Collapse file tree 4 files changed +48
-12
lines changed
Expand file tree Collapse file tree 4 files changed +48
-12
lines changed Original file line number Diff line number Diff line change 55 */
66
77import React from 'react' ;
8- import { FormattedMessage } from 'react-intl' ;
8+ import { injectIntl } from 'react-intl' ;
9+ import type { IntlShape } from 'react-intl' ;
10+
911import Button from '../../../components/button' ;
1012import IconSort from '../../../icons/general/IconSort' ;
11- import messages from '../messages' ;
1213import Tooltip from '../Tooltip' ;
14+
15+ import messages from '../messages' ;
16+
1317import './SortButton.scss' ;
1418
15- const SortButton = ( props : ?Object ) => (
16- < Tooltip text = { < FormattedMessage { ...messages . sort } /> } >
17- < Button className = "be-btn-sort" type = "button" { ...props } >
18- < IconSort />
19- </ Button >
20- </ Tooltip >
21- ) ;
19+ type Props = {
20+ intl : IntlShape ,
21+ } ;
22+
23+ const SortButton = ( { intl, ...rest } : Props ) => {
24+ const sortMessage = intl . formatMessage ( messages . sort ) ;
25+ return (
26+ < Tooltip text = { sortMessage } >
27+ < Button aria-label = { sortMessage } className = "be-btn-sort" type = "button" { ...rest } >
28+ < IconSort />
29+ </ Button >
30+ </ Tooltip >
31+ ) ;
32+ } ;
2233
23- export default SortButton ;
34+ export { SortButton as SortButtonBase } ;
35+ export default injectIntl ( SortButton ) ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import SortButton from '../SortButton';
77import messages from '../../messages' ;
88import { SORT_ASC , SORT_DESC } from '../../../../constants' ;
99
10- describe ( 'elements/SubHeader /Sort' , ( ) => {
10+ describe ( 'elements/common/sub-header /Sort' , ( ) => {
1111 test ( 'should render a button and menu with 4 menu items' , ( ) => {
1212 const wrapper = shallow ( < Sort onSortChange = { jest . fn ( ) } sortBy = "name" sortDirection = { SORT_ASC } /> ) ;
1313
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import Button from '../../../../components/button' ;
3+ import IconSort from '../../../../icons/general/IconSort' ;
4+ import { SortButtonBase } from '../SortButton' ;
5+
6+ const intlMock = {
7+ formatMessage : jest . fn ( ) . mockReturnValue ( 'Sort' ) ,
8+ } ;
9+
10+ describe ( 'elements/common/sub-header/SortButton' , ( ) => {
11+ const getWrapper = ( ) => shallow ( < SortButtonBase intl = { intlMock } /> ) ;
12+
13+ test ( 'should render IconSort' , ( ) => {
14+ const wrapper = getWrapper ( ) ;
15+ expect ( wrapper . exists ( IconSort ) ) . toBe ( true ) ;
16+ } ) ;
17+
18+ test ( 'should have aria-label "Sort"' , ( ) => {
19+ const wrapper = getWrapper ( ) ;
20+ const button = wrapper . find ( Button ) ;
21+ expect ( button . prop ( 'aria-label' ) ) . toBe ( 'Sort' ) ;
22+ expect ( button . prop ( 'aria-describedby' ) ) . toBeFalsy ( ) ;
23+ } ) ;
24+ } ) ;
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import { VIEW_FOLDER, VIEW_MODE_GRID } from '../../../../constants';
88
99const getWrapper = props => shallow ( < SubHeaderRight { ...props } /> ) ;
1010
11- describe ( 'Elements/SubHeader /SubHeaderRight' , ( ) => {
11+ describe ( 'elements/common/sub-header /SubHeaderRight' , ( ) => {
1212 const currentCollection = {
1313 sortBy : '' ,
1414 sortDirection : '' ,
You can’t perform that action at this time.
0 commit comments