bigbuffet-rw/app/soapbox/queries/__tests__/carousels.test.ts

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-08-09 09:00:44 -07:00
import { __stub } from 'soapbox/api';
import { renderHook, waitFor } from 'soapbox/jest/test-helpers';
2022-08-08 12:53:21 -07:00
import { useCarouselAvatars } from '../carousels';
2022-08-08 12:53:21 -07:00
describe('useCarouselAvatars', () => {
2022-08-09 09:00:44 -07:00
describe('with a successful query', () => {
2022-08-08 12:53:21 -07:00
beforeEach(() => {
2022-08-09 09:00:44 -07:00
__stub((mock) => {
mock.onGet('/api/v1/truth/carousels/avatars')
.reply(200, [
{ account_id: '1', acct: 'a', account_avatar: 'https://example.com/some.jpg' },
{ account_id: '2', acct: 'b', account_avatar: 'https://example.com/some.jpg' },
{ account_id: '3', acct: 'c', account_avatar: 'https://example.com/some.jpg' },
{ account_id: '4', acct: 'd', account_avatar: 'https://example.com/some.jpg' },
]);
});
2022-08-08 12:53:21 -07:00
});
it('is successful', async() => {
2022-08-09 09:00:44 -07:00
const { result } = renderHook(() => useCarouselAvatars());
2022-08-08 12:53:21 -07:00
await waitFor(() => expect(result.current.isFetching).toBe(false));
expect(result.current.data?.length).toBe(4);
});
});
2022-08-09 09:00:44 -07:00
describe('with an unsuccessful query', () => {
2022-08-08 12:53:21 -07:00
beforeEach(() => {
2022-08-09 09:00:44 -07:00
__stub((mock) => {
mock.onGet('/api/v1/truth/carousels/avatars').networkError();
});
2022-08-08 12:53:21 -07:00
});
it('is successful', async() => {
2022-08-09 09:00:44 -07:00
const { result } = renderHook(() => useCarouselAvatars());
2022-08-08 12:53:21 -07:00
await waitFor(() => expect(result.current.isFetching).toBe(false));
expect(result.current.error).toBeDefined();
});
});
});