about summary refs log tree commit diff
path: root/__tests__/state/models/root-store.test.ts
blob: ccaa6f83f763c0bbfa81097a1f39ba33e421d641 (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
import {RootStoreModel} from '../../../src/state/models/root-store'
import {setupState} from '../../../src/state'

describe('rootStore', () => {
  let rootStore: RootStoreModel

  beforeAll(() => {
    jest.useFakeTimers()
  })

  beforeEach(async () => {
    rootStore = await setupState()
  })

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

  it('resolveName() handles inputs correctly', () => {
    const spyMethod = jest
      .spyOn(rootStore.api.com.atproto.handle, 'resolve')
      .mockResolvedValue({success: true, headers: {}, data: {did: 'testdid'}})

    rootStore.resolveName('teststring')
    expect(spyMethod).toHaveBeenCalledWith({handle: 'teststring'})

    expect(rootStore.resolveName('')).rejects.toThrow('Invalid handle: ""')

    expect(rootStore.resolveName('did:123')).resolves.toReturnWith('did:123')
  })

  it('should call the clearAll() resets state correctly', () => {
    rootStore.clearAll()

    expect(rootStore.session.data).toEqual(null)
    expect(rootStore.nav.tabs).toEqual([
      {
        fixedTabPurpose: 0,
        history: [
          {
            id: expect.anything(),
            ts: expect.anything(),
            url: '/',
          },
        ],
        id: expect.anything(),
        index: 0,
        isNewTab: false,
      },
      {
        fixedTabPurpose: 1,
        history: [
          {
            id: expect.anything(),
            ts: expect.anything(),
            url: '/notifications',
          },
        ],
        id: expect.anything(),
        index: 0,
        isNewTab: false,
      },
    ])
    expect(rootStore.nav.tabIndex).toEqual(0)
    expect(rootStore.me.did).toEqual('')
    expect(rootStore.me.handle).toEqual('')
    expect(rootStore.me.displayName).toEqual('')
    expect(rootStore.me.description).toEqual('')
    expect(rootStore.me.avatar).toEqual('')
    expect(rootStore.me.notificationCount).toEqual(0)
    expect(rootStore.me.memberships).toBeUndefined()
  })
})