@@ -2,17 +2,19 @@ import React from 'react';
22import { cleanup , fireEvent , render } from '@testing-library/react' ;
33import '@testing-library/jest-dom' ;
44import { MessageRepliesCountButton } from '../MessageRepliesCountButton' ;
5- import { TranslationContext } from '../../../context' ;
5+ import { TranslationProvider } from '../../../context' ;
66
77const onClickMock = jest . fn ( ) ;
8+ const defaultSingularText = '1 reply' ;
9+ const defaultPluralText = '2 replies' ;
810
9- const i18nMock = ( key ) => key ;
11+ const i18nMock = ( key , { count } ) => ( count > 1 ? defaultPluralText : defaultSingularText ) ;
1012
1113const renderComponent = ( props ) =>
1214 render (
13- < TranslationContext . Provider value = { { t : i18nMock } } >
15+ < TranslationProvider value = { { t : i18nMock } } >
1416 < MessageRepliesCountButton { ...props } onClick = { onClickMock } />
15- </ TranslationContext . Provider > ,
17+ </ TranslationProvider > ,
1618 ) ;
1719
1820describe ( 'MessageRepliesCountButton' , ( ) => {
@@ -24,27 +26,27 @@ describe('MessageRepliesCountButton', () => {
2426 it ( 'should render the right text when there is one reply, and labelSingle is not defined' , ( ) => {
2527 const { getByText } = renderComponent ( { reply_count : 1 } ) ;
2628
27- expect ( getByText ( '1 reply' ) ) . toBeInTheDocument ( ) ;
29+ expect ( getByText ( defaultSingularText ) ) . toBeInTheDocument ( ) ;
2830 } ) ;
2931
3032 it ( 'should render the right text when there is one reply, and labelSingle is defined' , ( ) => {
31- const labelSingle = 'text' ;
32- const { getByText } = renderComponent ( { labelSingle, reply_count : 1 } ) ;
33+ const customSingularLabel = 'text' ;
34+ const { getByText } = renderComponent ( { labelSingle : customSingularLabel , reply_count : 1 } ) ;
3335
34- expect ( getByText ( `1 ${ labelSingle } ` ) ) . toBeInTheDocument ( ) ;
36+ expect ( getByText ( `1 ${ customSingularLabel } ` ) ) . toBeInTheDocument ( ) ;
3537 } ) ;
3638
3739 it ( 'should render the right text when there is more than one reply, and labelPlural is not defined' , ( ) => {
3840 const { getByText } = renderComponent ( { reply_count : 2 } ) ;
3941
40- expect ( getByText ( '{{ replyCount }} replies' ) ) . toBeInTheDocument ( ) ;
42+ expect ( getByText ( defaultPluralText ) ) . toBeInTheDocument ( ) ;
4143 } ) ;
4244
4345 it ( 'should render the right text when there is more than one reply, and labelPlural is defined' , ( ) => {
44- const labelPlural = 'text' ;
45- const { getByText } = renderComponent ( { labelPlural, reply_count : 2 } ) ;
46+ const customPluralLabel = 'text' ;
47+ const { getByText } = renderComponent ( { labelPlural : customPluralLabel , reply_count : 2 } ) ;
4648
47- expect ( getByText ( `2 ${ labelPlural } ` ) ) . toBeInTheDocument ( ) ;
49+ expect ( getByText ( `2 ${ customPluralLabel } ` ) ) . toBeInTheDocument ( ) ;
4850 } ) ;
4951
5052 it ( 'should call the onClick prop if the button is clicked' , ( ) => {
0 commit comments