/** * Copyright (c) 2019 Paul Armstrong */ import AppBar from '../AppBar'; import Button from '../Button'; import Menu from '../Menu'; import MenuIcon from '../../icons/Menu'; import MenuItem from '../MenuItem'; import MoreIcon from '../../icons/More'; import React from 'react'; import { fireEvent, render } from 'react-native-testing-library'; import { Text, View } from 'react-native'; describe('AppBar', () => { describe('rendering', () => { test('renders a blank bar', () => { const { getByType } = render(); expect(() => getByType(Text)).toThrow(); }); test('renders a basic bar with a title when given a string', () => { const { getByText } = render(); expect(getByText('Tacos')).not.toBeUndefined(); }); test('renders a title as provided when given an element', () => { const title = ; const { getByTestId } = render(); expect(getByTestId('foo')).not.toBeUndefined(); }); test('renders a button when provided a navigationIcon', () => { const { getByType } = render(); const button = getByType(Button); expect(button.props).toEqual(expect.objectContaining({ color: 'primary', icon: MenuIcon, title: 'Menu' })); }); test('renders action items', () => { const actionItems = [, ]; const { getByTestId } = render(); expect(getByTestId('tacos')).not.toBeUndefined(); expect(getByTestId('burritos')).not.toBeUndefined(); }); test('renders a button for overflow items', () => { const { getByType } = render(} />); expect(getByType(Button).props).toMatchObject({ icon: MoreIcon, iconOnly: true, title: 'More actions', }); }); }); describe('overflow items', () => { test('shows a menu on button press', () => { const { getByType, queryAllByProps } = render(} />); expect(queryAllByProps({ accessibilityRole: 'menu' })).toHaveLength(0); fireEvent.press(getByType(Button)); expect(queryAllByProps({ accessibilityRole: 'menu' })).toHaveLength(2); }); test('hides the menu on dismiss', () => { const { getByType, queryAllByProps } = render(} />); fireEvent.press(getByType(Button)); expect(queryAllByProps({ accessibilityRole: 'menu' })).toHaveLength(2); fireEvent(getByType(Menu), 'dismiss'); expect(queryAllByProps({ accessibilityRole: 'menu' })).toHaveLength(0); }); test('does not re-show the menu when overflowItems changes', () => { const { getByType, queryAllByProps, update } = render( } /> ); fireEvent.press(getByType(Button)); expect(queryAllByProps({ accessibilityRole: 'menu' })).toHaveLength(2); update(); expect(queryAllByProps({ accessibilityRole: 'menu' })).toHaveLength(0); update(} />); expect(queryAllByProps({ accessibilityRole: 'menu' })).toHaveLength(0); }); }); });