import { render, screen } from '@testing-library/react-native'
import React from 'react'
import { Text } from 'react-native'
import { MenuAdapter, MenuViewProps } from '../menu'
const actions = [{ id: 'all', title: 'All' }]
describe('MenuAdapter', () => {
it('renders the trigger and warns when the host configured no menu', () => {
const warn = jest.spyOn(console, 'warn').mockImplementation(() => {})
const { View, isConfigured } = new MenuAdapter()
expect(isConfigured).toBe(false)
render(
Trigger
)
expect(screen.getByText('Trigger')).toBeTruthy()
expect(warn).toHaveBeenCalledTimes(1)
warn.mockRestore()
})
it('renders through the view the host supplies', () => {
const HostMenuView = ({ actions: hostActions, children }: MenuViewProps) => (
<>
{children}
{hostActions.map(action => action.title).join(',')}
>
)
const { View, isConfigured } = new MenuAdapter({ View: HostMenuView })
expect(isConfigured).toBe(true)
render(
Trigger
)
expect(screen.getByText('Trigger')).toBeTruthy()
expect(screen.getByText('All')).toBeTruthy()
})
})