2021-12-13 11:57:00 +03:00
|
|
|
import fs from 'fs/promises'
|
|
|
|
import path from 'path'
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
|
|
|
import { beforeAll, jest } from '@jest/globals'
|
|
|
|
import nock from 'nock'
|
|
|
|
import japaneseCharacters from 'japanese-characters'
|
|
|
|
|
2021-07-14 23:49:18 +03:00
|
|
|
import '../../lib/feature-flags.js'
|
2022-03-19 00:06:12 +03:00
|
|
|
import { getDOM, getJSON } from '../helpers/e2etest.js'
|
2021-07-14 23:49:18 +03:00
|
|
|
import enterpriseServerReleases from '../../lib/enterprise-server-releases.js'
|
2021-12-13 11:57:00 +03:00
|
|
|
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2020-10-27 20:53:10 +03:00
|
|
|
describe('featuredLinks', () => {
|
2020-09-27 15:10:11 +03:00
|
|
|
jest.setTimeout(3 * 60 * 1000)
|
|
|
|
|
2021-12-13 11:57:00 +03:00
|
|
|
beforeAll(async () => {
|
|
|
|
const packagesFeedFixturePayload = await fs.readFile(
|
|
|
|
path.join(__dirname, '../fixtures/github-blog-feed-packages-2021.xml'),
|
|
|
|
'utf-8'
|
|
|
|
)
|
|
|
|
nock('https://github.blog')
|
|
|
|
.get('/changelog/label/packages/feed')
|
|
|
|
.reply(200, packagesFeedFixturePayload)
|
|
|
|
})
|
|
|
|
|
|
|
|
afterAll(() => nock.cleanAll())
|
|
|
|
|
2020-09-27 15:10:11 +03:00
|
|
|
describe('rendering', () => {
|
|
|
|
test('non-TOC pages do not have intro links', async () => {
|
2021-10-11 15:50:08 +03:00
|
|
|
const $ = await getDOM('/en/get-started/quickstart/set-up-git')
|
2021-07-29 20:27:20 +03:00
|
|
|
expect($('[data-testid=article-list]')).toHaveLength(0)
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
2020-09-29 20:36:07 +03:00
|
|
|
test('landing page intro links have expected properties', async () => {
|
2020-09-27 15:10:11 +03:00
|
|
|
const $ = await getDOM('/en')
|
2021-06-17 20:04:53 +03:00
|
|
|
const $featuredLinks = $('[data-testid=article-list] a')
|
2021-10-20 13:35:25 +03:00
|
|
|
expect($featuredLinks).toHaveLength(9)
|
2021-10-19 14:41:47 +03:00
|
|
|
expect($featuredLinks.eq(0).attr('href')).toBe('/en/get-started/quickstart/set-up-git')
|
2022-01-14 20:23:05 +03:00
|
|
|
expect($featuredLinks.eq(0).children('h3').text().startsWith('Set up Git')).toBe(true)
|
2021-07-15 00:35:01 +03:00
|
|
|
expect($featuredLinks.eq(0).children('p').text().startsWith('At the heart of GitHub')).toBe(
|
|
|
|
true
|
|
|
|
)
|
2020-09-27 15:10:11 +03:00
|
|
|
|
2021-10-19 14:41:47 +03:00
|
|
|
expect($featuredLinks.eq(8).attr('href')).toBe('/en/pages')
|
2022-01-14 20:23:05 +03:00
|
|
|
expect($featuredLinks.eq(8).children('h3').text().startsWith('GitHub Pages')).toBe(true)
|
2021-07-15 00:35:01 +03:00
|
|
|
expect($featuredLinks.eq(8).children('p').text().startsWith('You can create a website')).toBe(
|
|
|
|
true
|
|
|
|
)
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
2022-01-10 17:16:04 +03:00
|
|
|
test('localized intro links link to localized pages', async () => {
|
|
|
|
const $jaPages = await getDOM('/ja')
|
|
|
|
const $enPages = await getDOM('/en')
|
|
|
|
const $jaFeaturedLinks = $jaPages('[data-testid=article-list] a')
|
|
|
|
const $enFeaturedLinks = $enPages('[data-testid=article-list] a')
|
|
|
|
expect($jaFeaturedLinks.length).toBe($enFeaturedLinks.length)
|
|
|
|
expect($jaFeaturedLinks.eq(0).attr('href').startsWith('/ja')).toBe(true)
|
|
|
|
|
|
|
|
// Footer translations change very rarely if ever, so we can more
|
|
|
|
// reliably test those text values for the language
|
|
|
|
const footerText = []
|
|
|
|
$jaPages('footer a').each((index, element) => {
|
|
|
|
footerText.push($jaPages(element).text())
|
|
|
|
})
|
|
|
|
expect(footerText.some((elem) => japaneseCharacters.presentIn(elem)))
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
2020-09-29 20:36:07 +03:00
|
|
|
test('Enterprise user intro links have expected values', async () => {
|
2021-08-25 21:36:35 +03:00
|
|
|
const $ = await getDOM(`/en/enterprise/${enterpriseServerReleases.latest}/user/get-started`)
|
2021-06-17 20:04:53 +03:00
|
|
|
const $featuredLinks = $('[data-testid=article-list] a')
|
2021-12-17 12:53:30 +03:00
|
|
|
expect($featuredLinks).toHaveLength(11)
|
2021-07-15 00:35:01 +03:00
|
|
|
expect($featuredLinks.eq(0).attr('href')).toBe(
|
2021-08-25 21:36:35 +03:00
|
|
|
`/en/enterprise-server@${enterpriseServerReleases.latest}/github/getting-started-with-github/githubs-products`
|
2021-07-15 00:35:01 +03:00
|
|
|
)
|
2022-01-14 20:23:05 +03:00
|
|
|
expect($featuredLinks.eq(0).children('h3').text().startsWith("GitHub's products")).toBe(true)
|
2021-07-15 00:35:01 +03:00
|
|
|
expect(
|
2021-08-25 21:36:35 +03:00
|
|
|
$featuredLinks
|
|
|
|
.eq(0)
|
|
|
|
.children('p')
|
|
|
|
.text()
|
|
|
|
.startsWith("An overview of GitHub's products and pricing plans.")
|
2021-07-15 00:35:01 +03:00
|
|
|
).toBe(true)
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
|
2021-05-01 02:28:27 +03:00
|
|
|
// If any of these tests fail, check to see if the content has changed and update text if needed.
|
2021-06-17 20:04:53 +03:00
|
|
|
test('product articles links respect versioning', async () => {
|
2021-05-01 02:28:27 +03:00
|
|
|
const enterpriseVersionedLandingPage = `/en/enterprise-server@${enterpriseServerReleases.latest}/packages`
|
|
|
|
const $ = await getDOM(enterpriseVersionedLandingPage)
|
2021-06-17 20:04:53 +03:00
|
|
|
const $productArticlesLinks = $('[data-testid=product-articles-list] a')
|
|
|
|
let msg = `Product article links are not rendered as expected on ${enterpriseVersionedLandingPage}`
|
|
|
|
expect($productArticlesLinks.length, msg).toBeGreaterThan(2)
|
2021-05-01 02:28:27 +03:00
|
|
|
|
|
|
|
// Confirm that the following Enterprise link IS included on this Enterprise page.
|
2021-06-17 20:04:53 +03:00
|
|
|
msg = `Enterprise article link is not rendered as expected on ${enterpriseVersionedLandingPage}`
|
2021-07-15 00:35:01 +03:00
|
|
|
expect(
|
|
|
|
$productArticlesLinks.text().includes('Working with a GitHub Packages registry'),
|
|
|
|
msg
|
|
|
|
).toBe(true)
|
2021-05-01 02:28:27 +03:00
|
|
|
|
|
|
|
// Confirm that the following Dotcom-only links are NOT included on this Enterprise page.
|
2021-06-17 20:04:53 +03:00
|
|
|
msg = `Dotcom-only article link is rendered, but should not be, on ${enterpriseVersionedLandingPage}`
|
2021-07-15 00:35:01 +03:00
|
|
|
expect($productArticlesLinks.text().includes('Working with the Container registry')).toBe(
|
|
|
|
false
|
|
|
|
)
|
|
|
|
expect(
|
|
|
|
$productArticlesLinks
|
|
|
|
.text()
|
|
|
|
.includes('Migrating to the Container registry from the Docker registry'),
|
|
|
|
msg
|
|
|
|
).toBe(false)
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('context.page object', () => {
|
2020-09-29 20:36:07 +03:00
|
|
|
test('returns modified array of links', async () => {
|
2020-10-27 20:53:10 +03:00
|
|
|
const gettingStartedLinks = await getJSON('/en?json=featuredLinks.gettingStarted')
|
2020-09-27 15:10:11 +03:00
|
|
|
const expectedFirstLink = {
|
2021-10-11 15:50:08 +03:00
|
|
|
href: '/en/get-started/quickstart/set-up-git',
|
2021-07-15 00:35:01 +03:00
|
|
|
title: 'Set up Git',
|
2020-09-27 15:10:11 +03:00
|
|
|
}
|
|
|
|
expect(gettingStartedLinks[0].href).toEqual(expectedFirstLink.href)
|
|
|
|
expect(gettingStartedLinks[0].title).toEqual(expectedFirstLink.title)
|
|
|
|
expect(gettingStartedLinks[0].intro.startsWith('At the heart of GitHub')).toBe(true)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('returns raw array of links on the page object', async () => {
|
2020-10-27 20:53:10 +03:00
|
|
|
const rawGettingStartedLinks = await getJSON('/en?json=page.featuredLinks.gettingStarted')
|
2021-10-19 14:50:07 +03:00
|
|
|
expect(rawGettingStartedLinks[0]).toEqual('/get-started/quickstart/set-up-git')
|
2020-09-27 15:10:11 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|