Skip to content

Commit

Permalink
Port breadcrumbs rendering tests to fixture content (github#35143)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe authored Feb 27, 2023
1 parent b01f3d4 commit 88a7857
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 243 deletions.
13 changes: 13 additions & 0 deletions tests/fixtures/content/early-access/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Early Access documentation
hidden: true
versions: '*'
children:
- /secrets
---

👋 Hello, local test developer! This page is not visible on production.

These are the Early Access pages for {{ allVersions[currentVersion].versionTitle }}:

{{ earlyAccessPageLinks }}
7 changes: 7 additions & 0 deletions tests/fixtures/content/early-access/secrets/deeper/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Deeper secrets
versions: '*'
hidden: true
children:
- /mariana-trench
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Mariana Trench
versions: '*'
hidden: true
---

## This is a deep early-access article

Exists to test stuff like breadcrumbs.
8 changes: 8 additions & 0 deletions tests/fixtures/content/early-access/secrets/early-days.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Early days
hidden: true
versions:
fpt: '*'
---

This page is only available in **free, pro, & team**.
8 changes: 8 additions & 0 deletions tests/fixtures/content/early-access/secrets/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: GitHub Secrets
versions: '*'
hidden: true
children:
- /early-days
- /deeper
---
14 changes: 14 additions & 0 deletions tests/fixtures/content/get-started/quickstart/dynamic-title.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: '{% ifversion fpt %}Hello{% else %}Greetings{% endif %} {% data variables.product.product_name %}'
versions:
fpt: '*'
ghes: '*'
ghae: '*'
ghec: '*'
type: quick_start
---

## Introduction

This page has a single `title` and it uses Liquid that depends on
`ifversion` and `data variables...`.
1 change: 1 addition & 0 deletions tests/fixtures/content/get-started/quickstart/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ versions:
children:
- /hello-world
- /link-rewriting
- /dynamic-title
---
2 changes: 1 addition & 1 deletion tests/fixtures/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ children:
# as if the URL had been `/en/free-pro-team@latest/get-started/anything`.
- search
- get-started
- early-access
# - account-and-profile
# - authentication
# - repositories
Expand All @@ -42,7 +43,6 @@ children:
# - pages
# - education
# - desktop
# - early-access
# - support
childGroups:
- name: Get started
Expand Down
83 changes: 83 additions & 0 deletions tests/rendering-fixtures/breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { getDOM } from '../helpers/e2etest.js'

describe('breadcrumbs', () => {
test('top-level product pages have breadcrumbs and breadcrumbs should exist regardless of header or in-article', async () => {
const $ = await getDOM('/get-started')
const links = $('[data-testid=breadcrumbs-in-article] a')
expect(links.attr('class').includes('d-none')).toBe(false)
})

test('links always prefixed with language', async () => {
const $ = await getDOM('/get-started/quickstart/hello-world')
const links = $('[data-testid=breadcrumbs-in-article] a')
links.each((i, element) => {
expect($(element).attr('href').startsWith('/en/')).toBe(true)
})
expect.assertions(3)
})

test('top-level hidden /search page has no breadcrumbs', async () => {
const $ = await getDOM('/search')
const links = $('[data-testid=breadcrumbs-in-article] a')
expect(links.length).toBe(0)
const headers = $('[data-testid=breadcrumbs-header]')
expect(headers.length).toBe(0)
})

test('short titles are preferred', async () => {
const $ = await getDOM('/get-started/foo/bar')
const links = $('[data-testid=breadcrumbs-in-article] a:last-child')
expect(links.text()).toBe('Bar')
})

test('article pages have breadcrumbs in article with product, category, maptopic, and article and last breadcrumb is not viewable', async () => {
const $ = await getDOM('/get-started/quickstart/hello-world')
const links = $('[data-testid=breadcrumbs-in-article] a')
expect(links.length).toBe(3)
expect($(links[0]).text()).toBe('Get started')
expect($(links[0]).attr('class').includes('d-none')).toBe(false)
expect($(links[1]).text()).toBe('Quickstart')
expect($(links[1]).attr('class').includes('d-none')).toBe(false)
expect($(links[2]).text()).toBe('Hello World')
expect($(links[2]).attr('class').includes('d-none')).toBe(true)
})

test('works for enterprise-server articles too', async () => {
const $ = await getDOM('/enterprise-server@latest/get-started/quickstart/hello-world')
const links = $('[data-testid=breadcrumbs-in-article] a')
expect(links.length).toBe(3)
expect($(links[0]).text()).toBe('Get started')
expect($(links[1]).text()).toBe('Quickstart')
expect($(links[2]).text()).toBe('Hello World')
})

test('works for titles that depend on Liquid', async () => {
const $fpt = await getDOM('/get-started/quickstart/dynamic-title')
const fptLinks = $fpt('[data-testid=breadcrumbs-in-article] a')
expect($fpt(fptLinks[2]).text()).toBe('Hello GitHub')

const $ghec = await getDOM('/enterprise-cloud@latest/get-started/quickstart/dynamic-title')
const ghecLinks = $ghec('[data-testid=breadcrumbs-in-article] a')
expect($ghec(ghecLinks[2]).text()).toBe('Greetings GitHub Enterprise Cloud')
})

// Note, early access always work for fixture content
test('top-level product pages have breadcrumbs', async () => {
const $ = await getDOM('/early-access/secrets/deeper/mariana-trench')
expect($('[data-testid=breadcrumbs-in-article]').length).toBe(1)
expect($('[data-testid=breadcrumbs-header]').length).toBe(1)
})

test('early access article pages have breadcrumbs with product, category, and article', async () => {
const $ = await getDOM('/early-access/secrets/deeper/mariana-trench')
const $breadcrumbTitles = $(
'[data-testid=breadcrumbs-in-article] [data-testid=breadcrumb-title]'
)
const $breadcrumbLinks = $('[data-testid=breadcrumbs-in-article] a')

expect($breadcrumbTitles.length).toBe(0)
expect($breadcrumbLinks.length).toBe(2)
expect($breadcrumbLinks[0].attribs.title).toBe('Deeper secrets')
expect($breadcrumbLinks[1].attribs.title).toBe('Mariana Trench')
})
})
Loading

0 comments on commit 88a7857

Please sign in to comment.