About page: restore functionality, fix tests

merge-requests/71/head
Alex Gleason 4 years ago
parent 1a07c3bac5
commit d3b31c8bcf
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -17,7 +17,7 @@ describe('fetchAboutPage()', () => {
const expectedActions = [
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'index' },
{ type: FETCH_ABOUT_PAGE_SUCCESS, slug: 'index' },
{ type: FETCH_ABOUT_PAGE_SUCCESS, slug: 'index', html: '<h1>Hello world</h1>' },
];
const store = mockStore(ImmutableMap());
@ -29,11 +29,11 @@ describe('fetchAboutPage()', () => {
it('creates the expected actions on failure', () => {
const expectedActions = [
{ type: FETCH_ABOUT_PAGE_REQUEST, slug: 'asdf' },
{ type: FETCH_ABOUT_PAGE_FAIL, slug: 'asdf' },
{ type: FETCH_ABOUT_PAGE_FAIL, slug: 'asdf', error: new Error('Request failed with status code 404') },
];
const store = mockStore(ImmutableMap());
return store.dispatch(fetchAboutPage('asdf')).then(() => {
return store.dispatch(fetchAboutPage('asdf')).catch(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});

@ -7,10 +7,12 @@ export const FETCH_ABOUT_PAGE_FAIL = 'FETCH_ABOUT_PAGE_FAIL';
export function fetchAboutPage(slug = 'index') {
return (dispatch, getState) => {
dispatch({ type: FETCH_ABOUT_PAGE_REQUEST, slug });
return api(getState).get(`/instance/about/${slug}.html`).then(() => {
dispatch({ type: FETCH_ABOUT_PAGE_SUCCESS, slug });
return api(getState).get(`/instance/about/${slug}.html`).then(response => {
dispatch({ type: FETCH_ABOUT_PAGE_SUCCESS, slug, html: response.data });
return response.data;
}).catch(error => {
dispatch({ type: FETCH_ABOUT_PAGE_FAIL, slug });
dispatch({ type: FETCH_ABOUT_PAGE_FAIL, slug, error });
throw error;
});
};
}

@ -12,8 +12,8 @@ class AboutPage extends ImmutablePureComponent {
loadPageHtml = () => {
const { dispatch, match } = this.props;
const { slug } = match.params;
dispatch(fetchAboutPage(slug)).then(response => {
this.setState({ pageHtml: response.data });
dispatch(fetchAboutPage(slug)).then(html => {
this.setState({ pageHtml: html });
}).catch(error => {
// TODO: Better error handling. 404 page?
this.setState({ pageHtml: '<h1>Page not found</h1>' });

Loading…
Cancel
Save