154 lines
4.9 KiB
TypeScript
154 lines
4.9 KiB
TypeScript
import React from 'react'
|
|
import { render } from '@testing-library/react-native'
|
|
import { LikeButton } from './LikeButton'
|
|
|
|
describe('LikeButton Component', () => {
|
|
describe('Component Export', () => {
|
|
it('should be defined', () => {
|
|
expect(LikeButton).toBeDefined()
|
|
})
|
|
|
|
it('should be wrapped with React.memo', () => {
|
|
expect(typeof LikeButton).toBe('object')
|
|
})
|
|
})
|
|
|
|
describe('Props Interface', () => {
|
|
it('should accept liked prop', () => {
|
|
const props = { liked: true }
|
|
expect(props.liked).toBe(true)
|
|
})
|
|
|
|
it('should accept loading prop', () => {
|
|
const props = { loading: true }
|
|
expect(props.loading).toBe(true)
|
|
})
|
|
|
|
it('should accept count prop', () => {
|
|
const props = { count: 100 }
|
|
expect(props.count).toBe(100)
|
|
})
|
|
|
|
it('should accept size prop', () => {
|
|
const props = { size: 24 }
|
|
expect(props.size).toBe(24)
|
|
})
|
|
|
|
it('should accept onPress callback', () => {
|
|
const onPress = jest.fn()
|
|
expect(typeof onPress).toBe('function')
|
|
})
|
|
|
|
it('should accept testID prop', () => {
|
|
const props = { testID: 'like-button' }
|
|
expect(props.testID).toBe('like-button')
|
|
})
|
|
})
|
|
|
|
describe('Default Values', () => {
|
|
it('should have default liked value of false', () => {
|
|
const defaultLiked = false
|
|
expect(defaultLiked).toBe(false)
|
|
})
|
|
|
|
it('should have default loading value of false', () => {
|
|
const defaultLoading = false
|
|
expect(defaultLoading).toBe(false)
|
|
})
|
|
|
|
it('should have default size value of 24', () => {
|
|
const defaultSize = 24
|
|
expect(defaultSize).toBe(24)
|
|
})
|
|
})
|
|
|
|
describe('Rendering', () => {
|
|
it('should render successfully', () => {
|
|
const { getByTestId } = render(<LikeButton testID="like-button" />)
|
|
expect(getByTestId('like-button')).toBeTruthy()
|
|
})
|
|
|
|
it('should render with default props', () => {
|
|
const { getByTestId } = render(<LikeButton testID="like-button-default" />)
|
|
expect(getByTestId('like-button-default')).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('Liked State', () => {
|
|
it('should render outline heart when liked is false', () => {
|
|
const { getByTestId } = render(<LikeButton liked={false} testID="like-button-unliked" />)
|
|
const button = getByTestId('like-button-unliked')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
|
|
it('should render filled heart when liked is true', () => {
|
|
const { getByTestId } = render(<LikeButton liked={true} testID="like-button-liked" />)
|
|
const button = getByTestId('like-button-liked')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('Loading State', () => {
|
|
it('should render loading state when loading is true', () => {
|
|
const { getByTestId } = render(<LikeButton loading={true} testID="like-button-loading" />)
|
|
const button = getByTestId('like-button-loading')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
|
|
it('should disable button when loading', () => {
|
|
const { getByTestId } = render(<LikeButton loading={true} testID="like-button-disabled" />)
|
|
const button = getByTestId('like-button-disabled')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('Count Display', () => {
|
|
it('should render count when provided', () => {
|
|
const { getByTestId } = render(<LikeButton count={42} testID="like-button-count" />)
|
|
const button = getByTestId('like-button-count')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
|
|
it('should not render count when not provided', () => {
|
|
const { getByTestId } = render(<LikeButton testID="like-button-no-count" />)
|
|
const button = getByTestId('like-button-no-count')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
|
|
it('should display zero count', () => {
|
|
const { getByTestId } = render(<LikeButton count={0} testID="like-button-zero" />)
|
|
const button = getByTestId('like-button-zero')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('Custom Size', () => {
|
|
it('should render with custom size', () => {
|
|
const { getByTestId } = render(<LikeButton size={32} testID="like-button-size" />)
|
|
const button = getByTestId('like-button-size')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
|
|
it('should render with small size', () => {
|
|
const { getByTestId } = render(<LikeButton size={16} testID="like-button-small" />)
|
|
const button = getByTestId('like-button-small')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
|
|
it('should render with large size', () => {
|
|
const { getByTestId } = render(<LikeButton size={48} testID="like-button-large" />)
|
|
const button = getByTestId('like-button-large')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
describe('Press Handler', () => {
|
|
it('should accept onPress callback', () => {
|
|
const onPress = jest.fn()
|
|
const { getByTestId } = render(<LikeButton onPress={onPress} testID="like-button-press" />)
|
|
const button = getByTestId('like-button-press')
|
|
expect(button).toBeTruthy()
|
|
})
|
|
})
|
|
})
|