about summary refs log tree commit diff
path: root/__tests__/state/models/shell-ui.test.ts
blob: 8324609a1489597c96e570b10d459c3c4edc9c51 (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
import {
  ConfirmModal,
  ImageLightbox,
  ShellUiModel,
} from './../../../src/state/models/shell-ui'

describe('ShellUiModel', () => {
  let model: ShellUiModel

  beforeEach(() => {
    model = new ShellUiModel()
  })

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

  it('should call the openModal & closeModal method', () => {
    model.openModal(ConfirmModal)
    expect(model.isModalActive).toEqual(true)
    expect(model.activeModal).toEqual(ConfirmModal)

    model.closeModal()
    expect(model.isModalActive).toEqual(false)
    expect(model.activeModal).toBeUndefined()
  })

  it('should call the openLightbox & closeLightbox method', () => {
    model.openLightbox(new ImageLightbox('uri'))
    expect(model.isLightboxActive).toEqual(true)
    expect(model.activeLightbox).toEqual(new ImageLightbox('uri'))

    model.closeLightbox()
    expect(model.isLightboxActive).toEqual(false)
    expect(model.activeLightbox).toBeUndefined()
  })

  it('should call the openComposer & closeComposer method', () => {
    const composer = {
      replyTo: {
        uri: 'uri',
        cid: 'cid',
        text: 'text',
        author: {
          handle: 'handle',
          displayName: 'name',
        },
      },
      onPost: jest.fn(),
    }
    model.openComposer(composer)
    expect(model.isComposerActive).toEqual(true)
    expect(model.composerOpts).toEqual(composer)

    model.closeComposer()
    expect(model.isComposerActive).toEqual(false)
    expect(model.composerOpts).toBeUndefined()
  })
})