flyerhq/react-native-keyboard-accessory-view

View on GitHub
src/__tests__/KeyboardAccessoryView.test.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import { act, render } from '@testing-library/react-native'
import React from 'react'
import { NativeEventEmitter, ScrollView } from 'react-native'

import { keyboardOpenEvent } from '../../jest/fixtures'
import { KeyboardAccessoryView } from '../KeyboardAccessoryView'

const emitter = new NativeEventEmitter()

describe('keyboard accessory view', () => {
  it('sticks to the bottom with a closed keyboard', () => {
    expect.assertions(1)
    const { getByTestId } = render(
      <KeyboardAccessoryView renderScrollable={() => <ScrollView />} />
    )
    const container = getByTestId('container')
    expect(container.props.style).toHaveProperty('bottom', 0)
  })

  it('sticks to the keyboard top with an open keyboard', () => {
    expect.assertions(1)
    const { getByTestId } = render(
      <KeyboardAccessoryView renderScrollable={() => <ScrollView />} />
    )
    act(() => {
      emitter.emit('keyboardWillChangeFrame', keyboardOpenEvent)
    })
    const container = getByTestId('container')
    expect(container.props.style).toHaveProperty('bottom', 346)
  })
})