From b711251978556e650dd8f9356b0a8eb91c342e71 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 30 Nov 2017 11:03:00 +0200 Subject: [PATCH 1/4] Use .env files for dev and test setup --- .env.development | 2 ++ .env.test | 3 +++ package.json | 6 +++--- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .env.development create mode 100644 .env.test diff --git a/.env.development b/.env.development new file mode 100644 index 00000000..cff1ca7b --- /dev/null +++ b/.env.development @@ -0,0 +1,2 @@ +NODE_ENV=development +REACT_APP_ENV=development diff --git a/.env.test b/.env.test new file mode 100644 index 00000000..d8e17a78 --- /dev/null +++ b/.env.test @@ -0,0 +1,3 @@ +NODE_ENV=test +REACT_APP_ENV=test +REACT_APP_SHARETRIBE_MARKETPLACE_CURRENCY=USD diff --git a/package.json b/package.json index e68e3107..644ffd30 100644 --- a/package.json +++ b/package.json @@ -55,12 +55,12 @@ }, "scripts": { "clean": "rm -rf build/*", - "dev": "REACT_APP_ENV=development sharetribe-scripts start", + "dev": "sharetribe-scripts start", "build": "sharetribe-scripts build", "format": "prettier --write '**/*.{js,css}'", "format-ci": "prettier --list-different '**/*.{js,css}'", - "test": "export REACT_APP_SHARETRIBE_MARKETPLACE_CURRENCY=USD&&sharetribe-scripts test --env=jsdom", - "test-ci": "export REACT_APP_SHARETRIBE_MARKETPLACE_CURRENCY=USD&&sharetribe-scripts test --env=jsdom --runInBand", + "test": "sharetribe-scripts test --env=jsdom", + "test-ci": "sharetribe-scripts test --env=jsdom --runInBand", "eject": "sharetribe-scripts eject", "start": "node server/index.js", "dev-server": "export REACT_APP_ENV=development REACT_APP_CANONICAL_ROOT_URL=http://localhost:4000&&yarn run build&&nodemon --watch server server/index.js", From 81a2a2c50b90ecea292c141c81265400a3d1231d Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 30 Nov 2017 11:04:10 +0200 Subject: [PATCH 2/4] Use message IDs as translations in tests --- src/app.js | 17 +++++++++++++++-- src/util/test-helpers.js | 9 +++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/app.js b/src/app.js index 277ac632..24d81e86 100644 --- a/src/app.js +++ b/src/app.js @@ -4,6 +4,7 @@ import ReactDOMServer from 'react-dom/server'; import Helmet from 'react-helmet'; import { BrowserRouter, StaticRouter } from 'react-router-dom'; import { Provider } from 'react-redux'; +import { mapValues } from 'lodash'; import moment from 'moment'; import { IntlProvider, addLocaleData } from 'react-intl'; import configureStore from './store'; @@ -18,7 +19,19 @@ import config from './config'; import localeData from 'react-intl/locale-data/en'; import messages from './translations/en.json'; +const isTestEnv = process.env.NODE_ENV === 'test'; + +// Locale should not affect the tests. We ensure this by providing +// messages with the key as the value of each message. +const testMessages = mapValues(messages, (val, key) => key); +const localeMessages = isTestEnv ? testMessages : messages; + const setupLocale = () => { + if (isTestEnv) { + // Don't change the locale in tests + return; + } + // Add the translation messages addLocaleData([...localeData]); @@ -31,7 +44,7 @@ export const ClientApp = props => { const { store } = props; setupLocale(); return ( - + @@ -49,7 +62,7 @@ export const ServerApp = props => { const { url, context, store } = props; setupLocale(); return ( - + diff --git a/src/util/test-helpers.js b/src/util/test-helpers.js index e63c4e6c..f544cbda 100644 --- a/src/util/test-helpers.js +++ b/src/util/test-helpers.js @@ -1,5 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; +import { mapValues } from 'lodash'; import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import { IntlProvider, addLocaleData } from 'react-intl'; @@ -7,7 +8,11 @@ import en from 'react-intl/locale-data/en'; import { BrowserRouter } from 'react-router-dom'; import { Provider } from 'react-redux'; import configureStore from '../store'; -import localeData from '../translations/en.json'; +import messages from '../translations/en.json'; + +// Locale should not affect the tests. We ensure this by providing +// messages with the key as the value of each message. +const testMessages = mapValues(messages, (val, key) => key); // Provide all the context for components that connect to the Redux // store, i18n, router, etc. @@ -15,7 +20,7 @@ export const TestProvider = props => { const store = configureStore(); addLocaleData([...en]); return ( - + {props.children} From ec1a834b204e4cf1712c906caf20a20dda490876 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 30 Nov 2017 11:07:29 +0200 Subject: [PATCH 3/4] Update title test with message IDs in translations --- src/app.test.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app.test.js b/src/app.test.js index 827e72f1..728d5ca8 100644 --- a/src/app.test.js +++ b/src/app.test.js @@ -34,16 +34,16 @@ describe('Application', () => { it('server renders pages that do not require authentication', () => { const urlTitles = { - '/': 'Book saunas everywhere', - '/s': 'Search results for map search', - '/l/listing-title-slug/1234': 'Loading listing…', - '/l/1234': 'Loading listing…', - '/u/1234': ' | Saunatime', - '/login': 'Log in', - '/signup': 'Sign up', - '/recover-password': 'Request a new password', - '/this-url-should-not-be-found': 'Page not found', - '/reset-password?t=token&e=email': 'Reset password', + '/': 'LandingPage.schemaTitle', + '/s': 'SearchPage.schemaTitle', + '/l/listing-title-slug/1234': 'ListingPage.loadingListingTitle', + '/l/1234': 'ListingPage.loadingListingTitle', + '/u/1234': 'ProfilePage.schemaTitle', + '/login': 'AuthenticationPage.schemaTitleLogin', + '/signup': 'AuthenticationPage.schemaTitleSignup', + '/recover-password': 'PasswordRecoveryPage.title', + '/this-url-should-not-be-found': 'NotFoundPage.title', + '/reset-password?t=token&e=email': 'PasswordResetPage.title', }; forEach(urlTitles, (title, url) => { const context = {}; From 2d462771480d3c4a0f80e257ddfef7901c0f4cf1 Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Thu, 30 Nov 2017 11:12:05 +0200 Subject: [PATCH 4/4] Update snapshots with message IDs as translations --- .../BookingBreakdown.test.js.snap | 80 +++++-------------- .../__snapshots__/DateInputField.test.js.snap | 8 +- .../DateRangeInputField.test.js.snap | 4 +- .../__snapshots__/SectionHero.test.js.snap | 8 +- .../__snapshots__/TopbarDesktop.test.js.snap | 14 ++-- .../EditListingDescriptionForm.test.js.snap | 8 +- .../EditListingPricingForm.test.js.snap | 4 +- .../__snapshots__/LoginForm.test.js.snap | 23 ++---- .../__snapshots__/SignupForm.test.js.snap | 31 +++---- 9 files changed, 59 insertions(+), 121 deletions(-) diff --git a/src/components/BookingBreakdown/__snapshots__/BookingBreakdown.test.js.snap b/src/components/BookingBreakdown/__snapshots__/BookingBreakdown.test.js.snap index 5ad0b41e..2af3179a 100644 --- a/src/components/BookingBreakdown/__snapshots__/BookingBreakdown.test.js.snap +++ b/src/components/BookingBreakdown/__snapshots__/BookingBreakdown.test.js.snap @@ -11,7 +11,7 @@ exports[`BookingBreakdown customer transaction data matches snapshot 1`] = ` className={undefined} > - Price per night + BookingBreakdown.pricePerNight - - 2017-04-14 - - – - - 2017-04-16 - + BookingBreakdown.bookingPeriod @@ -62,7 +52,7 @@ exports[`BookingBreakdown customer transaction data matches snapshot 1`] = ` className={undefined} > - Total price + BookingBreakdown.total
- Price per night + BookingBreakdown.pricePerNight - - 2017-04-14 - - – - - 2017-04-16 - + BookingBreakdown.bookingPeriod @@ -136,7 +116,7 @@ exports[`BookingBreakdown pretransaction data matches snapshot 1`] = ` className={undefined} > - Total price + BookingBreakdown.total
- Price per night + BookingBreakdown.pricePerNight - - 2017-04-14 - - – - - 2017-04-16 - + BookingBreakdown.bookingPeriod @@ -207,7 +177,7 @@ exports[`BookingBreakdown provider canceled transaction data matches snapshot 1` className={undefined} > - Subtotal + BookingBreakdown.subTotal - Refund + BookingBreakdown.refund - Total price + BookingBreakdown.providerTotalCanceled
- Price per night + BookingBreakdown.pricePerNight - - 2017-04-14 - - – - - 2017-04-16 - + BookingBreakdown.bookingPeriod @@ -313,7 +273,7 @@ exports[`BookingBreakdown provider transaction data matches snapshot 1`] = ` className={undefined} > - Subtotal + BookingBreakdown.subTotal - Saunatime fee + BookingBreakdown.commission - You'll make + BookingBreakdown.providerTotalDefault
- Date input + DateInput.screenReaderInputMessage

- Date input + DateInput.defaultPlaceholder
diff --git a/src/components/DateRangeInputField/__snapshots__/DateRangeInputField.test.js.snap b/src/components/DateRangeInputField/__snapshots__/DateRangeInputField.test.js.snap index 8f76739a..a6ab501f 100644 --- a/src/components/DateRangeInputField/__snapshots__/DateRangeInputField.test.js.snap +++ b/src/components/DateRangeInputField/__snapshots__/DateRangeInputField.test.js.snap @@ -35,7 +35,7 @@ exports[`DateRangeInput matches snapshot 1`] = ` className="screen-reader-only" id="DateInput__screen-reader-message-bookingStartDate" > - Date input + DateRangeInputField.screenReaderInputMessage

- Date input + DateRangeInputField.screenReaderInputMessage

- Book saunas everywhere. + SectionHero.title

- The largest online community to rent saunas in Finland. + SectionHero.subTitle

diff --git a/src/components/TopbarDesktop/__snapshots__/TopbarDesktop.test.js.snap b/src/components/TopbarDesktop/__snapshots__/TopbarDesktop.test.js.snap index 2719969d..a95ff13c 100644 --- a/src/components/TopbarDesktop/__snapshots__/TopbarDesktop.test.js.snap +++ b/src/components/TopbarDesktop/__snapshots__/TopbarDesktop.test.js.snap @@ -65,7 +65,7 @@ exports[`TopbarDesktop data matches snapshot 1`] = ` onChange={[Function]} onFocus={[Function]} onKeyDown={[Function]} - placeholder="Search saunas…" + placeholder="TopbarSearchForm.placeholder" type="search" value="" /> @@ -82,7 +82,7 @@ exports[`TopbarDesktop data matches snapshot 1`] = ` className={undefined} > - + Add your sauna + TopbarDesktop.createListing @@ -97,7 +97,7 @@ exports[`TopbarDesktop data matches snapshot 1`] = ` className={undefined} > - Inbox + TopbarDesktop.inbox @@ -142,7 +142,7 @@ exports[`TopbarDesktop data matches snapshot 1`] = ` className={undefined} /> - Your listings + TopbarDesktop.yourListingsLink @@ -161,7 +161,7 @@ exports[`TopbarDesktop data matches snapshot 1`] = ` className={undefined} /> - Profile settings + TopbarDesktop.profileSettingsLink @@ -180,7 +180,7 @@ exports[`TopbarDesktop data matches snapshot 1`] = ` className={undefined} /> - Account settings + TopbarDesktop.accountSettingsLink @@ -197,7 +197,7 @@ exports[`TopbarDesktop data matches snapshot 1`] = ` className={undefined} /> - Log out + TopbarDesktop.logout diff --git a/src/containers/EditListingDescriptionForm/__snapshots__/EditListingDescriptionForm.test.js.snap b/src/containers/EditListingDescriptionForm/__snapshots__/EditListingDescriptionForm.test.js.snap index 3859ca0a..40e835c7 100644 --- a/src/containers/EditListingDescriptionForm/__snapshots__/EditListingDescriptionForm.test.js.snap +++ b/src/containers/EditListingDescriptionForm/__snapshots__/EditListingDescriptionForm.test.js.snap @@ -13,7 +13,7 @@ exports[`EditListingDescriptionForm matches snapshot 1`] = ` @@ -37,7 +37,7 @@ exports[`EditListingDescriptionForm matches snapshot 1`] = `