2021-07-14 23:49:18 +03:00
|
|
|
import revalidator from 'revalidator'
|
|
|
|
import schema from '../helpers/schemas/site-tree-schema.js'
|
2021-07-29 23:28:30 +03:00
|
|
|
import EnterpriseServerReleases from '../../lib/enterprise-server-releases.js'
|
2021-07-14 23:49:18 +03:00
|
|
|
import { loadSiteTree } from '../../lib/page-data.js'
|
|
|
|
import japaneseCharacters from 'japanese-characters'
|
|
|
|
import nonEnterpriseDefaultVersion from '../../lib/non-enterprise-default-version.js'
|
|
|
|
import { jest } from '@jest/globals'
|
|
|
|
|
2021-07-29 23:28:30 +03:00
|
|
|
const latestEnterpriseRelease = EnterpriseServerReleases.latest
|
2021-05-19 03:44:46 +03:00
|
|
|
|
2020-09-27 15:10:11 +03:00
|
|
|
describe('siteTree', () => {
|
|
|
|
jest.setTimeout(3 * 60 * 1000)
|
|
|
|
|
2021-05-26 22:18:26 +03:00
|
|
|
let siteTree
|
2021-07-14 23:49:18 +03:00
|
|
|
beforeAll(async () => {
|
2021-05-20 17:01:33 +03:00
|
|
|
siteTree = await loadSiteTree()
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
test('has language codes as top-level keys', () => {
|
|
|
|
expect('en' in siteTree).toBe(true)
|
|
|
|
expect('ja' in siteTree).toBe(true)
|
|
|
|
})
|
|
|
|
|
2021-05-20 17:01:33 +03:00
|
|
|
test('object order and structure', () => {
|
2021-06-18 20:13:04 +03:00
|
|
|
expect(siteTree.en[nonEnterpriseDefaultVersion].childPages[0].href).toBe('/en/get-started')
|
2021-07-15 00:35:01 +03:00
|
|
|
expect(siteTree.en[nonEnterpriseDefaultVersion].childPages[0].childPages[0].href).toBe(
|
|
|
|
'/en/get-started/quickstart'
|
|
|
|
)
|
2021-05-19 03:44:46 +03:00
|
|
|
})
|
|
|
|
|
2020-09-27 15:10:11 +03:00
|
|
|
describe('localized titles', () => {
|
2021-12-13 05:11:48 +03:00
|
|
|
// skipped because it has rendering errors. See translations/log/ja-resets.csv
|
|
|
|
test.skip('titles for categories', () => {
|
2021-07-15 00:35:01 +03:00
|
|
|
const japaneseTitle =
|
|
|
|
siteTree.ja[nonEnterpriseDefaultVersion].childPages[0].childPages[0].page.title
|
2021-05-19 03:44:46 +03:00
|
|
|
expect(typeof japaneseTitle).toBe('string')
|
|
|
|
expect(japaneseCharacters.presentIn(japaneseTitle)).toBe(true)
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2021-07-15 00:35:01 +03:00
|
|
|
const englishTitle =
|
|
|
|
siteTree.en[nonEnterpriseDefaultVersion].childPages[0].childPages[0].page.title
|
2021-05-19 03:44:46 +03:00
|
|
|
expect(typeof englishTitle).toBe('string')
|
|
|
|
expect(japaneseCharacters.presentIn(englishTitle)).toBe(false)
|
|
|
|
})
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2021-05-20 17:01:33 +03:00
|
|
|
test('articles that include site data in liquid templating', async () => {
|
2021-05-19 03:44:46 +03:00
|
|
|
const ghesLatest = `enterprise-server@${latestEnterpriseRelease}`
|
|
|
|
const ghesSiteTree = siteTree.en[ghesLatest]
|
|
|
|
|
|
|
|
// Find a page in the tree that we know contains Liquid
|
2021-05-21 19:32:05 +03:00
|
|
|
// TODO: use new findPageInSiteTree helper when it's available
|
2021-07-15 00:35:01 +03:00
|
|
|
const pageWithDynamicTitle = ghesSiteTree.childPages
|
|
|
|
.find((child) => child.href === `/en/${ghesLatest}/admin`)
|
2022-01-18 16:24:02 +03:00
|
|
|
.childPages.find((child) => child.href === `/en/${ghesLatest}/admin/installation`)
|
2021-05-19 03:44:46 +03:00
|
|
|
|
|
|
|
// Confirm the raw title contains Liquid
|
2021-07-15 00:35:01 +03:00
|
|
|
expect(pageWithDynamicTitle.page.title).toEqual(
|
2022-01-18 16:24:02 +03:00
|
|
|
'Installing {% data variables.product.prodname_enterprise %}'
|
2021-07-15 00:35:01 +03:00
|
|
|
)
|
2021-05-19 03:44:46 +03:00
|
|
|
|
|
|
|
// Confirm a new property contains the rendered title
|
2022-01-18 16:24:02 +03:00
|
|
|
expect(pageWithDynamicTitle.renderedFullTitle).toEqual('Installing GitHub Enterprise')
|
2021-05-19 03:44:46 +03:00
|
|
|
})
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
2021-05-20 17:01:33 +03:00
|
|
|
test('object validation', () => {
|
2021-05-19 03:44:46 +03:00
|
|
|
const childPages = siteTree.en[nonEnterpriseDefaultVersion].childPages
|
|
|
|
expect(childPages.length).toBeGreaterThan(0)
|
|
|
|
|
|
|
|
validate(siteTree.en[nonEnterpriseDefaultVersion])
|
|
|
|
})
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
2021-05-19 03:44:46 +03:00
|
|
|
|
2021-07-15 00:35:01 +03:00
|
|
|
function validate(currentPage) {
|
|
|
|
;(currentPage.childPages || []).forEach((childPage) => {
|
2021-05-19 03:44:46 +03:00
|
|
|
const { valid, errors } = revalidator.validate(childPage, schema.childPage)
|
|
|
|
const expectation = JSON.stringify(errors, null, 2)
|
|
|
|
expect(valid, expectation).toBe(true)
|
|
|
|
|
|
|
|
// Run recurisvely until we run out of child pages
|
|
|
|
validate(childPage)
|
|
|
|
})
|
|
|
|
}
|