diff --git a/client/src/__mocks__/gatsby.js b/client/src/__mocks__/gatsby.js index 53952b33fc..7ee4afd3df 100644 --- a/client/src/__mocks__/gatsby.js +++ b/client/src/__mocks__/gatsby.js @@ -4,6 +4,8 @@ const React = require('react'); const gatsby = jest.requireActual('gatsby'); +const { clientLocale } = require('../../config/env'); + module.exports = { ...gatsby, navigate: jest.fn(), @@ -26,6 +28,13 @@ module.exports = { href: to }) ), + withPrefix: jest.fn().mockImplementation(path => { + const pathPrefix = + clientLocale === 'english' || clientLocale === 'chinese' + ? '' + : '/' + clientLocale; + return pathPrefix + path; + }), StaticQuery: jest.fn(), useStaticQuery: jest.fn() }; diff --git a/client/src/components/RedirectHome.js b/client/src/components/RedirectHome.js index ad5bb65171..e49a24f3db 100644 --- a/client/src/components/RedirectHome.js +++ b/client/src/components/RedirectHome.js @@ -1,3 +1,4 @@ import createRedirect from './createRedirect'; +import { withPrefix } from 'gatsby'; -export default createRedirect('/'); +export default createRedirect(withPrefix('/')); diff --git a/client/src/pages/404.js b/client/src/pages/404.js index e0e2052f31..fd8dcff09a 100644 --- a/client/src/pages/404.js +++ b/client/src/pages/404.js @@ -1,5 +1,6 @@ import React from 'react'; import { Router } from '@reach/router'; +import { withPrefix } from 'gatsby'; import FourOhFour from '../components/FourOhFour'; /* eslint-disable max-len */ @@ -9,7 +10,7 @@ import ShowProfileOrFourOhFour from '../client-only-routes/ShowProfileOrFourOhFo function FourOhFourPage() { return ( - + ); diff --git a/client/src/pages/certification.js b/client/src/pages/certification.js index f7ee3e74c1..aa5e62c59b 100644 --- a/client/src/pages/certification.js +++ b/client/src/pages/certification.js @@ -1,5 +1,6 @@ import React, { Component } from 'react'; import { Router } from '@reach/router'; +import { withPrefix } from 'gatsby'; import RedirectHome from '../components/RedirectHome'; import ShowCertification from '../client-only-routes/ShowCertification'; @@ -10,7 +11,9 @@ class Certification extends Component { render() { return ( - + ); diff --git a/client/src/pages/challenges.js b/client/src/pages/challenges.js index 0291e098ff..8eb4bd58b8 100644 --- a/client/src/pages/challenges.js +++ b/client/src/pages/challenges.js @@ -1,11 +1,7 @@ // this exists purely to redirect legacy challenge paths to /learn import React from 'react'; import { Router } from '@reach/router'; -import { navigate } from 'gatsby'; - -import createRedirect from '../components/createRedirect'; - -const RedirectToLearn = createRedirect('/learn'); +import { navigate, withPrefix } from 'gatsby'; const Redirect = props => { if (typeof window !== 'undefined') { @@ -15,18 +11,18 @@ const Redirect = props => { }; const Challenges = () => ( - + - + ); Challenges.displayName = 'Challenges'; export function toLearnPath({ superBlock, block, challenge }) { - let path = '/learn'; + let path = withPrefix('/learn'); if (superBlock) path += `/${superBlock}`; if (block) path += `/${block}`; if (challenge) path += `/${challenge}`; diff --git a/client/src/pages/challenges.test.js b/client/src/pages/challenges.test.js index 86fd4dcc21..dbc43f81bf 100644 --- a/client/src/pages/challenges.test.js +++ b/client/src/pages/challenges.test.js @@ -1,19 +1,22 @@ /* global expect */ import { toLearnPath } from './challenges'; +import { withPrefix } from 'gatsby'; describe('toLearnPath', () => { it('should return a string', () => { expect(typeof toLearnPath({})).toBe('string'); }); it('should include /learn', () => { - expect(toLearnPath({})).toMatch(/\/learn/); + expect(toLearnPath({})).toMatch(withPrefix('/learn')); }); it('should include superBlock after learn', () => { - expect(toLearnPath({ superBlock: 'testSuper' })).toBe('/learn/testSuper'); + expect(toLearnPath({ superBlock: 'testSuper' })).toBe( + withPrefix('/learn/testSuper') + ); }); it('should include superBlock, then block after learn', () => { expect(toLearnPath({ superBlock: 'testSuper', block: 'testBlock' })).toBe( - '/learn/testSuper/testBlock' + withPrefix('/learn/testSuper/testBlock') ); }); it('should include superBlock, block, then challenge after learn', () => { @@ -23,6 +26,6 @@ describe('toLearnPath', () => { block: 'testBlock', challenge: 'testChallenge' }) - ).toBe('/learn/testSuper/testBlock/testChallenge'); + ).toBe(withPrefix('/learn/testSuper/testBlock/testChallenge')); }); }); diff --git a/client/src/pages/settings.js b/client/src/pages/settings.js index ac1ef0b5e8..e1170f2f07 100644 --- a/client/src/pages/settings.js +++ b/client/src/pages/settings.js @@ -1,5 +1,6 @@ import React from 'react'; import { Router } from '@reach/router'; +import { withPrefix } from 'gatsby'; import RedirectHome from '../components/RedirectHome'; import ShowSettings from '../client-only-routes/ShowSettings'; @@ -7,7 +8,7 @@ import ShowSettings from '../client-only-routes/ShowSettings'; function Settings() { return ( - + ); diff --git a/client/src/pages/unsubscribed.js b/client/src/pages/unsubscribed.js index 050a2fa6b2..e0a3ea7305 100644 --- a/client/src/pages/unsubscribed.js +++ b/client/src/pages/unsubscribed.js @@ -1,5 +1,6 @@ import React from 'react'; import { Router } from '@reach/router'; +import { withPrefix } from 'gatsby'; import RedirectHome from '../components/RedirectHome'; import ShowUnsubscribed from '../client-only-routes/ShowUnsubscribed'; @@ -7,8 +8,8 @@ import ShowUnsubscribed from '../client-only-routes/ShowUnsubscribed'; function Unsubscribed() { return ( - - + + ); diff --git a/client/src/pages/user.js b/client/src/pages/user.js index 4071327b2f..cb78847438 100644 --- a/client/src/pages/user.js +++ b/client/src/pages/user.js @@ -1,5 +1,6 @@ import React from 'react'; import { Router } from '@reach/router'; +import { withPrefix } from 'gatsby'; import RedirectHome from '../components/RedirectHome'; import ShowUser from '../client-only-routes/ShowUser'; @@ -7,7 +8,7 @@ import ShowUser from '../client-only-routes/ShowUser'; function User() { return ( - + );