Restructure the project

This commit is contained in:
Alex Demchenko
2020-05-09 12:52:36 +02:00
parent 2b0f2a6cf6
commit ea6463dac3
25 changed files with 42 additions and 36 deletions

View File

@@ -74,7 +74,7 @@
],
"preset": "react-native",
"setupFiles": [
"./src/jest.setup.ts"
"./src/utils/jest.setup.ts"
]
},
"typeCoverage": {

View File

@@ -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')
})

View File

@@ -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 {

View File

@@ -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', () => {

View File

@@ -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 {

View File

@@ -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', () => {

View File

@@ -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>
)
}

View File

@@ -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 {

View File

@@ -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', () => {

View File

@@ -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
View File

@@ -0,0 +1,4 @@
export * from './Chat'
export * from './Input'
export * from './SendButton'
export * from './TextMessage'

View File

@@ -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'

View 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')
})
})

View File

@@ -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
View File

@@ -0,0 +1 @@
export * from './utils'