1
1
import React from 'react' ;
2
- import ShallowRenderer from 'react-test-renderer/shallow' ;
3
2
import merge from 'lodash/merge' ;
3
+ import { render } from '@testing-library/react' ;
4
4
5
5
import { notificationTypes } from '../../models/notificationTypes' ;
6
6
import { useUserData } from '../../context/UserContext' ;
@@ -10,7 +10,7 @@ import CardText from './CardText';
10
10
const actorsMock = [
11
11
{
12
12
id : '12345' ,
13
- name : 'ATOB ' ,
13
+ name : 'ATO<b>B</b> ' ,
14
14
avatarUrl : 'https://static.wikia.nocookie.net/458a839b-8f84-42c2-b9d1-cf8c5a21bd75' ,
15
15
profileUrl : 'http://localhost:6060/wiki/User:ATOB' ,
16
16
src : 'https://static.wikia.nocookie.net/458a839b-8f84-42c2-b9d1-cf8c5a21bd75' ,
@@ -35,6 +35,11 @@ jest.mock('../../context/UserContext', () => ({
35
35
useUserData : jest . fn ( ) ,
36
36
} ) ) ;
37
37
38
+ jest . mock ( 'react-i18next' , ( ) => ( {
39
+ ...jest . requireActual ( 'react-i18next' ) ,
40
+ useTranslation : ( ) => [ jest . fn ( ( key , params ) => `${ key } ${ params ? JSON . stringify ( params ) : '' } ` ) ] ,
41
+ } ) ) ;
42
+
38
43
const defaultProps = {
39
44
track : ( ) => null ,
40
45
model : {
@@ -45,20 +50,19 @@ const defaultProps = {
45
50
latestEventUri : 'http://xkxd.wikia.com/d/p/3100000000000001096/r/3086787452863005635' ,
46
51
snippet : 'some snippet' ,
47
52
timestamp : 1550663179 ,
48
- title : 'MOAR LIKES' ,
53
+ title : 'MOAR <b> LIKES</b> ' ,
49
54
type : notificationTypes . discussionReply ,
50
55
totalUniqueActors : actorsMock . length ,
51
56
uri : 'http://xkxd.wikia.com/d/p/3100000000000001096' ,
52
57
} ,
53
58
} ;
54
59
55
60
function renderComponent ( props ) {
56
- const renderer = new ShallowRenderer ( ) ;
57
61
const computedProps = merge ( { } , defaultProps , props ) ;
58
62
59
- renderer . render ( < CardText { ...computedProps } /> ) ;
63
+ const { container } = render ( < CardText { ...computedProps } /> ) ;
60
64
61
- return renderer . getRenderOutput ( ) ;
65
+ return container . firstChild ;
62
66
}
63
67
64
68
test ( 'CardText renders correctly with default props' , ( ) => {
@@ -223,7 +227,7 @@ describe('Discussion at mentions', () => {
223
227
type : notificationTypes . postAtMention ,
224
228
latestActors : actorsMock . slice ( 0 , 1 ) ,
225
229
totalUniqueActors : 1 ,
226
- title : 'Post with at mention' ,
230
+ title : 'Post with at <b> mention</b> ' ,
227
231
} ,
228
232
} ) ) . toMatchSnapshot ( ) ;
229
233
} ) ;
@@ -234,7 +238,7 @@ describe('Discussion at mentions', () => {
234
238
type : notificationTypes . threadAtMention ,
235
239
latestActors : actorsMock . slice ( 0 , 1 ) ,
236
240
totalUniqueActors : 1 ,
237
- title : 'Post with at mention' ,
241
+ title : 'Post with at <b> mention</b> ' ,
238
242
} ,
239
243
} ) ) . toMatchSnapshot ( ) ;
240
244
} ) ;
@@ -250,7 +254,7 @@ describe('Article Comments', () => {
250
254
type : notificationTypes . articleCommentReply ,
251
255
latestActors : actorsMock . slice ( 0 , 1 ) ,
252
256
totalUniqueActors : 1 ,
253
- title : 'Article Title' ,
257
+ title : 'Article <b> Title</b> ' ,
254
258
refersToAuthorId : someMockAuthor . id ,
255
259
} ,
256
260
} ) ) . toMatchSnapshot ( ) ;
@@ -265,7 +269,7 @@ describe('Article Comments', () => {
265
269
type : notificationTypes . articleCommentReply ,
266
270
latestActors : actorsMock . slice ( 0 , 1 ) ,
267
271
totalUniqueActors : 1 ,
268
- title : 'Article Title' ,
272
+ title : 'Article <b> Title</b> ' ,
269
273
refersToAuthorId : '11111' ,
270
274
} ,
271
275
} ) ) . toMatchSnapshot ( ) ;
@@ -283,7 +287,7 @@ describe('Article Comments at mentions', () => {
283
287
type : notificationTypes . articleCommentAtMention ,
284
288
latestActors : actorsMock . slice ( 0 , 1 ) ,
285
289
totalUniqueActors : 1 ,
286
- title : 'Article Title' ,
290
+ title : 'Article <b> Title</b> ' ,
287
291
} ,
288
292
} ) ) . toMatchSnapshot ( ) ;
289
293
} ) ;
@@ -294,7 +298,7 @@ describe('Article Comments at mentions', () => {
294
298
type : notificationTypes . articleCommentReplyAtMention ,
295
299
latestActors : actorsMock . slice ( 0 , 1 ) ,
296
300
totalUniqueActors : 1 ,
297
- title : 'Article Title' ,
301
+ title : 'Article <b> Title</b> ' ,
298
302
} ,
299
303
} ) ) . toMatchSnapshot ( ) ;
300
304
} ) ;
@@ -305,7 +309,7 @@ describe('Article Comments at mentions', () => {
305
309
type : notificationTypes . articleCommentReplyAtMention ,
306
310
latestActors : [ { id : 0 , name : null } ] ,
307
311
totalUniqueActors : 1 ,
308
- title : 'Article Title' ,
312
+ title : 'Article <b> Title</b> ' ,
309
313
} ,
310
314
} ) ) . toMatchSnapshot ( ) ;
311
315
} ) ;
0 commit comments