diff --git a/app/soapbox/api/hooks/groups/__tests__/usePendingGroups.test.ts b/app/soapbox/api/hooks/groups/__tests__/usePendingGroups.test.ts new file mode 100644 index 000000000..c30516962 --- /dev/null +++ b/app/soapbox/api/hooks/groups/__tests__/usePendingGroups.test.ts @@ -0,0 +1,47 @@ +import { __stub } from 'soapbox/api'; +import { buildGroup } from 'soapbox/jest/factory'; +import { renderHook, waitFor } from 'soapbox/jest/test-helpers'; +import { normalizeInstance } from 'soapbox/normalizers'; + +import { usePendingGroups } from '../usePendingGroups'; + +const group = buildGroup({ id: '1', display_name: 'soapbox' }); +const store = { + instance: normalizeInstance({ + version: '3.4.1 (compatible; TruthSocial 1.0.0+unreleased)', + }), +}; + +describe('usePendingGroups hook', () => { + describe('with a successful request', () => { + beforeEach(() => { + __stub((mock) => { + mock.onGet('/api/v1/groups').reply(200, [group]); + }); + }); + + it('is successful', async () => { + const { result } = renderHook(usePendingGroups, undefined, store); + + await waitFor(() => expect(result.current.isFetching).toBe(false)); + + expect(result.current.groups).toHaveLength(1); + }); + }); + + describe('with an unsuccessful query', () => { + beforeEach(() => { + __stub((mock) => { + mock.onGet('/api/v1/groups').networkError(); + }); + }); + + it('is has error state', async() => { + const { result } = renderHook(usePendingGroups, undefined, store); + + await waitFor(() => expect(result.current.isFetching).toBe(false)); + + expect(result.current.groups).toHaveLength(0); + }); + }); +}); \ No newline at end of file diff --git a/app/soapbox/api/hooks/groups/usePendingGroups.ts b/app/soapbox/api/hooks/groups/usePendingGroups.ts index b8cfb0789..f7b6b4cef 100644 --- a/app/soapbox/api/hooks/groups/usePendingGroups.ts +++ b/app/soapbox/api/hooks/groups/usePendingGroups.ts @@ -17,7 +17,7 @@ function usePendingGroups() { }), { schema: groupSchema, - enabled: !!account && features.groupsPending, + enabled: features.groupsPending, }, );