react-native-gifted-chat 2.8.2-alpha.6 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -269
- package/package.json +2 -1
- package/src/Actions.tsx +1 -1
- package/src/Avatar.tsx +12 -12
- package/src/Bubble/index.tsx +14 -16
- package/src/Bubble/styles.ts +1 -1
- package/src/Bubble/types.ts +26 -27
- package/src/Color.ts +1 -1
- package/src/Composer.tsx +1 -4
- package/src/Day/styles.ts +1 -1
- package/src/GiftedAvatar.tsx +2 -2
- package/src/GiftedChat/index.tsx +26 -61
- package/src/GiftedChat/types.ts +40 -49
- package/src/InputToolbar.tsx +28 -19
- package/src/LoadEarlierMessages.tsx +1 -1
- package/src/Message/index.tsx +11 -14
- package/src/Message/types.ts +8 -12
- package/src/MessageAudio.tsx +1 -1
- package/src/MessageContainer/components/DayAnimated/index.tsx +1 -3
- package/src/MessageContainer/components/DayAnimated/types.ts +1 -1
- package/src/MessageContainer/components/Item/index.tsx +9 -11
- package/src/MessageContainer/components/Item/types.ts +1 -1
- package/src/MessageContainer/index.tsx +32 -36
- package/src/MessageContainer/styles.ts +1 -1
- package/src/MessageContainer/types.ts +12 -16
- package/src/MessageImage.tsx +1 -1
- package/src/MessageText.tsx +1 -1
- package/src/MessageVideo.tsx +1 -1
- package/src/Models.ts +63 -0
- package/src/QuickReplies.tsx +2 -2
- package/src/Send.tsx +31 -32
- package/src/SystemMessage.tsx +2 -2
- package/src/Time.tsx +6 -6
- package/src/TypingIndicator/index.tsx +1 -3
- package/src/TypingIndicator/styles.ts +1 -1
- package/src/__tests__/Actions.test.tsx +1 -1
- package/src/__tests__/Avatar.test.tsx +7 -2
- package/src/__tests__/Bubble.test.tsx +3 -7
- package/src/__tests__/Color.test.tsx +1 -1
- package/src/__tests__/Composer.test.tsx +1 -1
- package/src/__tests__/Day.test.tsx +3 -3
- package/src/__tests__/DayAnimated.test.tsx +5 -11
- package/src/__tests__/GiftedAvatar.test.tsx +1 -1
- package/src/__tests__/GiftedChat.test.tsx +1 -1
- package/src/__tests__/InputToolbar.test.tsx +1 -1
- package/src/__tests__/LoadEarlier.test.tsx +2 -2
- package/src/__tests__/Message.test.tsx +7 -13
- package/src/__tests__/MessageContainer.test.tsx +4 -4
- package/src/__tests__/MessageImage.test.tsx +2 -2
- package/src/__tests__/MessageText.test.tsx +3 -2
- package/src/__tests__/Send.test.tsx +2 -2
- package/src/__tests__/SystemMessage.test.tsx +1 -1
- package/src/__tests__/Time.test.tsx +1 -1
- package/src/__tests__/__snapshots__/Actions.test.tsx.snap +2 -86
- package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +1 -1
- package/src/__tests__/__snapshots__/Day.test.tsx.snap +96 -2
- package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +1 -1
- package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +3 -89
- package/src/__tests__/__snapshots__/Message.test.tsx.snap +43 -4
- package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +1 -1
- package/src/__tests__/__snapshots__/Send.test.tsx.snap +10 -142
- package/src/__tests__/data.ts +2 -2
- package/src/components/TouchableOpacity.tsx +19 -8
- package/src/index.ts +19 -1
- package/src/types.ts +1 -63
- package/src/utils.ts +23 -2
package/src/Models.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { StyleProp, ViewStyle } from 'react-native'
|
|
2
|
+
|
|
3
|
+
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
|
|
4
|
+
|
|
5
|
+
export interface LeftRightStyle<T> {
|
|
6
|
+
left?: StyleProp<T>
|
|
7
|
+
right?: StyleProp<T>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
type renderFunction = (x: unknown) => React.ReactNode
|
|
11
|
+
|
|
12
|
+
export interface User {
|
|
13
|
+
_id: string | number
|
|
14
|
+
name?: string
|
|
15
|
+
avatar?: string | number | renderFunction
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Reply {
|
|
19
|
+
title: string
|
|
20
|
+
value: string
|
|
21
|
+
messageId?: number | string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface QuickReplies {
|
|
25
|
+
type: 'radio' | 'checkbox'
|
|
26
|
+
values: Reply[]
|
|
27
|
+
keepIt?: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface IMessage {
|
|
31
|
+
_id: string | number
|
|
32
|
+
text: string
|
|
33
|
+
createdAt: Date | number
|
|
34
|
+
user: User
|
|
35
|
+
image?: string
|
|
36
|
+
video?: string
|
|
37
|
+
audio?: string
|
|
38
|
+
system?: boolean
|
|
39
|
+
sent?: boolean
|
|
40
|
+
received?: boolean
|
|
41
|
+
pending?: boolean
|
|
42
|
+
quickReplies?: QuickReplies
|
|
43
|
+
location?: {
|
|
44
|
+
latitude: number
|
|
45
|
+
longitude: number
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type IChatMessage = IMessage
|
|
50
|
+
|
|
51
|
+
export interface MessageVideoProps<TMessage extends IMessage> {
|
|
52
|
+
currentMessage: TMessage
|
|
53
|
+
containerStyle?: StyleProp<ViewStyle>
|
|
54
|
+
videoStyle?: StyleProp<ViewStyle>
|
|
55
|
+
videoProps?: object
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface MessageAudioProps<TMessage extends IMessage> {
|
|
59
|
+
currentMessage: TMessage
|
|
60
|
+
containerStyle?: StyleProp<ViewStyle>
|
|
61
|
+
audioStyle?: StyleProp<ViewStyle>
|
|
62
|
+
audioProps?: object
|
|
63
|
+
}
|
package/src/QuickReplies.tsx
CHANGED
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
ViewStyle,
|
|
8
8
|
TextStyle,
|
|
9
9
|
} from 'react-native'
|
|
10
|
-
import Color from './Color'
|
|
10
|
+
import { Color } from './Color'
|
|
11
11
|
import { TouchableOpacity } from './components/TouchableOpacity'
|
|
12
12
|
import { warning } from './logging'
|
|
13
|
+
import { IMessage, Reply } from './Models'
|
|
13
14
|
import stylesCommon from './styles'
|
|
14
|
-
import { IMessage, Reply } from './types'
|
|
15
15
|
|
|
16
16
|
const styles = StyleSheet.create({
|
|
17
17
|
container: {
|
package/src/Send.tsx
CHANGED
|
@@ -8,30 +8,11 @@ import {
|
|
|
8
8
|
TextStyle,
|
|
9
9
|
useColorScheme,
|
|
10
10
|
} from 'react-native'
|
|
11
|
-
import Color from './Color'
|
|
11
|
+
import { Color } from './Color'
|
|
12
12
|
|
|
13
13
|
import { TouchableOpacity, TouchableOpacityProps } from './components/TouchableOpacity'
|
|
14
14
|
import { TEST_ID } from './Constant'
|
|
15
|
-
import { IMessage } from './
|
|
16
|
-
|
|
17
|
-
const styles = StyleSheet.create({
|
|
18
|
-
container: {
|
|
19
|
-
height: 44,
|
|
20
|
-
justifyContent: 'flex-end',
|
|
21
|
-
},
|
|
22
|
-
text: {
|
|
23
|
-
color: Color.defaultBlue,
|
|
24
|
-
fontWeight: '600',
|
|
25
|
-
fontSize: 17,
|
|
26
|
-
backgroundColor: Color.backgroundTransparent,
|
|
27
|
-
marginBottom: 12,
|
|
28
|
-
marginLeft: 10,
|
|
29
|
-
marginRight: 10,
|
|
30
|
-
},
|
|
31
|
-
text_dark: {
|
|
32
|
-
color: '#4da6ff',
|
|
33
|
-
},
|
|
34
|
-
})
|
|
15
|
+
import { IMessage } from './Models'
|
|
35
16
|
|
|
36
17
|
export interface SendProps<TMessage extends IMessage> {
|
|
37
18
|
text?: string
|
|
@@ -39,8 +20,7 @@ export interface SendProps<TMessage extends IMessage> {
|
|
|
39
20
|
containerStyle?: StyleProp<ViewStyle>
|
|
40
21
|
textStyle?: StyleProp<TextStyle>
|
|
41
22
|
children?: React.ReactNode
|
|
42
|
-
|
|
43
|
-
disabled?: boolean
|
|
23
|
+
isSendButtonAlwaysVisible?: boolean
|
|
44
24
|
sendButtonProps?: Partial<TouchableOpacityProps>
|
|
45
25
|
onSend?(
|
|
46
26
|
messages: Partial<TMessage> | Partial<TMessage>[],
|
|
@@ -54,21 +34,22 @@ export const Send = <TMessage extends IMessage = IMessage>({
|
|
|
54
34
|
children,
|
|
55
35
|
textStyle,
|
|
56
36
|
label = 'Send',
|
|
57
|
-
|
|
58
|
-
disabled = false,
|
|
37
|
+
isSendButtonAlwaysVisible = false,
|
|
59
38
|
sendButtonProps,
|
|
60
39
|
onSend,
|
|
61
40
|
}: SendProps<TMessage>) => {
|
|
62
41
|
const colorScheme = useColorScheme()
|
|
63
42
|
|
|
64
43
|
const handleOnPress = useCallback(() => {
|
|
65
|
-
|
|
66
|
-
|
|
44
|
+
const message = { text: text?.trim() } as Partial<TMessage>
|
|
45
|
+
|
|
46
|
+
if (onSend && message.text?.length)
|
|
47
|
+
onSend(message, true)
|
|
67
48
|
}, [text, onSend])
|
|
68
49
|
|
|
69
50
|
const showSend = useMemo(
|
|
70
|
-
() =>
|
|
71
|
-
[
|
|
51
|
+
() => isSendButtonAlwaysVisible || !!text?.trim().length,
|
|
52
|
+
[isSendButtonAlwaysVisible, text]
|
|
72
53
|
)
|
|
73
54
|
|
|
74
55
|
if (!showSend)
|
|
@@ -77,12 +58,11 @@ export const Send = <TMessage extends IMessage = IMessage>({
|
|
|
77
58
|
return (
|
|
78
59
|
<TouchableOpacity
|
|
79
60
|
testID={TEST_ID.SEND_TOUCHABLE}
|
|
80
|
-
accessible
|
|
81
|
-
accessibilityLabel='send'
|
|
82
61
|
style={[styles.container, containerStyle]}
|
|
83
62
|
onPress={handleOnPress}
|
|
63
|
+
accessible
|
|
64
|
+
accessibilityLabel='send'
|
|
84
65
|
accessibilityRole='button'
|
|
85
|
-
disabled={disabled}
|
|
86
66
|
{...sendButtonProps}
|
|
87
67
|
>
|
|
88
68
|
<View>
|
|
@@ -91,3 +71,22 @@ export const Send = <TMessage extends IMessage = IMessage>({
|
|
|
91
71
|
</TouchableOpacity>
|
|
92
72
|
)
|
|
93
73
|
}
|
|
74
|
+
|
|
75
|
+
const styles = StyleSheet.create({
|
|
76
|
+
container: {
|
|
77
|
+
height: 44,
|
|
78
|
+
justifyContent: 'flex-end',
|
|
79
|
+
},
|
|
80
|
+
text: {
|
|
81
|
+
color: Color.defaultBlue,
|
|
82
|
+
fontWeight: '600',
|
|
83
|
+
fontSize: 17,
|
|
84
|
+
backgroundColor: Color.backgroundTransparent,
|
|
85
|
+
marginBottom: 12,
|
|
86
|
+
marginLeft: 10,
|
|
87
|
+
marginRight: 10,
|
|
88
|
+
},
|
|
89
|
+
text_dark: {
|
|
90
|
+
color: '#4da6ff',
|
|
91
|
+
},
|
|
92
|
+
})
|
package/src/SystemMessage.tsx
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
StyleProp,
|
|
7
7
|
TextStyle,
|
|
8
8
|
} from 'react-native'
|
|
9
|
-
import Color from './Color'
|
|
9
|
+
import { Color } from './Color'
|
|
10
10
|
import { MessageText } from './MessageText'
|
|
11
|
+
import { IMessage } from './Models'
|
|
11
12
|
import stylesCommon from './styles'
|
|
12
|
-
import { IMessage } from './types'
|
|
13
13
|
|
|
14
14
|
export interface SystemMessageProps<TMessage extends IMessage> {
|
|
15
15
|
currentMessage: TMessage
|
package/src/Time.tsx
CHANGED
|
@@ -2,10 +2,10 @@ import React, { useMemo } from 'react'
|
|
|
2
2
|
import { StyleSheet, Text, View, ViewStyle, TextStyle } from 'react-native'
|
|
3
3
|
import dayjs from 'dayjs'
|
|
4
4
|
|
|
5
|
-
import Color from './Color'
|
|
5
|
+
import { Color } from './Color'
|
|
6
6
|
import { TIME_FORMAT } from './Constant'
|
|
7
7
|
import { useChatContext } from './GiftedChatContext'
|
|
8
|
-
import { LeftRightStyle, IMessage } from './
|
|
8
|
+
import { LeftRightStyle, IMessage } from './Models'
|
|
9
9
|
|
|
10
10
|
const { containerStyle } = StyleSheet.create({
|
|
11
11
|
containerStyle: {
|
|
@@ -51,23 +51,23 @@ export interface TimeProps<TMessage extends IMessage> {
|
|
|
51
51
|
timeFormat?: string
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export
|
|
54
|
+
export const Time = <TMessage extends IMessage = IMessage>({
|
|
55
55
|
position = 'left',
|
|
56
56
|
containerStyle,
|
|
57
57
|
currentMessage,
|
|
58
58
|
timeFormat = TIME_FORMAT,
|
|
59
59
|
timeTextStyle,
|
|
60
|
-
}: TimeProps<TMessage>) {
|
|
60
|
+
}: TimeProps<TMessage>) => {
|
|
61
61
|
const { getLocale } = useChatContext()
|
|
62
62
|
|
|
63
63
|
const formattedTime = useMemo(() => {
|
|
64
|
-
if (currentMessage
|
|
64
|
+
if (!currentMessage)
|
|
65
65
|
return null
|
|
66
66
|
|
|
67
67
|
return dayjs(currentMessage.createdAt).locale(getLocale()).format(timeFormat)
|
|
68
68
|
}, [currentMessage, getLocale, timeFormat])
|
|
69
69
|
|
|
70
|
-
if (currentMessage
|
|
70
|
+
if (!currentMessage)
|
|
71
71
|
return null
|
|
72
72
|
|
|
73
73
|
return (
|
|
@@ -89,7 +89,7 @@ const DotsAnimation = () => {
|
|
|
89
89
|
)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
const TypingIndicator = ({ isTyping, style }: TypingIndicatorProps) => {
|
|
92
|
+
export const TypingIndicator = ({ isTyping, style }: TypingIndicatorProps) => {
|
|
93
93
|
const yCoords = useSharedValue(200)
|
|
94
94
|
const heightScale = useSharedValue(0)
|
|
95
95
|
const marginScale = useSharedValue(0)
|
|
@@ -153,5 +153,3 @@ const TypingIndicator = ({ isTyping, style }: TypingIndicatorProps) => {
|
|
|
153
153
|
</Animated.View>
|
|
154
154
|
)
|
|
155
155
|
}
|
|
156
|
-
|
|
157
|
-
export default TypingIndicator
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { Actions } from '
|
|
4
|
+
import { Actions } from '..'
|
|
5
5
|
|
|
6
6
|
it('should render <Actions /> and compare with snapshot', () => {
|
|
7
7
|
const { toJSON } = render(<Actions />)
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { Avatar } from '
|
|
4
|
+
import { Avatar } from '..'
|
|
5
|
+
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
5
6
|
|
|
6
7
|
it('should render <Avatar /> and compare with snapshot', () => {
|
|
7
8
|
const { toJSON } = render(
|
|
8
|
-
<Avatar
|
|
9
|
+
<Avatar
|
|
10
|
+
renderAvatar={() => 'renderAvatar'}
|
|
11
|
+
position='left'
|
|
12
|
+
currentMessage={DEFAULT_TEST_MESSAGE}
|
|
13
|
+
/>
|
|
9
14
|
)
|
|
10
15
|
|
|
11
16
|
expect(toJSON()).toMatchSnapshot()
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { Bubble } from '
|
|
4
|
+
import { Bubble } from '..'
|
|
5
|
+
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
5
6
|
|
|
6
7
|
it('should render <Bubble /> and compare with snapshot', () => {
|
|
7
8
|
const { toJSON } = render(
|
|
8
9
|
<Bubble
|
|
9
10
|
user={{ _id: 1 }}
|
|
10
|
-
currentMessage={
|
|
11
|
-
_id: 1,
|
|
12
|
-
text: 'test',
|
|
13
|
-
createdAt: 1554744013721,
|
|
14
|
-
user: { _id: 1 },
|
|
15
|
-
}}
|
|
11
|
+
currentMessage={DEFAULT_TEST_MESSAGE}
|
|
16
12
|
position='left'
|
|
17
13
|
/>
|
|
18
14
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { Composer } from '
|
|
4
|
+
import { Composer } from '..'
|
|
5
5
|
|
|
6
6
|
it('should render <Composer /> and compare with snapshot', () => {
|
|
7
7
|
const { toJSON } = render(<Composer />)
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { Day } from '
|
|
4
|
+
import { Day } from '..'
|
|
5
5
|
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
6
6
|
|
|
7
7
|
describe('Day', () => {
|
|
8
8
|
it('should not render <Day /> and compare with snapshot', () => {
|
|
9
|
-
const { toJSON } = render(<Day />)
|
|
9
|
+
const { toJSON } = render(<Day createdAt={DEFAULT_TEST_MESSAGE.createdAt} />)
|
|
10
10
|
|
|
11
11
|
expect(toJSON()).toMatchSnapshot()
|
|
12
12
|
})
|
|
13
13
|
|
|
14
14
|
it('should render <Day /> and compare with snapshot', () => {
|
|
15
15
|
const { toJSON } = render(
|
|
16
|
-
<Day
|
|
16
|
+
<Day createdAt={DEFAULT_TEST_MESSAGE.createdAt} />
|
|
17
17
|
)
|
|
18
18
|
expect(toJSON()).toMatchSnapshot()
|
|
19
19
|
})
|
|
@@ -2,19 +2,13 @@ import React from 'react'
|
|
|
2
2
|
import { View, Text } from 'react-native'
|
|
3
3
|
import { render } from '@testing-library/react-native'
|
|
4
4
|
import { DayProps } from '../Day'
|
|
5
|
-
import DayAnimated from '../MessageContainer/components/DayAnimated'
|
|
5
|
+
import { DayAnimated } from '../MessageContainer/components/DayAnimated'
|
|
6
|
+
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
6
7
|
|
|
7
8
|
const mockDaysPositions = { value: {} }
|
|
8
9
|
const mockScrolledY = { value: 0 }
|
|
9
10
|
const mockListHeight = { value: 800 }
|
|
10
11
|
|
|
11
|
-
const mockMessage = {
|
|
12
|
-
_id: 1,
|
|
13
|
-
text: 'Hello',
|
|
14
|
-
createdAt: new Date('2023-01-01'),
|
|
15
|
-
user: { _id: 1, name: 'User 1' },
|
|
16
|
-
}
|
|
17
|
-
|
|
18
12
|
describe('DayAnimated', () => {
|
|
19
13
|
it('should render DayAnimated with default Day component', () => {
|
|
20
14
|
const { toJSON } = render(
|
|
@@ -22,7 +16,7 @@ describe('DayAnimated', () => {
|
|
|
22
16
|
scrolledY={mockScrolledY}
|
|
23
17
|
daysPositions={mockDaysPositions}
|
|
24
18
|
listHeight={mockListHeight}
|
|
25
|
-
messages={[
|
|
19
|
+
messages={[DEFAULT_TEST_MESSAGE]}
|
|
26
20
|
isLoading={false}
|
|
27
21
|
/>
|
|
28
22
|
)
|
|
@@ -32,7 +26,7 @@ describe('DayAnimated', () => {
|
|
|
32
26
|
it('should use custom renderDay when provided', () => {
|
|
33
27
|
const customRenderDay = jest.fn((props: DayProps) => (
|
|
34
28
|
<View testID='custom-day'>
|
|
35
|
-
<Text>Custom Day: {props.createdAt}</Text>
|
|
29
|
+
<Text>Custom Day: {props.createdAt.toLocaleString()}</Text>
|
|
36
30
|
</View>
|
|
37
31
|
))
|
|
38
32
|
|
|
@@ -41,7 +35,7 @@ describe('DayAnimated', () => {
|
|
|
41
35
|
scrolledY={mockScrolledY}
|
|
42
36
|
daysPositions={mockDaysPositions}
|
|
43
37
|
listHeight={mockListHeight}
|
|
44
|
-
messages={[
|
|
38
|
+
messages={[DEFAULT_TEST_MESSAGE]}
|
|
45
39
|
isLoading={false}
|
|
46
40
|
renderDay={customRenderDay}
|
|
47
41
|
/>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { GiftedAvatar } from '
|
|
4
|
+
import { GiftedAvatar } from '..'
|
|
5
5
|
|
|
6
6
|
it('should render <GiftedAvatar /> and compare with snapshot', () => {
|
|
7
7
|
const { toJSON } = render(<GiftedAvatar />)
|
|
@@ -2,7 +2,7 @@ import React from 'react'
|
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
4
|
import { useReanimatedKeyboardAnimation } from 'react-native-keyboard-controller'
|
|
5
|
-
import { GiftedChat } from '
|
|
5
|
+
import { GiftedChat } from '..'
|
|
6
6
|
|
|
7
7
|
const messages = [
|
|
8
8
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { InputToolbar } from '
|
|
4
|
+
import { InputToolbar } from '..'
|
|
5
5
|
|
|
6
6
|
it('should render <InputToolbar /> and compare with snapshot', () => {
|
|
7
7
|
const { toJSON } = render(<InputToolbar />)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { LoadEarlierMessages } from '
|
|
4
|
+
import { LoadEarlierMessages } from '..'
|
|
5
5
|
|
|
6
6
|
it('should render <LoadEarlierMessages /> and compare with snapshot', () => {
|
|
7
|
-
const { toJSON } = render(<LoadEarlierMessages />)
|
|
7
|
+
const { toJSON } = render(<LoadEarlierMessages isAvailable isLoading={false} onPress={() => {}} />)
|
|
8
8
|
|
|
9
9
|
expect(toJSON()).toMatchSnapshot()
|
|
10
10
|
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { Message } from '
|
|
4
|
+
import { Message } from '..'
|
|
5
|
+
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
5
6
|
|
|
6
7
|
describe('Message component', () => {
|
|
7
8
|
it('should render <Message /> and compare with snapshot', () => {
|
|
@@ -35,14 +36,9 @@ describe('Message component', () => {
|
|
|
35
36
|
<Message
|
|
36
37
|
key='123'
|
|
37
38
|
user={{ _id: 1 }}
|
|
38
|
-
currentMessage={
|
|
39
|
-
_id: 1,
|
|
40
|
-
text: 'test',
|
|
41
|
-
createdAt: 1554744013721,
|
|
42
|
-
user: { _id: 1 },
|
|
43
|
-
}}
|
|
39
|
+
currentMessage={DEFAULT_TEST_MESSAGE}
|
|
44
40
|
position='left'
|
|
45
|
-
|
|
41
|
+
isUserAvatarVisible
|
|
46
42
|
/>
|
|
47
43
|
)
|
|
48
44
|
|
|
@@ -55,16 +51,14 @@ describe('Message component', () => {
|
|
|
55
51
|
key='123'
|
|
56
52
|
user={{ _id: 1 }}
|
|
57
53
|
currentMessage={{
|
|
58
|
-
|
|
59
|
-
text: 'test',
|
|
60
|
-
createdAt: 1554744013721,
|
|
54
|
+
...DEFAULT_TEST_MESSAGE,
|
|
61
55
|
user: {
|
|
62
56
|
_id: 1,
|
|
63
|
-
avatar:
|
|
57
|
+
avatar: undefined,
|
|
64
58
|
},
|
|
65
59
|
}}
|
|
66
60
|
position='left'
|
|
67
|
-
|
|
61
|
+
isUserAvatarVisible
|
|
68
62
|
/>
|
|
69
63
|
)
|
|
70
64
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { MessageContainer } from '
|
|
4
|
+
import { MessageContainer } from '..'
|
|
5
5
|
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
6
6
|
|
|
7
7
|
it('should render <MessageContainer /> without crashing', () => {
|
|
@@ -9,7 +9,7 @@ it('should render <MessageContainer /> without crashing', () => {
|
|
|
9
9
|
expect(() => render(
|
|
10
10
|
<MessageContainer
|
|
11
11
|
messages={[DEFAULT_TEST_MESSAGE]}
|
|
12
|
-
user={{ _id:
|
|
12
|
+
user={{ _id: 1 }}
|
|
13
13
|
/>
|
|
14
14
|
)).not.toThrow()
|
|
15
15
|
})
|
|
@@ -23,7 +23,7 @@ it('should render <MessageContainer /> with multiple messages', () => {
|
|
|
23
23
|
expect(() => render(
|
|
24
24
|
<MessageContainer
|
|
25
25
|
messages={messages}
|
|
26
|
-
user={{ _id:
|
|
26
|
+
user={{ _id: 1 }}
|
|
27
27
|
/>
|
|
28
28
|
)).not.toThrow()
|
|
29
29
|
})
|
|
@@ -32,7 +32,7 @@ it('should render <MessageContainer /> with empty messages', () => {
|
|
|
32
32
|
expect(() => render(
|
|
33
33
|
<MessageContainer
|
|
34
34
|
messages={[]}
|
|
35
|
-
user={{ _id:
|
|
35
|
+
user={{ _id: 1 }}
|
|
36
36
|
/>
|
|
37
37
|
)).not.toThrow()
|
|
38
38
|
})
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { MessageImage } from '
|
|
4
|
+
import { MessageImage } from '..'
|
|
5
5
|
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
6
6
|
|
|
7
7
|
describe('MessageImage', () => {
|
|
8
8
|
it('should not render <MessageImage /> and compare with snapshot', () => {
|
|
9
|
-
const { toJSON } = render(<MessageImage />)
|
|
9
|
+
const { toJSON } = render(<MessageImage currentMessage={null} />)
|
|
10
10
|
expect(toJSON()).toMatchSnapshot()
|
|
11
11
|
})
|
|
12
12
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { MessageText } from '
|
|
4
|
+
import { MessageText } from '..'
|
|
5
|
+
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
5
6
|
|
|
6
7
|
it('should render <MessageText /> and compare with snapshot', () => {
|
|
7
8
|
const { toJSON } = render(
|
|
8
9
|
<MessageText
|
|
9
|
-
currentMessage={
|
|
10
|
+
currentMessage={DEFAULT_TEST_MESSAGE}
|
|
10
11
|
/>
|
|
11
12
|
)
|
|
12
13
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { render } from '@testing-library/react-native'
|
|
3
3
|
|
|
4
|
-
import { Send } from '
|
|
4
|
+
import { Send } from '..'
|
|
5
5
|
|
|
6
6
|
describe('Send', () => {
|
|
7
7
|
it('should not render <Send /> and compare with snapshot', () => {
|
|
@@ -10,7 +10,7 @@ describe('Send', () => {
|
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
it('should always render <Send /> and compare with snapshot', () => {
|
|
13
|
-
const { toJSON } = render(<Send
|
|
13
|
+
const { toJSON } = render(<Send isSendButtonAlwaysVisible />)
|
|
14
14
|
expect(toJSON()).toMatchSnapshot()
|
|
15
15
|
})
|
|
16
16
|
|