bigbuffet-rw/app/soapbox/actions/__tests__/about.test.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-01-10 14:01:24 -08:00
import MockAdapter from 'axios-mock-adapter';
import { Map as ImmutableMap } from 'immutable';
2022-01-10 14:01:24 -08:00
import { staticClient } from 'soapbox/api';
import { mockStore } from 'soapbox/jest/test-helpers';
import {
FETCH_ABOUT_PAGE_REQUEST,
FETCH_ABOUT_PAGE_SUCCESS,
2020-06-09 15:22:35 -07:00
FETCH_ABOUT_PAGE_FAIL,
fetchAboutPage,
} from '../about';
2020-06-09 15:05:28 -07:00
describe('fetchAboutPage()', () => {
2020-06-09 15:22:35 -07:00
it('creates the expected actions on success', () => {
2021-09-05 12:07:42 -07:00
const mock = new MockAdapter(staticClient);
mock.onGet('/instance/about/index.html')
.reply(200, '<h1>Hello world</h1>');
2020-06-09 15:05:28 -07:00
const expectedActions = [
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' },
{ type: FETCH_ABOUT_PAGE_SUCCESS, slug: 'index', html: '<h1>Hello world</h1>' },
];
const store = mockStore(ImmutableMap());
return store.dispatch(fetchAboutPage()).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
2020-06-09 15:22:35 -07:00
it('creates the expected actions on failure', () => {
const expectedActions = [
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'asdf' },
{ type: FETCH_ABOUT_PAGE_FAIL, slug: 'asdf', error: new Error('Request failed with status code 404') },
2020-06-09 15:22:35 -07:00
];
const store = mockStore(ImmutableMap());
return store.dispatch(fetchAboutPage('asdf')).catch(() => {
2020-06-09 15:22:35 -07:00
expect(store.getActions()).toEqual(expectedActions);
});
});
});