From e9ba0ac8550633c8bee134037f15b00ca93de26d Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Wed, 1 Mar 2017 13:19:14 +0200 Subject: [PATCH] Test and styleguide related mock data separated from test-helpers --- .../ListingCard/ListingCard.test.js | 3 ++- .../ListingCardSmall/ListingCardSmall.test.js | 3 ++- src/util/test-data.js | 25 +++++++++++++++++++ src/util/test-helpers.js | 25 ------------------- 4 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 src/util/test-data.js diff --git a/src/components/ListingCard/ListingCard.test.js b/src/components/ListingCard/ListingCard.test.js index 6e3ba0ef..73057076 100644 --- a/src/components/ListingCard/ListingCard.test.js +++ b/src/components/ListingCard/ListingCard.test.js @@ -1,5 +1,6 @@ import React from 'react'; -import { renderShallow, createUser, createListing } from '../../util/test-helpers'; +import { renderShallow } from '../../util/test-helpers'; +import { createUser, createListing } from '../../util/test-data'; import ListingCard from './ListingCard'; describe('ListingCard', () => { diff --git a/src/components/ListingCardSmall/ListingCardSmall.test.js b/src/components/ListingCardSmall/ListingCardSmall.test.js index 36e053a1..b729556e 100644 --- a/src/components/ListingCardSmall/ListingCardSmall.test.js +++ b/src/components/ListingCardSmall/ListingCardSmall.test.js @@ -1,5 +1,6 @@ import React from 'react'; -import { renderShallow, createUser, createListing } from '../../util/test-helpers'; +import { renderShallow } from '../../util/test-helpers'; +import { createUser, createListing } from '../../util/test-data'; import ListingCardSmall from './ListingCardSmall'; describe('ListingCardSmall', () => { diff --git a/src/util/test-data.js b/src/util/test-data.js new file mode 100644 index 00000000..2c2575c8 --- /dev/null +++ b/src/util/test-data.js @@ -0,0 +1,25 @@ +import { types } from 'sharetribe-sdk'; + +const { UUID, LatLng } = types; + +// Create a user that conforms to the util/propTypes user schema +export const createUser = id => ({ + id: new UUID(id), + type: 'user', + attributes: { + email: `${id}@example.com`, + profile: { firstName: `${id} first name`, lastName: `${id} last name`, slug: `${id}-slug` }, + }, +}); + +// Create a user that conforms to the util/propTypes listing schema +export const createListing = id => ({ + id: new UUID(id), + type: 'listing', + attributes: { + title: `${id} title`, + description: `${id} description`, + address: `${id} address`, + geolocation: new LatLng(40, 60), + }, +}); diff --git a/src/util/test-helpers.js b/src/util/test-helpers.js index c04a9b02..e2021dac 100644 --- a/src/util/test-helpers.js +++ b/src/util/test-helpers.js @@ -5,11 +5,8 @@ import toJson from 'enzyme-to-json'; import { IntlProvider } from 'react-intl'; import { BrowserRouter } from 'react-router-dom'; import { Provider } from 'react-redux'; -import { types } from 'sharetribe-sdk'; import configureStore from '../store'; -const { UUID, LatLng } = types; - // Provide all the context for components that connect to the Redux // store, i18n, router, etc. export const TestProvider = props => { @@ -49,25 +46,3 @@ export const renderDeep = component => { ); return comp.toJSON(); }; - -// Create a user that conforms to the util/propTypes user schema -export const createUser = id => ({ - id: new UUID(id), - type: 'user', - attributes: { - email: '${id}@example.com', - profile: { firstName: `${id} first name`, lastName: `${id} last name`, slug: `${id}-slug` }, - }, -}); - -// Create a user that conforms to the util/propTypes listing schema -export const createListing = id => ({ - id: new UUID(id), - type: 'listing', - attributes: { - title: `${id} title`, - description: `${id} description`, - address: `${id} address`, - geolocation: new LatLng(40, 60), - }, -});