Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 1 addition & 133 deletions tests/browser/browser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import fs from 'fs'
import path from 'path'
import { jest } from '@jest/globals'
import { oldestSupported } from '../../lib/enterprise-server-releases.js'

import { getDOM } from '../helpers/e2etest.js'
import frontmatter from '../../lib/read-frontmatter.js'
import getApplicableVersions from '../../lib/get-applicable-versions.js'
import { allVersions } from '../../lib/all-versions.js'
import renderContent from '../../lib/render-content/index.js'
import shortVersionsMiddleware from '../../middleware/contextualizers/short-versions.js'

jest.useFakeTimers({ legacyFakeTimers: true })
const req = {}

/* global page, browser */
describe('homepage', () => {
jest.setTimeout(60 * 1000)
Expand Down Expand Up @@ -175,126 +166,3 @@ describe('iframe pages', () => {
).toBeTruthy()
})
})

describe('REST sidebar', () => {
req.context = {
allVersions,
currentLanguage: 'en',
}

it('Check REST categories and subcategories are rendering', async () => {
// Get the titles from the content/rest directory to match the titles on the page
const contentFiles = getCatAndSubCat('content/rest')
const contentCheck = await createContentCheckDirectory(contentFiles)

for (const version in allVersions) {
// Get MapTopic level categories/subcategories for each version on /rest page
const url = `/en/${version}/rest`
const $ = await getDOM(url)

const categories = []
$('[data-testid=sidebar] [data-testid=rest-category]').each((i, el) => {
categories[i] = $(el).text()
})
const browserUrl = `http://localhost:4000${url}`
await page.goto(browserUrl)
await page.setViewport({ width: 1024, height: 768 })
await page.waitForSelector('[data-testid=rest-category] li div div span')

await page.evaluate(() => {
Array.from(
document.querySelectorAll('[data-testid=rest-category] li div div span')
).forEach(async (element) => {
if (element) element.click()
})
})

const subcategories = await page.evaluate(() =>
Array.from(document.querySelectorAll('[data-testid=rest-subcategory] li div div span')).map(
(subCategory) => subCategory.textContent
)
)
expect(contentCheck[version].cat.length).toBe(categories.length)
expect(contentCheck[version].subcat.length).toBe(subcategories.length)

categories.forEach((category) => {
expect(contentCheck[version].cat).toContain(category)
})

subcategories.forEach((subcategory) => {
expect(contentCheck[version].subcat).toContain(subcategory)
})
}
})
})

// Recursively go through the content/rest directory and get all the absolute file names
function getCatAndSubCat(root) {
const files = []
for (const dirent of fs.readdirSync(root, { withFileTypes: true })) {
const { name } = dirent
const file = path.join(root, name)
if (dirent.isDirectory()) {
if (!(name === 'guides' || name === 'overview')) {
files.push(...getCatAndSubCat(file))
}
} else if (
!(
name === 'README.md' ||
file.includes('rest/index.md') ||
file.includes('rest/quickstart.md')
)
) {
files.push(file)
}
}
return files
}

// Create a ContentCheck object that has all the categories/subcategories and get the title from frontmatter
async function createContentCheckDirectory(contentFiles) {
const contentCheck = Object.keys(allVersions).reduce((acc, val) => {
return { ...acc, [val]: { cat: [], subcat: [] } }
}, {})

const renderOpts = { textOnly: true }

for (const filename of contentFiles) {
const { data } = frontmatter(await fs.promises.readFile(filename, 'utf8'))
const applicableVersions = getApplicableVersions(data.versions, filename)
const splitPath = filename.split('/')
let category = ''
let subCategory = ''

if (splitPath[splitPath.length - 2] === 'rest') {
category = data.title
} else if (splitPath[splitPath.length - 3] === 'rest') {
filename.includes('index.md')
? (category = data.shortTitle || data.title)
: (subCategory = data.shortTitle || data.title)
}
for (const version of applicableVersions) {
req.context.currentVersion = version

if (category !== '')
if (category.includes('{')) {
await shortVersionsMiddleware(req, null, () => {})
contentCheck[version].cat.push(
await renderContent.liquid.parseAndRender(category, req.context, renderOpts)
)
} else {
contentCheck[version].cat.push(category)
}
if (subCategory !== '')
if (subCategory.includes('{')) {
await shortVersionsMiddleware(req, null, () => {})
contentCheck[version].subcat.push(
await renderContent.liquid.parseAndRender(subCategory, req.context, renderOpts)
)
} else {
contentCheck[version].subcat.push(subCategory)
}
}
}
return contentCheck
}
22 changes: 22 additions & 0 deletions tests/fixtures/content/rest/code-scanning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Code Scanning
intro: >-
Use the REST API to retrieve and update {% data
variables.product.prodname_code_scanning %} alerts from a repository.
versions:
fpt: '*'
ghae: '*'
ghec: '*'
ghes: '*'
autogenerated: rest
---


## About code scanning

👋, if you're reading this, this is fixture content based on picking
a single endpoint from the real REST API reference docs.
This page, in particular, is different from "[AUTOTITLE](/rest/actions)"
in that the sidebar shows all sub-headings directly.

<!-- Content after this section is automatically generated -->
1 change: 1 addition & 0 deletions tests/fixtures/content/rest/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ versions:
children:
- /overview
- /actions
- /code-scanning

---

Expand Down
22 changes: 22 additions & 0 deletions tests/rendering-fixtures/playwright-rendering.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,25 @@ test.describe('survey', () => {
await expect(page.getByRole('button', { name: 'Send' })).not.toBeVisible()
})
})

test.describe('rest API reference pages', () => {
test('REST code-scanning', async ({ page }) => {
await page.goto('/rest')
await page.getByRole('treeitem', { name: 'Code Scanning' }).locator('svg').click()
await page.getByText('Code Scanning').click()
await page.getByTestId('sidebar').getByRole('link', { name: 'About code scanning' }).click()
await expect(page).toHaveURL(/\/en\/rest\/code-scanning\?apiVersion=/)
await expect(page).toHaveTitle(/Code Scanning - GitHub Docs/)
})
test('REST actions', async ({ page }) => {
await page.goto('/rest')
await page.getByTestId('sidebar').getByText('Actions').click()
await page.getByTestId('rest-subcategory').getByRole('link', { name: 'Artifacts' }).click()
await page
.getByTestId('rest-subcategory')
.getByRole('link', { name: 'About artifacts in GitHub Actions' })
.click()
await expect(page).toHaveURL(/\/en\/rest\/actions\/artifacts\?apiVersion=/)
await expect(page).toHaveTitle(/GitHub Actions Artifacts - GitHub Docs/)
})
})