parent
159741f0af
commit
796f1cdac0
23 changed files with 1798 additions and 99 deletions
@ -0,0 +1,84 @@ |
|||||||
|
const path = require('path'); |
||||||
|
const fs = require('fs'); |
||||||
|
const guides = require('../data/guides'); |
||||||
|
const roadmaps = require('../data/roadmaps'); |
||||||
|
|
||||||
|
const { |
||||||
|
getPageRoutes, |
||||||
|
getGuideRoutes, |
||||||
|
getRoadmapRoutes |
||||||
|
} = require("../path-map"); |
||||||
|
|
||||||
|
describe("Build scripts tests", () => { |
||||||
|
test('it should generate valid pathmap for pages', () => { |
||||||
|
const pageRoutes = getPageRoutes(); |
||||||
|
|
||||||
|
expect(pageRoutes).toEqual({ |
||||||
|
'/': { page: '/index' }, |
||||||
|
'/about': { page: '/about' }, |
||||||
|
'/privacy': { page: '/privacy' }, |
||||||
|
'/terms': { page: '/terms' }, |
||||||
|
'/guides': { page: '/guides/index' }, |
||||||
|
'/roadmaps': { page: '/roadmaps' }, |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
test('it should generate valid guides pathmap', () => { |
||||||
|
const expectedGuideRoutes = guides.reduce((acc, guide) => { |
||||||
|
const [,, slug] = guide.url.split('/'); |
||||||
|
return { |
||||||
|
...acc, |
||||||
|
[guide.url]: { |
||||||
|
page: '/guides/[guide]', |
||||||
|
query: slug, |
||||||
|
} |
||||||
|
}; |
||||||
|
}, {}); |
||||||
|
|
||||||
|
// Valid path map is generated
|
||||||
|
expect(expectedGuideRoutes).toEqual(getGuideRoutes()); |
||||||
|
|
||||||
|
const pageFilePath = path.join(__dirname, '../pages/guides/[guide].js'); |
||||||
|
const foundFilePath = fs.existsSync(pageFilePath) ? pageFilePath : ''; |
||||||
|
|
||||||
|
// Given page component exists
|
||||||
|
expect(foundFilePath).toEqual(pageFilePath); |
||||||
|
}); |
||||||
|
|
||||||
|
test('it should have markdown file for each guide', () => { |
||||||
|
guides.forEach(guide => { |
||||||
|
const [,, slug] = guide.url.split('/'); |
||||||
|
|
||||||
|
const expectedFile = path.join(__dirname, `../data/guides/${slug}.md`); |
||||||
|
const foundFile = fs.existsSync(expectedFile) ? expectedFile : ''; |
||||||
|
|
||||||
|
expect(foundFile).toEqual(expectedFile); |
||||||
|
}) |
||||||
|
}); |
||||||
|
|
||||||
|
test('it should generate valid roadmap routes', () => { |
||||||
|
const expectedPathMap = roadmaps.reduce((roadmapAcc, roadmap) => { |
||||||
|
// Routes for each of the versions of this roadmap
|
||||||
|
const versionRoutes = roadmap.versions.reduce((versionAcc, version) => ({ |
||||||
|
...versionAcc, |
||||||
|
[`${roadmap.url}/${version}`]: { |
||||||
|
page: '/[roadmap]/[version]', |
||||||
|
query: `${roadmap.url.split('/')[1]}/${version}`, |
||||||
|
} |
||||||
|
}), {}); |
||||||
|
|
||||||
|
// Route for the route roadmap itself
|
||||||
|
return { |
||||||
|
...roadmapAcc, |
||||||
|
[roadmap.url]: { |
||||||
|
page: '/[roadmap]/index', |
||||||
|
query: roadmap.url.split('/')[1] |
||||||
|
}, |
||||||
|
// Expected roadmap for versions
|
||||||
|
...versionRoutes |
||||||
|
}; |
||||||
|
}, {}); |
||||||
|
|
||||||
|
expect(getRoadmapRoutes()).toEqual(expectedPathMap); |
||||||
|
}) |
||||||
|
}); |
@ -1,3 +0,0 @@ |
|||||||
import OldRoadmap from './index'; |
|
||||||
|
|
||||||
export default OldRoadmap; |
|
@ -1,22 +0,0 @@ |
|||||||
import Error from 'next/error'; |
|
||||||
import Roadmap from 'pages/roadmaps/[roadmap]/index'; |
|
||||||
import { serverOnlyProps } from 'lib/server'; |
|
||||||
import { getRequestedRoadmap } from 'lib/roadmap'; |
|
||||||
|
|
||||||
// Fallback page to handle the old roadmap pages implementation
|
|
||||||
const OldRoadmap = ({ roadmap }) => { |
|
||||||
if (roadmap) { |
|
||||||
return <Roadmap roadmap={ roadmap } /> |
|
||||||
} |
|
||||||
|
|
||||||
return <Error statusCode={ 404 } />; |
|
||||||
}; |
|
||||||
|
|
||||||
OldRoadmap.getInitialProps = serverOnlyProps(({ req }) => { |
|
||||||
return { |
|
||||||
roadmap: getRequestedRoadmap(req), |
|
||||||
}; |
|
||||||
}); |
|
||||||
|
|
||||||
|
|
||||||
export default OldRoadmap; |
|
@ -1,10 +1,10 @@ |
|||||||
import Error from 'next/error'; |
import Error from 'next/error'; |
||||||
import DefaultLayout from 'layouts/default'; |
import DefaultLayout from 'layouts/default'; |
||||||
import { serverOnlyProps } from 'lib/server'; |
|
||||||
import PageHeader from 'components/page-header'; |
import PageHeader from 'components/page-header'; |
||||||
import PageFooter from 'components/page-footer'; |
import PageFooter from 'components/page-footer'; |
||||||
import { getRequestedRoadmap } from 'lib/roadmap'; |
|
||||||
import RoadmapSummary from 'components/roadmap-summary'; |
import RoadmapSummary from 'components/roadmap-summary'; |
||||||
|
import { serverOnlyProps } from 'lib/server'; |
||||||
|
import { getRequestedRoadmap } from 'lib/roadmap'; |
||||||
|
|
||||||
const Roadmap = ({ roadmap }) => { |
const Roadmap = ({ roadmap }) => { |
||||||
if (!roadmap) { |
if (!roadmap) { |
Loading…
Reference in new issue