about summary refs log tree commit diff
path: root/__tests__/view/com/profile/ProfileHeader.test.tsx
blob: 6ffe1a9a27374c82531e732829d1ca1dd08abd52 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React from 'react'
import {cleanup, fireEvent, render} from '../../../../jest/test-utils'
import {ProfileViewModel} from '../../../../src/state/models/profile-view'
import {ProfileHeader} from '../../../../src/view/com/profile/ProfileHeader'
import {
  mockedNavigationStore,
  mockedProfileStore,
  mockedShellStore,
} from '../../../../__mocks__/state-mock'

describe('ProfileHeader', () => {
  const mockedProps = {
    view: mockedProfileStore,
    onRefreshAll: jest.fn(),
  }
  afterAll(() => {
    jest.clearAllMocks()
    cleanup()
  })

  it('renders ErrorMessage on error', async () => {
    const {findByTestId} = render(
      <ProfileHeader
        {...{
          view: {
            ...mockedProfileStore,
            hasError: true,
          } as ProfileViewModel,
          onRefreshAll: jest.fn(),
        }}
      />,
    )

    const profileHeaderHasError = await findByTestId('profileHeaderHasError')
    expect(profileHeaderHasError).toBeTruthy()
  })

  it('presses and opens edit profile', async () => {
    const {findByTestId} = render(<ProfileHeader {...mockedProps} />)

    const profileHeaderEditProfileButton = await findByTestId(
      'profileHeaderEditProfileButton',
    )
    expect(profileHeaderEditProfileButton).toBeTruthy()
    fireEvent.press(profileHeaderEditProfileButton)

    expect(mockedShellStore.openModal).toHaveBeenCalled()
  })

  it('presses and opens followers page', async () => {
    const {findByTestId} = render(<ProfileHeader {...mockedProps} />)

    const profileHeaderFollowersButton = await findByTestId(
      'profileHeaderFollowersButton',
    )
    expect(profileHeaderFollowersButton).toBeTruthy()
    fireEvent.press(profileHeaderFollowersButton)

    expect(mockedNavigationStore.navigate).toHaveBeenCalledWith(
      '/profile/testhandle/followers',
    )
  })

  // TODO - this will only pass if the profile has an avatar image set
  // it('presses and opens avatar modal', async () => {
  //   const {findByTestId} = render(<ProfileHeader {...mockedProps} />)

  //   const profileHeaderAviButton = await findByTestId('profileHeaderAviButton')
  //   expect(profileHeaderAviButton).toBeTruthy()
  //   fireEvent.press(profileHeaderAviButton)

  //   expect(mockedShellStore.openLightbox).toHaveBeenCalled()
  // })

  it('presses and opens follows page', async () => {
    const {findByTestId} = render(<ProfileHeader {...mockedProps} />)

    const profileHeaderFollowsButton = await findByTestId(
      'profileHeaderFollowsButton',
    )
    expect(profileHeaderFollowsButton).toBeTruthy()
    fireEvent.press(profileHeaderFollowsButton)

    expect(mockedNavigationStore.navigate).toHaveBeenCalledWith(
      '/profile/testhandle/follows',
    )
  })

  it('toggles following', async () => {
    const {findByTestId} = render(
      <ProfileHeader
        {...{
          view: {
            ...mockedProfileStore,
            did: 'test did 2',
          } as ProfileViewModel,
          onRefreshAll: jest.fn(),
        }}
      />,
    )

    const profileHeaderToggleFollowButton = await findByTestId(
      'profileHeaderToggleFollowButton',
    )
    expect(profileHeaderToggleFollowButton).toBeTruthy()
    fireEvent.press(profileHeaderToggleFollowButton)

    expect(mockedProps.view.toggleFollowing).toHaveBeenCalled()
  })
})