Test: Refactor helper functions
This commit is contained in:
parent
f147940d22
commit
49589e1e7c
6 changed files with 24 additions and 21 deletions
|
@ -1,10 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ColumnBackButton from '../column_back_button';
|
import ColumnBackButton from '../column_back_button';
|
||||||
import { createComponentWithIntl } from 'soapbox/test_helpers';
|
import { createComponent } from 'soapbox/test_helpers';
|
||||||
|
|
||||||
describe('<ColumnBackButton />', () => {
|
describe('<ColumnBackButton />', () => {
|
||||||
it('renders correctly', () => {
|
it('renders correctly', () => {
|
||||||
const component = createComponentWithIntl(<ColumnBackButton />);
|
const component = createComponent(<ColumnBackButton />);
|
||||||
const tree = component.toJSON();
|
const tree = component.toJSON();
|
||||||
expect(tree).toMatchSnapshot();
|
expect(tree).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ColumnBackButtonSlim from '../column_back_button_slim';
|
import ColumnBackButtonSlim from '../column_back_button_slim';
|
||||||
import { createComponentWithIntl } from 'soapbox/test_helpers';
|
import { createComponent } from 'soapbox/test_helpers';
|
||||||
|
|
||||||
describe('<ColumnBackButtonSlim />', () => {
|
describe('<ColumnBackButtonSlim />', () => {
|
||||||
it('renders correctly', () => {
|
it('renders correctly', () => {
|
||||||
const component = createComponentWithIntl(<ColumnBackButtonSlim />);
|
const component = createComponent(<ColumnBackButtonSlim />);
|
||||||
const tree = component.toJSON();
|
const tree = component.toJSON();
|
||||||
expect(tree).toMatchSnapshot();
|
expect(tree).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ColumnHeader from '../column_header';
|
import ColumnHeader from '../column_header';
|
||||||
import { createComponentWithIntl } from 'soapbox/test_helpers';
|
import { createComponent } from 'soapbox/test_helpers';
|
||||||
|
|
||||||
describe('<ColumnHeader />', () => {
|
describe('<ColumnHeader />', () => {
|
||||||
it('renders correctly with minimal props', () => {
|
it('renders correctly with minimal props', () => {
|
||||||
const component = createComponentWithIntl(<ColumnHeader />);
|
const component = createComponent(<ColumnHeader />);
|
||||||
const tree = component.toJSON();
|
const tree = component.toJSON();
|
||||||
expect(tree).toMatchSnapshot();
|
expect(tree).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import TimelineQueueButtonHeader from '../timeline_queue_button_header';
|
import TimelineQueueButtonHeader from '../timeline_queue_button_header';
|
||||||
import { createComponentWithIntl } from 'soapbox/test_helpers';
|
import { createComponent } from 'soapbox/test_helpers';
|
||||||
import { defineMessages } from 'react-intl';
|
import { defineMessages } from 'react-intl';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
|
@ -9,7 +9,7 @@ const messages = defineMessages({
|
||||||
|
|
||||||
describe('<TimelineQueueButtonHeader />', () => {
|
describe('<TimelineQueueButtonHeader />', () => {
|
||||||
it('renders correctly', () => {
|
it('renders correctly', () => {
|
||||||
expect(createComponentWithIntl(
|
expect(createComponent(
|
||||||
<TimelineQueueButtonHeader
|
<TimelineQueueButtonHeader
|
||||||
key='timeline-queue-button-header'
|
key='timeline-queue-button-header'
|
||||||
onClick={() => {}} // eslint-disable-line react/jsx-no-bind
|
onClick={() => {}} // eslint-disable-line react/jsx-no-bind
|
||||||
|
@ -18,7 +18,7 @@ describe('<TimelineQueueButtonHeader />', () => {
|
||||||
/>
|
/>
|
||||||
).toJSON()).toMatchSnapshot();
|
).toJSON()).toMatchSnapshot();
|
||||||
|
|
||||||
expect(createComponentWithIntl(
|
expect(createComponent(
|
||||||
<TimelineQueueButtonHeader
|
<TimelineQueueButtonHeader
|
||||||
key='timeline-queue-button-header'
|
key='timeline-queue-button-header'
|
||||||
onClick={() => {}} // eslint-disable-line react/jsx-no-bind
|
onClick={() => {}} // eslint-disable-line react/jsx-no-bind
|
||||||
|
@ -27,7 +27,7 @@ describe('<TimelineQueueButtonHeader />', () => {
|
||||||
/>
|
/>
|
||||||
).toJSON()).toMatchSnapshot();
|
).toJSON()).toMatchSnapshot();
|
||||||
|
|
||||||
expect(createComponentWithIntl(
|
expect(createComponent(
|
||||||
<TimelineQueueButtonHeader
|
<TimelineQueueButtonHeader
|
||||||
key='timeline-queue-button-header'
|
key='timeline-queue-button-header'
|
||||||
onClick={() => {}} // eslint-disable-line react/jsx-no-bind
|
onClick={() => {}} // eslint-disable-line react/jsx-no-bind
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import CaptchaField, { NativeCaptchaField } from '../captcha';
|
import CaptchaField, { NativeCaptchaField } from '../captcha';
|
||||||
import renderer from 'react-test-renderer';
|
import renderer from 'react-test-renderer';
|
||||||
import { createComponentWithStore } from 'soapbox/test_helpers';
|
import { createComponent } from 'soapbox/test_helpers';
|
||||||
import { Map as ImmutableMap } from 'immutable';
|
import { Map as ImmutableMap } from 'immutable';
|
||||||
|
|
||||||
describe('<CaptchaField />', () => {
|
describe('<CaptchaField />', () => {
|
||||||
it('renders null by default', () => {
|
it('renders null by default', () => {
|
||||||
expect(createComponentWithStore(
|
expect(createComponent(
|
||||||
<CaptchaField />
|
<CaptchaField />
|
||||||
).toJSON()).toMatchSnapshot();
|
).toJSON()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@ import thunk from 'redux-thunk';
|
||||||
import renderer from 'react-test-renderer';
|
import renderer from 'react-test-renderer';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
import { IntlProvider } from 'react-intl';
|
import { IntlProvider } from 'react-intl';
|
||||||
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import configureMockStore from 'redux-mock-store';
|
import configureMockStore from 'redux-mock-store';
|
||||||
import { Map as ImmutableMap } from 'immutable';
|
import { Map as ImmutableMap } from 'immutable';
|
||||||
|
|
||||||
|
@ -13,13 +14,15 @@ import { Map as ImmutableMap } from 'immutable';
|
||||||
const middlewares = [thunk];
|
const middlewares = [thunk];
|
||||||
export const mockStore = configureMockStore(middlewares);
|
export const mockStore = configureMockStore(middlewares);
|
||||||
|
|
||||||
// Test Redux connected components
|
// Create test component with i18n and Redux store, etc
|
||||||
export const createComponentWithStore = (children, props = { store: mockStore(ImmutableMap()) }) => {
|
export const createComponent = (children, props = { locale: 'en', store: mockStore(ImmutableMap()) }) => {
|
||||||
return renderer.create(<Provider {...props}>{children}</Provider>);
|
return renderer.create(
|
||||||
};
|
<Provider store={props.store}>
|
||||||
|
<IntlProvider locale={props.locale}>
|
||||||
// Testing i18n components
|
<BrowserRouter>
|
||||||
// https://formatjs.io/docs/react-intl/testing/#helper-function-2
|
{children}
|
||||||
export const createComponentWithIntl = (children, props = { locale: 'en' }) => {
|
</BrowserRouter>
|
||||||
return renderer.create(<IntlProvider {...props}>{children}</IntlProvider>);
|
</IntlProvider>
|
||||||
|
</Provider>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue