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