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