File size: 1,195 Bytes
cf0f72e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React from 'react'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
import { AddMovie } from '../AddMovie'

describe('components/AddMovie', () => {
  let component
  let instance
  let mutate
  let navigation

  beforeEach(() => {
    mutate = jest.fn()
    navigation = {
      navigate: jest.fn()
    }

    component = shallow(<AddMovie mutate={mutate} navigation={navigation} />)

    instance = component.instance()
  })

  it('renders AddMovie', () => {
    expect(toJson(component)).toMatchSnapshot()
  })

  describe('#insertMovie', () => {
    it('should call mutate with correct variables', async () => {
      try {
        await instance.insertMovie()

        expect(mutate).toHaveBeenCalledWith({
          variables: {
            input: {
              imdbId: '',
              rating: 0,
              userId: 2
            }
          }
        })
      } catch (e) {
        throw new Error(e)
      }
    })

    it('should navigate back to Feed', async () => {
      try {
        await instance.insertMovie()

        expect(navigation.navigate).toHaveBeenCalledWith('Feed')
      } catch (e) {
        throw new Error(e)
      }
    })
  })
})