| | import { beforeAll, describe, expect, test } from 'vitest' |
| |
|
| | import { get } from '@/tests/helpers/e2etest' |
| |
|
| | const makeURL = (pathname: string) => `/api/article/body?${new URLSearchParams({ pathname })}` |
| |
|
| | describe('article body api', () => { |
| | beforeAll(() => { |
| | |
| | |
| | |
| | if (!process.env.ROOT) { |
| | console.warn( |
| | 'WARNING: The articlebody tests require the ROOT environment variable to be set to the fixture root', |
| | ) |
| | } |
| | |
| | if (!process.env.TRANSLATIONS_FIXTURE_ROOT) { |
| | console.warn( |
| | 'WARNING: The articlebody tests require the TRANSLATIONS_FIXTURE_ROOT environment variable to be set', |
| | ) |
| | } |
| | }) |
| |
|
| | test('happy path', async () => { |
| | const res = await get(makeURL('/en/get-started/start-your-journey/api-article-body-test-page')) |
| | expect(res.statusCode).toBe(200) |
| | expect(res.headers['content-type']).toContain('text/markdown') |
| | expect(res.body).toContain('## About GitHub') |
| | expect(res.body).toContain('## About Git') |
| | expect(res.body).toMatch(/^#+\s+\w+/m) |
| |
|
| | expect(res.headers['set-cookie']).toBeUndefined() |
| | expect(res.headers['cache-control']).toContain('public') |
| | expect(res.headers['cache-control']).toMatch(/max-age=[1-9]/) |
| | expect(res.headers['surrogate-control']).toContain('public') |
| | expect(res.headers['surrogate-control']).toMatch(/max-age=[1-9]/) |
| | }) |
| |
|
| | test('a pathname that does not exist', async () => { |
| | const res = await get(makeURL('/en/never/heard/of')) |
| | expect(res.statusCode).toBe(404) |
| | const { error } = JSON.parse(res.body) |
| | expect(error).toBe("No page found for '/en/never/heard/of'") |
| | }) |
| |
|
| | test("no 'pathname' query string at all", async () => { |
| | const res = await get('/api/article/body') |
| | expect(res.statusCode).toBe(400) |
| | const { error } = JSON.parse(res.body) |
| | expect(error).toBe("No 'pathname' query") |
| | }) |
| |
|
| | test('has proper markdown structure with frontmatter removed', async () => { |
| | const res = await get(makeURL('/en/get-started/start-your-journey/api-article-body-test-page')) |
| |
|
| | expect(res.statusCode).toBe(200) |
| | |
| | expect(res.body).not.toMatch(/^---/) |
| | |
| | expect(res.body).toMatch(/^#{1,6}\s+\w+/m) |
| | }) |
| |
|
| | test("empty 'pathname' query string", async () => { |
| | const res = await get('/api/article/body?pathname=%20') |
| | expect(res.statusCode).toBe(400) |
| | const { error } = JSON.parse(res.body) |
| | expect(error).toBe("'pathname' query empty") |
| | }) |
| |
|
| | test('repeated pathname query string key', async () => { |
| | const res = await get('/api/article/body?pathname=a&pathname=b') |
| | expect(res.statusCode).toBe(400) |
| | const { error } = JSON.parse(res.body) |
| | expect(error).toBe("Multiple 'pathname' keys") |
| | }) |
| |
|
| | test('tool picker shows all tool variants in markdown', async () => { |
| | const res = await get(makeURL('/en/get-started/liquid/tool-specific')) |
| | expect(res.statusCode).toBe(200) |
| | expect(res.headers['content-type']).toContain('text/markdown') |
| |
|
| | |
| | expect(res.body).toContain('<div class="ghd-tool webui">') |
| | expect(res.body).toContain('<div class="ghd-tool cli">') |
| | expect(res.body).toContain('<div class="ghd-tool desktop">') |
| |
|
| | |
| | expect(res.body).toContain('This is webui content') |
| | expect(res.body).toContain('This is cli content') |
| | expect(res.body).toContain('This is desktop content') |
| |
|
| | |
| | expect(res.body).toContain('Webui section specific content') |
| | expect(res.body).toContain('Desktop section specific content') |
| |
|
| | |
| | const webuiMatches = res.body.match(/<div class="ghd-tool webui">/g) |
| | const desktopMatches = res.body.match(/<div class="ghd-tool desktop">/g) |
| | expect(webuiMatches).toBeDefined() |
| | expect(webuiMatches!.length).toBeGreaterThan(1) |
| | expect(desktopMatches).toBeDefined() |
| | expect(desktopMatches!.length).toBeGreaterThan(1) |
| | }) |
| |
|
| | test('codespaces tool content is included in markdown API', async () => { |
| | const res = await get(makeURL('/en/get-started/liquid/tool-picker-issue')) |
| | expect(res.statusCode).toBe(200) |
| | expect(res.headers['content-type']).toContain('text/markdown') |
| |
|
| | |
| | expect(res.body).toContain('<div class="ghd-tool webui">') |
| | expect(res.body).toContain('<div class="ghd-tool codespaces">') |
| |
|
| | |
| | expect(res.body).toContain('Under your repository name, click **Pull requests**') |
| | expect(res.body).toContain('Open the pull request in your codespace') |
| | expect(res.body).toContain( |
| | 'After reviewing the files, you can submit your review from the web interface', |
| | ) |
| | expect(res.body).toContain( |
| | 'After reviewing the files, you can submit your review directly from Codespaces', |
| | ) |
| |
|
| | |
| | const webuiMatches = res.body.match(/<div class="ghd-tool webui">/g) |
| | const codespacesMatches = res.body.match(/<div class="ghd-tool codespaces">/g) |
| | expect(webuiMatches).toBeDefined() |
| | expect(webuiMatches!.length).toBe(2) |
| | expect(codespacesMatches).toBeDefined() |
| | expect(codespacesMatches!.length).toBe(2) |
| | }) |
| |
|
| | test('codespaces content included in production markdown API', async () => { |
| | |
| | const res = await get( |
| | makeURL( |
| | '/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request', |
| | ), |
| | ) |
| |
|
| | |
| | if (res.statusCode === 404) { |
| | console.log('Production page not available in fixture environment, skipping test') |
| | return |
| | } |
| |
|
| | expect(res.statusCode).toBe(200) |
| |
|
| | |
| | const hasCodespacesContent = res.body.includes('<div class="ghd-tool codespaces">') |
| | expect(hasCodespacesContent).toBe(true) |
| |
|
| | |
| | expect(res.body).toContain('<div class="ghd-tool webui">') |
| | }) |
| |
|
| | test('verifies original issue #5400 is resolved', async () => { |
| | |
| | |
| | const res = await get( |
| | makeURL( |
| | '/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/reviewing-proposed-changes-in-a-pull-request', |
| | ), |
| | ) |
| |
|
| | |
| | if (res.statusCode === 404) { |
| | console.log( |
| | 'Production page not available in fixture environment, skipping issue verification test', |
| | ) |
| | return |
| | } |
| |
|
| | expect(res.statusCode).toBe(200) |
| | expect(res.headers['content-type']).toContain('text/markdown') |
| |
|
| | |
| | expect(res.body).toContain('<div class="ghd-tool webui">') |
| | expect(res.body).toContain('<div class="ghd-tool codespaces">') |
| |
|
| | |
| | expect(res.body).toContain('GitHub Codespaces') |
| | expect(res.body).toContain('Open the pull request in a codespace') |
| |
|
| | |
| | const webuiMatches = res.body.match(/<div class="ghd-tool webui">/g) |
| | const codespacesMatches = res.body.match(/<div class="ghd-tool codespaces">/g) |
| |
|
| | expect(webuiMatches).toBeDefined() |
| | expect(codespacesMatches).toBeDefined() |
| | expect(codespacesMatches!.length).toBeGreaterThan(0) |
| |
|
| | console.log('✅ Issue #5400 resolved: All tool picker content now included in Markdown API') |
| | }) |
| | }) |
| |
|