Skip to content

Commit ca1a27c

Browse files
authored
Merge pull request #25595 from github/repo-sync
repo sync
2 parents a80daa2 + a7c015d commit ca1a27c

File tree

4 files changed

+46
-133
lines changed

4 files changed

+46
-133
lines changed

tests/browser/browser.js

Lines changed: 1 addition & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
import fs from 'fs'
2-
import path from 'path'
31
import { jest } from '@jest/globals'
42
import { oldestSupported } from '../../lib/enterprise-server-releases.js'
53

6-
import { getDOM } from '../helpers/e2etest.js'
7-
import frontmatter from '../../lib/read-frontmatter.js'
8-
import getApplicableVersions from '../../lib/get-applicable-versions.js'
9-
import { allVersions } from '../../lib/all-versions.js'
10-
import renderContent from '../../lib/render-content/index.js'
11-
import shortVersionsMiddleware from '../../middleware/contextualizers/short-versions.js'
12-
134
jest.useFakeTimers({ legacyFakeTimers: true })
14-
const req = {}
5+
156
/* global page, browser */
167
describe('homepage', () => {
178
jest.setTimeout(60 * 1000)
@@ -175,126 +166,3 @@ describe('iframe pages', () => {
175166
).toBeTruthy()
176167
})
177168
})
178-
179-
describe('REST sidebar', () => {
180-
req.context = {
181-
allVersions,
182-
currentLanguage: 'en',
183-
}
184-
185-
it('Check REST categories and subcategories are rendering', async () => {
186-
// Get the titles from the content/rest directory to match the titles on the page
187-
const contentFiles = getCatAndSubCat('content/rest')
188-
const contentCheck = await createContentCheckDirectory(contentFiles)
189-
190-
for (const version in allVersions) {
191-
// Get MapTopic level categories/subcategories for each version on /rest page
192-
const url = `/en/${version}/rest`
193-
const $ = await getDOM(url)
194-
195-
const categories = []
196-
$('[data-testid=sidebar] [data-testid=rest-category]').each((i, el) => {
197-
categories[i] = $(el).text()
198-
})
199-
const browserUrl = `http://localhost:4000${url}`
200-
await page.goto(browserUrl)
201-
await page.setViewport({ width: 1024, height: 768 })
202-
await page.waitForSelector('[data-testid=rest-category] li div div span')
203-
204-
await page.evaluate(() => {
205-
Array.from(
206-
document.querySelectorAll('[data-testid=rest-category] li div div span')
207-
).forEach(async (element) => {
208-
if (element) element.click()
209-
})
210-
})
211-
212-
const subcategories = await page.evaluate(() =>
213-
Array.from(document.querySelectorAll('[data-testid=rest-subcategory] li div div span')).map(
214-
(subCategory) => subCategory.textContent
215-
)
216-
)
217-
expect(contentCheck[version].cat.length).toBe(categories.length)
218-
expect(contentCheck[version].subcat.length).toBe(subcategories.length)
219-
220-
categories.forEach((category) => {
221-
expect(contentCheck[version].cat).toContain(category)
222-
})
223-
224-
subcategories.forEach((subcategory) => {
225-
expect(contentCheck[version].subcat).toContain(subcategory)
226-
})
227-
}
228-
})
229-
})
230-
231-
// Recursively go through the content/rest directory and get all the absolute file names
232-
function getCatAndSubCat(root) {
233-
const files = []
234-
for (const dirent of fs.readdirSync(root, { withFileTypes: true })) {
235-
const { name } = dirent
236-
const file = path.join(root, name)
237-
if (dirent.isDirectory()) {
238-
if (!(name === 'guides' || name === 'overview')) {
239-
files.push(...getCatAndSubCat(file))
240-
}
241-
} else if (
242-
!(
243-
name === 'README.md' ||
244-
file.includes('rest/index.md') ||
245-
file.includes('rest/quickstart.md')
246-
)
247-
) {
248-
files.push(file)
249-
}
250-
}
251-
return files
252-
}
253-
254-
// Create a ContentCheck object that has all the categories/subcategories and get the title from frontmatter
255-
async function createContentCheckDirectory(contentFiles) {
256-
const contentCheck = Object.keys(allVersions).reduce((acc, val) => {
257-
return { ...acc, [val]: { cat: [], subcat: [] } }
258-
}, {})
259-
260-
const renderOpts = { textOnly: true }
261-
262-
for (const filename of contentFiles) {
263-
const { data } = frontmatter(await fs.promises.readFile(filename, 'utf8'))
264-
const applicableVersions = getApplicableVersions(data.versions, filename)
265-
const splitPath = filename.split('/')
266-
let category = ''
267-
let subCategory = ''
268-
269-
if (splitPath[splitPath.length - 2] === 'rest') {
270-
category = data.title
271-
} else if (splitPath[splitPath.length - 3] === 'rest') {
272-
filename.includes('index.md')
273-
? (category = data.shortTitle || data.title)
274-
: (subCategory = data.shortTitle || data.title)
275-
}
276-
for (const version of applicableVersions) {
277-
req.context.currentVersion = version
278-
279-
if (category !== '')
280-
if (category.includes('{')) {
281-
await shortVersionsMiddleware(req, null, () => {})
282-
contentCheck[version].cat.push(
283-
await renderContent.liquid.parseAndRender(category, req.context, renderOpts)
284-
)
285-
} else {
286-
contentCheck[version].cat.push(category)
287-
}
288-
if (subCategory !== '')
289-
if (subCategory.includes('{')) {
290-
await shortVersionsMiddleware(req, null, () => {})
291-
contentCheck[version].subcat.push(
292-
await renderContent.liquid.parseAndRender(subCategory, req.context, renderOpts)
293-
)
294-
} else {
295-
contentCheck[version].subcat.push(subCategory)
296-
}
297-
}
298-
}
299-
return contentCheck
300-
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title: Code Scanning
3+
intro: >-
4+
Use the REST API to retrieve and update {% data
5+
variables.product.prodname_code_scanning %} alerts from a repository.
6+
versions:
7+
fpt: '*'
8+
ghae: '*'
9+
ghec: '*'
10+
ghes: '*'
11+
autogenerated: rest
12+
---
13+
14+
15+
## About code scanning
16+
17+
👋, if you're reading this, this is fixture content based on picking
18+
a single endpoint from the real REST API reference docs.
19+
This page, in particular, is different from "[AUTOTITLE](/rest/actions)"
20+
in that the sidebar shows all sub-headings directly.
21+
22+
<!-- Content after this section is automatically generated -->

tests/fixtures/content/rest/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ versions:
2020
children:
2121
- /overview
2222
- /actions
23+
- /code-scanning
2324

2425
---
2526

tests/rendering-fixtures/playwright-rendering.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,25 @@ test.describe('survey', () => {
402402
await expect(page.getByRole('button', { name: 'Send' })).not.toBeVisible()
403403
})
404404
})
405+
406+
test.describe('rest API reference pages', () => {
407+
test('REST code-scanning', async ({ page }) => {
408+
await page.goto('/rest')
409+
await page.getByRole('treeitem', { name: 'Code Scanning' }).locator('svg').click()
410+
await page.getByText('Code Scanning').click()
411+
await page.getByTestId('sidebar').getByRole('link', { name: 'About code scanning' }).click()
412+
await expect(page).toHaveURL(/\/en\/rest\/code-scanning\?apiVersion=/)
413+
await expect(page).toHaveTitle(/Code Scanning - GitHub Docs/)
414+
})
415+
test('REST actions', async ({ page }) => {
416+
await page.goto('/rest')
417+
await page.getByTestId('sidebar').getByText('Actions').click()
418+
await page.getByTestId('rest-subcategory').getByRole('link', { name: 'Artifacts' }).click()
419+
await page
420+
.getByTestId('rest-subcategory')
421+
.getByRole('link', { name: 'About artifacts in GitHub Actions' })
422+
.click()
423+
await expect(page).toHaveURL(/\/en\/rest\/actions\/artifacts\?apiVersion=/)
424+
await expect(page).toHaveTitle(/GitHub Actions Artifacts - GitHub Docs/)
425+
})
426+
})

0 commit comments

Comments
 (0)