about summary refs log tree commit diff
path: root/__tests__/view/shell/mobile/Menu.test.tsx
blob: caec5f29a739b332bc5b85592d107ff8accf89a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React from 'react'
import {Menu} from '../../../../src/view/shell/mobile/Menu'
import {cleanup, fireEvent, render} from '../../../../jest/test-utils'
import {
  mockedNavigationStore,
  mockedShellStore,
} from '../../../../__mocks__/state-mock'

describe('Menu', () => {
  const onCloseMock = jest.fn()

  const mockedProps = {
    visible: true,
    onClose: onCloseMock,
  }

  afterAll(() => {
    jest.clearAllMocks()
    cleanup()
  })

  it('renders menu', () => {
    const {getByTestId} = render(<Menu {...mockedProps} />)

    const menuView = getByTestId('menuView')

    expect(menuView).toBeTruthy()
  })

  it('presses profile card button', () => {
    const {getByTestId} = render(<Menu {...mockedProps} />)

    const profileCardButton = getByTestId('profileCardButton')
    fireEvent.press(profileCardButton)

    expect(onCloseMock).toHaveBeenCalled()
    expect(mockedNavigationStore.switchTo).toHaveBeenCalledWith(0, true)
  })

  it('presses search button', () => {
    const {getByTestId} = render(<Menu {...mockedProps} />)

    const searchBtn = getByTestId('searchBtn')
    fireEvent.press(searchBtn)

    expect(onCloseMock).toHaveBeenCalled()
    expect(mockedNavigationStore.switchTo).toHaveBeenCalledWith(0, true)
    expect(mockedNavigationStore.navigate).toHaveBeenCalledWith('/search')
  })

  it("presses notifications menu item' button", () => {
    const {getAllByTestId} = render(<Menu {...mockedProps} />)

    const menuItemButton = getAllByTestId('menuItemButton')
    fireEvent.press(menuItemButton[1])

    expect(onCloseMock).toHaveBeenCalled()
    expect(mockedNavigationStore.switchTo).toHaveBeenCalledWith(1, true)
  })
})