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", 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/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 = {}; 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`] = `