From 6ca732f3a5c5f805b0c486b9ab07e3b8f121efa0 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Thu, 27 Apr 2023 08:03:56 -0400 Subject: [PATCH] Use fixture content test html (#36657) --- tests/rendering-fixtures/head.js | 13 +++++++++++++ tests/rendering/head.js | 29 ----------------------------- 2 files changed, 13 insertions(+), 29 deletions(-) create mode 100644 tests/rendering-fixtures/head.js delete mode 100644 tests/rendering/head.js diff --git a/tests/rendering-fixtures/head.js b/tests/rendering-fixtures/head.js new file mode 100644 index 000000000000..3cdd03297b9b --- /dev/null +++ b/tests/rendering-fixtures/head.js @@ -0,0 +1,13 @@ +import { getDOM } from '../helpers/e2etest.js' + +describe('', () => { + test('includes page intro in `description` meta tag', async () => { + const $ = await getDOM('/get-started/markdown/intro') + // The intro has Markdown syntax which becomes HTML encoded in the lead element. + const lead = $('[data-testid="lead"] p') + expect(lead.html()).toMatch('syntax') + // As a meta description its content is stripped of all HTML + const description = $('head meta[name="description"]') + expect(description.attr('content')).toBe('This intro has Markdown syntax for GitHub') + }) +}) diff --git a/tests/rendering/head.js b/tests/rendering/head.js deleted file mode 100644 index 3a4132421bb7..000000000000 --- a/tests/rendering/head.js +++ /dev/null @@ -1,29 +0,0 @@ -import { getDOM } from '../helpers/e2etest.js' -import { jest } from '@jest/globals' - -jest.useFakeTimers({ legacyFakeTimers: true }) - -describe('', () => { - jest.setTimeout(5 * 60 * 1000) - - test('includes page intro in `description` meta tag', async () => { - const $ = await getDOM('/en/articles/about-ssh') - const $description = $('meta[name="description"]') - expect($description.attr('content').startsWith('Using the SSH protocol')).toBe(true) - }) - - test('renders `description` meta tag in plaintext (no HTML)', async () => { - const $ = await getDOM('/en/articles/about-pull-request-merges') - const $description = $('meta[name="description"]') - // plain text intro - expect( - $description.attr('content').startsWith('You can merge pull requests by retaining') - ).toBe(true) - // HTML intro - expect( - $('[data-testid="lead"]') - .html() - .startsWith('

You can merge pull requests') - ) - }) -})