forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind-page.js
More file actions
44 lines (37 loc) · 1.44 KB
/
Copy pathfind-page.js
File metadata and controls
44 lines (37 loc) · 1.44 KB
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
const path = require('path')
const Page = require('../../lib/page')
const loadRedirects = require('../../lib/redirects/precompile')
const findPage = require('../../lib/find-page')
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
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 = new Page({
relativePath: 'page-that-does-not-exist-in-translations-dir.md',
basePath: path.join(__dirname, '../fixtures'),
languageCode: 'en'
})
const pages = [page]
// add named keys
for (const page of pages) {
pages[`/en/${nonEnterpriseDefaultVersion}/${page.relativePath}`] = page
}
const localizedPage = findPage(page.relativePath, pages, {}, 'ja')
expect(typeof localizedPage.title).toBe('string')
})
test('follows redirects', async () => {
const page = new Page({
relativePath: 'page-with-redirects.md',
basePath: path.join(__dirname, '../fixtures'),
languageCode: 'en'
})
const pages = [page]
// add named keys
for (const page of pages) {
pages[`/en/${nonEnterpriseDefaultVersion}/${page.relativePath.replace('.md', '')}`] = page
}
const redirects = await loadRedirects(pages)
const redirectedPage = findPage('some-old-path', pages, redirects, 'en')
expect(typeof redirectedPage.title).toBe('string')
})
})