forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-page.js
45 lines (36 loc) · 1.3 KB
/
find-page.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const path = require('path')
const Page = require('../../lib/page')
const findPage = require('../../lib/find-page')
describe('find page', () => {
jest.setTimeout(1000 * 1000)
test('falls back to the English page if it can\'t find a localized page', async () => {
const page = await Page.init({
relativePath: 'page-that-does-not-exist-in-translations-dir.md',
basePath: path.join(__dirname, '../fixtures'),
languageCode: 'en'
})
const englishPermalink = page.permalinks[0].href
const japanesePermalink = englishPermalink.replace('/en/', '/ja/')
// add named keys
const pageMap = {
[englishPermalink]: page
}
const localizedPage = findPage(japanesePermalink, pageMap, {})
expect(typeof localizedPage.title).toBe('string')
})
test('follows redirects', async () => {
const page = await Page.init({
relativePath: 'page-with-redirects.md',
basePath: path.join(__dirname, '../fixtures'),
languageCode: 'en'
})
const englishPermalink = page.permalinks[0].href
const redirectToFind = '/some-old-path'
// add named keys
const pageMap = {
[englishPermalink]: page
}
const redirectedPage = findPage(redirectToFind, pageMap, page.buildRedirects())
expect(typeof redirectedPage.title).toBe('string')
})
})