File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed
components/ChannelPreview/__tests__ Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+
3+ import { render } from '@testing-library/react-native' ;
4+
5+ import { generateGiphyAttachment } from '../../../mock-builders/generator/attachment' ;
6+ import { generateMessage } from '../../../mock-builders/generator/message' ;
7+ import { generateUser } from '../../../mock-builders/generator/user' ;
8+ import { getTestClientWithUser } from '../../../mock-builders/mock' ;
9+ import { Chat } from '../../Chat/Chat' ;
10+ import { ChannelLastMessagePreview } from '../ChannelLastMessagePreview' ;
11+
12+ describe ( 'ChannelLastMessagePreview' , ( ) => {
13+ it ( 'shows Giphy instead of slash-command text for giphy attachments with quoted replies' , async ( ) => {
14+ const client = await getTestClientWithUser ( { id : 'preview-user' } ) ;
15+ const user = generateUser ( ) ;
16+ const message = generateMessage ( {
17+ attachments : [ generateGiphyAttachment ( ) ] ,
18+ quoted_message : generateMessage ( { text : 'quoted message' , user } ) ,
19+ text : '/giphy Cat' ,
20+ user,
21+ } ) ;
22+
23+ const { getByText, queryByText } = render (
24+ < Chat client = { client } >
25+ < ChannelLastMessagePreview message = { message } />
26+ </ Chat > ,
27+ ) ;
28+
29+ expect ( getByText ( 'Giphy' ) ) . toBeTruthy ( ) ;
30+ expect ( queryByText ( '/giphy Cat' ) ) . toBeNull ( ) ;
31+ } ) ;
32+ } ) ;
Original file line number Diff line number Diff line change @@ -35,7 +35,6 @@ export const useMessagePreviewText = ({
3535 const onlyAudio = audios ?. length === attachmentsLength ;
3636 const onlyVoiceRecordings =
3737 voiceRecordings ?. length && voiceRecordings ?. length === attachmentsLength ;
38-
3938 if ( message ?. type === 'deleted' ) {
4039 return 'Message deleted' ;
4140 }
@@ -55,8 +54,12 @@ export const useMessagePreviewText = ({
5554 return 'Location' ;
5655 }
5756
57+ if ( giphys ?. length ) {
58+ return 'Giphy' ;
59+ }
60+
5861 if ( message ?. text ) {
59- return message ? .text ;
62+ return message . text ;
6063 }
6164
6265 if ( onlyImages ) {
@@ -91,10 +94,6 @@ export const useMessagePreviewText = ({
9194 }
9295 }
9396
94- if ( giphys ?. length ) {
95- return 'Giphy' ;
96- }
97-
9897 if ( onlyFiles && files ?. length === 1 ) {
9998 return files ?. [ 0 ] ?. title ;
10099 }
You can’t perform that action at this time.
0 commit comments