From c02f90a06c86b8ab640f9e75897008e648af8620 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 26 Apr 2023 10:31:19 -0400 Subject: [PATCH 1/2] remove test that looked for duplicate IDs (#36626) --- tests/rendering/server.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/rendering/server.js b/tests/rendering/server.js index fea4fa8dcf..b3ea1e45f1 100644 --- a/tests/rendering/server.js +++ b/tests/rendering/server.js @@ -614,26 +614,6 @@ describe('GitHub Desktop URLs', () => { }) }) -describe('search', () => { - function findDupesInArray(arr) { - return lodash.filter(arr, (val, i, iteratee) => lodash.includes(iteratee, val, i + 1)) - } - // SKIPPING: Can we have duplicate IDs? search-input-container and search-results-container are duplicated for mobile and desktop - // Docs Engineering issue: 969 - it.skip('articles pages do not render any elements with duplicate IDs', async () => { - const $ = await getDOM('/en/articles/accessing-an-organization') - const ids = $('body') - .find('[id]') - .map((i, el) => $(el).attr('id')) - .get() - .sort() - const dupes = findDupesInArray(ids) - const message = `Oops found duplicate DOM id(s): ${dupes.join(', ')}` - expect(ids.length).toBeGreaterThan(0) - expect(dupes.length === 0, message).toBe(true) - }) -}) - describe('?json query param for context debugging', () => { it('uses query param value as a key', async () => { const res = await get('/en?json=page') From 8fd4a37d518ef438b5e8f772c9dda3be40a4cdf0 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 26 Apr 2023 10:47:33 -0400 Subject: [PATCH 2/2] test categories and map-topics with fixtures (#36627) --- .../categories-and-map-topic.js | 54 +++++++++++++ tests/rendering/server.js | 76 ------------------- 2 files changed, 54 insertions(+), 76 deletions(-) create mode 100644 tests/rendering-fixtures/categories-and-map-topic.js diff --git a/tests/rendering-fixtures/categories-and-map-topic.js b/tests/rendering-fixtures/categories-and-map-topic.js new file mode 100644 index 0000000000..0ab8d79ab1 --- /dev/null +++ b/tests/rendering-fixtures/categories-and-map-topic.js @@ -0,0 +1,54 @@ +import { getDOM, head } from '../helpers/e2etest.js' + +describe('map topics', () => { + test('get-started/quickstart map-topic', async () => { + const $ = await getDOM('/get-started/quickstart') + const lead = $('[data-search=lead]').text() + expect(lead).toMatch('Get started using GitHub to manage Git repositories') + + const links = $('[data-testid=table-of-contents] a[href]') + expect(links.length).toBeGreaterThan(0) + // They all have the same prefix + const hrefs = links.map((i, el) => $(el).attr('href')).get() + expect(hrefs.every((href) => href.startsWith('/en/get-started/quickstart/'))).toBeTruthy() + // The all resolve to a 200 OK without redirects + const responses = await Promise.all(hrefs.map((href) => head(href))) + expect(responses.every((r) => r.statusCode === 200)).toBeTruthy() + }) + + test('actions/category/map-topic map-topic has its articles intro', async () => { + const $ = await getDOM('/actions/category/map-topic') + const lead = $('[data-search=lead]').text() + expect(lead).toMatch("Here's the intro for GitHub Actions.") + + const links = $('[data-testid=table-of-contents] a[href]') + const hrefs = links.map((i, el) => $(el).attr('href')).get() + expect(hrefs.every((href) => href.startsWith('/en/actions/category/'))).toBeTruthy() + + const firstArticleH2 = $('[data-testid=table-of-contents] h2').first() + expect(firstArticleH2.text()).toMatch('Article title') + + const firstArticleIntro = $('[data-testid=table-of-contents] p').first() + // Its HTML in the intro is escaped and Markdown converted + expect(firstArticleIntro.html()).toMatch( + 'This page uses < and > in the title and shortTitle' + ) + }) +}) + +describe('categories', () => { + test('actions/category map-topic', async () => { + const $ = await getDOM('/actions/category') + const lead = $('[data-search=lead]').text() + expect(lead).toMatch('Learn how to migrate your existing CI/CD') + + const links = $('[data-testid=table-of-contents] a[href]') + expect(links.length).toBeGreaterThan(0) + // They all have the same prefix + const hrefs = links.map((i, el) => $(el).attr('href')).get() + expect(hrefs.every((href) => href.startsWith('/en/actions/category/'))).toBeTruthy() + // The all resolve to a 200 OK without redirects + const responses = await Promise.all(hrefs.map((href) => head(href))) + expect(responses.every((r) => r.statusCode === 200)).toBeTruthy() + }) +}) diff --git a/tests/rendering/server.js b/tests/rendering/server.js index b3ea1e45f1..8f324f700d 100644 --- a/tests/rendering/server.js +++ b/tests/rendering/server.js @@ -473,52 +473,6 @@ describe('server', () => { expect(res.headers['cache-control']).toMatch(/max-age=\d+/) }) }) - - describe('categories and map topics', () => { - test('adds links to map topics on a category homepage', async () => { - const $ = await getDOM('/en/get-started/writing-on-github') - expect( - $( - 'a[href="/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github"]' - ).length - ).toBe(1) - expect($('a[href="#managing-user-account-settings"]').length).toBe(0) - }) - - test('category page renders with TOC', async () => { - const $ = await getDOM('/en/get-started/writing-on-github') - expect($('[data-testid=table-of-contents] ul li a').length).toBeGreaterThan(5) - }) - - test('map topic renders with links to articles', async () => { - const $ = await getDOM( - '/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github' - ) - expect( - $( - 'li h2 a[href="/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/quickstart-for-writing-on-github"]' - ).length - ).toBe(1) - }) - - test('map topic renders with one intro for every h2', async () => { - const $ = await getDOM('/en/get-started/writing-on-github/working-with-advanced-formatting') - const $links = $('[data-testid=expanded-item]') - expect($links.length).toBeGreaterThan(3) - }) - - test('map topic intros are parsed', async () => { - const $ = await getDOM('/en/get-started/writing-on-github/working-with-advanced-formatting') - const $parent = $('[data-testid=expanded-item] a[href*="organizing-information-with-tables"]') - .parent() - .parent() - const $intro = $('p', $parent) - expect($intro.length).toBe(1) - expect($intro.html()).toContain( - 'You can build tables to organize information in comments, issues, pull requests, and wikis.' - ) - }) - }) }) describe('GitHub Enterprise URLs', () => { @@ -584,36 +538,6 @@ describe('GitHub Enterprise URLs', () => { }) }) -describe('GitHub Desktop URLs', () => { - test('renders the GitHub Desktop homepage with correct links', async () => { - const $ = await getDOM('/en/desktop') - expect($('a[href^="/en/desktop/"]').length).toBeGreaterThan(1) - }) - - test('renders a Desktop category with expected links', async () => { - const $ = await getDOM('/en/desktop/installing-and-configuring-github-desktop') - expect( - $('a[href^="/en/desktop/installing-and-configuring-github-desktop/"]').length - ).toBeGreaterThan(1) - }) - - test('renders a Desktop map topic', async () => { - const $ = await getDOM( - '/en/desktop/installing-and-configuring-github-desktop/installing-and-authenticating-to-github-desktop' - ) - expect( - $('a[href^="/en/desktop/installing-and-configuring-github-desktop/"]').length - ).toBeGreaterThan(1) - }) - - test('renders a Desktop article within a map topic', async () => { - const res = await get( - '/en/desktop/installing-and-configuring-github-desktop/installing-and-authenticating-to-github-desktop/installing-github-desktop' - ) - expect(res.statusCode).toBe(200) - }) -}) - describe('?json query param for context debugging', () => { it('uses query param value as a key', async () => { const res = await get('/en?json=page')