docs/tests/content/site-tree.js

83 строки
3.1 KiB
JavaScript
Исходник Обычный вид История

import revalidator from 'revalidator'
import schema from '../helpers/schemas/site-tree-schema.js'
import EnterpriseServerReleases from '../../lib/enterprise-server-releases.js'
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'
const latestEnterpriseRelease = EnterpriseServerReleases.latest
describe('siteTree', () => {
jest.setTimeout(3 * 60 * 1000)
2021-05-26 22:18:26 +03:00
let siteTree
beforeAll(async () => {
2021-05-20 17:01:33 +03:00
siteTree = await loadSiteTree()
})
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', () => {
expect(siteTree.en[nonEnterpriseDefaultVersion].childPages[0].href).toBe('/en/get-started')
expect(siteTree.en[nonEnterpriseDefaultVersion].childPages[0].childPages[0].href).toBe(
'/en/get-started/quickstart'
)
})
describe('localized titles', () => {
// skipped because it has rendering errors. See translations/log/ja-resets.csv
test.skip('titles for categories', () => {
const japaneseTitle =
siteTree.ja[nonEnterpriseDefaultVersion].childPages[0].childPages[0].page.title
expect(typeof japaneseTitle).toBe('string')
expect(japaneseCharacters.presentIn(japaneseTitle)).toBe(true)
const englishTitle =
siteTree.en[nonEnterpriseDefaultVersion].childPages[0].childPages[0].page.title
expect(typeof englishTitle).toBe('string')
expect(japaneseCharacters.presentIn(englishTitle)).toBe(false)
})
2021-05-20 17:01:33 +03:00
test('articles that include site data in liquid templating', async () => {
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
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`)
// Confirm the raw title contains Liquid
expect(pageWithDynamicTitle.page.title).toEqual(
2022-01-18 16:24:02 +03:00
'Installing {% data variables.product.prodname_enterprise %}'
)
// 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-20 17:01:33 +03:00
test('object validation', () => {
const childPages = siteTree.en[nonEnterpriseDefaultVersion].childPages
expect(childPages.length).toBeGreaterThan(0)
validate(siteTree.en[nonEnterpriseDefaultVersion])
})
})
function validate(currentPage) {
;(currentPage.childPages || []).forEach((childPage) => {
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)
})
}