mirror of
https://github.com/zhigang1992/react-native-chat-ui.git
synced 2026-05-27 09:03:53 +08:00
Restructure the project
This commit is contained in:
@@ -74,7 +74,7 @@
|
||||
],
|
||||
"preset": "react-native",
|
||||
"setupFiles": [
|
||||
"./src/jest.setup.ts"
|
||||
"./src/utils/jest.setup.ts"
|
||||
]
|
||||
},
|
||||
"typeCoverage": {
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { getTextSizeInBytes, uuidv4 } from '../utils'
|
||||
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
jest.spyOn(Math, 'random').mockReturnValue(0)
|
||||
})
|
||||
|
||||
test('it calculates size in bytes for the simple text', () => {
|
||||
const text = 'text'
|
||||
expect(getTextSizeInBytes(text)).toEqual(4)
|
||||
})
|
||||
|
||||
test('it calculates size in bytes for the emoji text', () => {
|
||||
const text = '🤔 🤓'
|
||||
expect(getTextSizeInBytes(text)).toEqual(9)
|
||||
})
|
||||
|
||||
test('uuidv4', () => {
|
||||
expect(uuidv4()).toEqual('00000000-0000-4000-8000-000000000000')
|
||||
})
|
||||
@@ -1,9 +1,9 @@
|
||||
import * as React from 'react'
|
||||
import { FlatList, SafeAreaView } from 'react-native'
|
||||
import { useComponentSize, useKeyboardBottomInset } from '../hooks'
|
||||
import { useComponentSize, useKeyboardBottomInset } from '../../hooks'
|
||||
import { Message, User } from '../../types'
|
||||
import { Input, InputProps } from '../Input'
|
||||
import { TextMessage } from '../TextMessage'
|
||||
import { Message, User } from '../types'
|
||||
import styles from './styles'
|
||||
|
||||
export interface ChatProps extends InputProps {
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react'
|
||||
import { fireEvent, render } from 'react-native-testing-library'
|
||||
import { message, user } from '../../fixtures'
|
||||
import { message, user } from '../../../utils/fixtures'
|
||||
import { Chat } from '../Chat'
|
||||
|
||||
test('it calls onSendPress', () => {
|
||||
@@ -6,9 +6,9 @@ import {
|
||||
TextInputProps,
|
||||
View,
|
||||
} from 'react-native'
|
||||
import { Message, User } from '../../types'
|
||||
import { uuidv4 } from '../../utils'
|
||||
import { SendButton } from '../SendButton'
|
||||
import { Message, User } from '../types'
|
||||
import { uuidv4 } from '../utils'
|
||||
import styles from './styles'
|
||||
|
||||
export interface InputProps {
|
||||
@@ -2,7 +2,7 @@ import * as React from 'react'
|
||||
import { InputAccessoryView, View } from 'react-native'
|
||||
import { fireEvent, render } from 'react-native-testing-library'
|
||||
import { ReactTestInstance } from 'react-test-renderer'
|
||||
import { message, user } from '../../fixtures'
|
||||
import { message, user } from '../../../utils/fixtures'
|
||||
import { Input } from '../Input'
|
||||
|
||||
describe('input', () => {
|
||||
@@ -31,7 +31,7 @@ export const SendButton = ({
|
||||
{...touchableOpacityProps}
|
||||
onPress={handlePress}
|
||||
>
|
||||
<Image source={require('../assets/icon-send.png')} />
|
||||
<Image source={require('../../assets/icon-send.png')} />
|
||||
</TouchableOpacity>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react'
|
||||
import { Text, View } from 'react-native'
|
||||
import { Message, Size, User } from '../types'
|
||||
import { Message, Size, User } from '../../types'
|
||||
import styles from './styles'
|
||||
|
||||
export interface TextMessageProps {
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as React from 'react'
|
||||
import { render } from 'react-native-testing-library'
|
||||
import { message, size, user } from '../../fixtures'
|
||||
import { message, size, user } from '../../../utils/fixtures'
|
||||
import { TextMessage } from '../TextMessage'
|
||||
|
||||
test('it renders text', () => {
|
||||
@@ -1,5 +1,5 @@
|
||||
import { StyleSheet } from 'react-native'
|
||||
import { Message, Size, User } from '../types'
|
||||
import { Message, Size, User } from '../../types'
|
||||
|
||||
const styles = ({
|
||||
message,
|
||||
4
src/components/index.ts
Normal file
4
src/components/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './Chat'
|
||||
export * from './Input'
|
||||
export * from './SendButton'
|
||||
export * from './TextMessage'
|
||||
@@ -1,7 +1,4 @@
|
||||
export * from './Chat'
|
||||
export * from './Input'
|
||||
export * from './SendButton'
|
||||
export * from './TextMessage'
|
||||
export * from './components'
|
||||
export * from './hooks'
|
||||
export * from './types'
|
||||
export * from './utils'
|
||||
|
||||
24
src/utils/__tests__/utils.test.ts
Normal file
24
src/utils/__tests__/utils.test.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { getTextSizeInBytes, uuidv4 } from '../'
|
||||
|
||||
describe('Text size in bytes', () => {
|
||||
test('it calculates the size for a simple text', () => {
|
||||
const text = 'text'
|
||||
expect(getTextSizeInBytes(text)).toEqual(4)
|
||||
})
|
||||
|
||||
test('it calculates the size for an emoji text', () => {
|
||||
const text = '🤔 🤓'
|
||||
expect(getTextSizeInBytes(text)).toEqual(9)
|
||||
})
|
||||
})
|
||||
|
||||
describe('uuiv4', () => {
|
||||
beforeEach(() => {
|
||||
jest.restoreAllMocks()
|
||||
jest.spyOn(Math, 'random').mockReturnValue(0)
|
||||
})
|
||||
|
||||
test('it generates specific id when Math.random returns only 0', () => {
|
||||
expect(uuidv4()).toEqual('00000000-0000-4000-8000-000000000000')
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Message, Size, User } from './types'
|
||||
import { Message, Size, User } from '../types'
|
||||
|
||||
export const message: Message = {
|
||||
authorId: 'userId',
|
||||
1
src/utils/index.ts
Normal file
1
src/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './utils'
|
||||
Reference in New Issue
Block a user