about summary refs log tree commit diff
path: root/__tests__/view/com/composer/SelectedPhoto.test.tsx
blob: 26059ae303d8b849a630dfbcac8e22046807663e (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
import React from 'react'
import {SelectedPhoto} from '../../../../src/view/com/composer/SelectedPhoto'
import {cleanup, fireEvent, render} from '../../../../jest/test-utils'

describe('SelectedPhoto', () => {
  const mockedProps = {
    selectedPhotos: ['mock-uri', 'mock-uri-2'],
    onSelectPhotos: jest.fn(),
  }

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

  it('has no photos to render', () => {
    const {queryByTestId} = render(
      <SelectedPhoto selectedPhotos={[]} onSelectPhotos={jest.fn()} />,
    )
    const selectedPhotosView = queryByTestId('selectedPhotosView')
    expect(selectedPhotosView).toBeNull()

    const selectedPhotoImage = queryByTestId('selectedPhotoImage')
    expect(selectedPhotoImage).toBeNull()
  })

  it('has 1 photos to render', async () => {
    const {findByTestId} = render(
      <SelectedPhoto
        selectedPhotos={['mock-uri']}
        onSelectPhotos={jest.fn()}
      />,
    )
    const selectedPhotosView = await findByTestId('selectedPhotosView')
    expect(selectedPhotosView).toBeTruthy()

    const selectedPhotoImage = await findByTestId('selectedPhotoImage')
    expect(selectedPhotoImage).toBeTruthy()
    // @ts-expect-error
    expect(selectedPhotoImage).toHaveStyle({width: 250})
  })

  it('has 2 photos to render', async () => {
    const {findAllByTestId} = render(<SelectedPhoto {...mockedProps} />)
    const selectedPhotoImage = await findAllByTestId('selectedPhotoImage')
    expect(selectedPhotoImage[0]).toBeTruthy()
    // @ts-expect-error
    expect(selectedPhotoImage[0]).toHaveStyle({width: 175})
  })

  it('has 3 photos to render', async () => {
    const {findAllByTestId} = render(
      <SelectedPhoto
        selectedPhotos={['mock-uri', 'mock-uri-2', 'mock-uri-3']}
        onSelectPhotos={jest.fn()}
      />,
    )
    const selectedPhotoImage = await findAllByTestId('selectedPhotoImage')
    expect(selectedPhotoImage[0]).toBeTruthy()
    // @ts-expect-error
    expect(selectedPhotoImage[0]).toHaveStyle({width: 85})
  })

  it('removes a photo', async () => {
    const {findAllByTestId} = render(<SelectedPhoto {...mockedProps} />)
    const removePhotoButton = await findAllByTestId('removePhotoButton')
    fireEvent.press(removePhotoButton[0])
    expect(mockedProps.onSelectPhotos).toHaveBeenCalledWith(['mock-uri-2'])
  })
})