diff options
Diffstat (limited to '__tests__/state/models/root-store.test.ts')
-rw-r--r-- | __tests__/state/models/root-store.test.ts | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/__tests__/state/models/root-store.test.ts b/__tests__/state/models/root-store.test.ts new file mode 100644 index 000000000..ccaa6f83f --- /dev/null +++ b/__tests__/state/models/root-store.test.ts @@ -0,0 +1,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() + }) +}) |