Skip to content

Commit 0f0f038

Browse files
Test page titles (#1800)
* Remove one off test for command line title * write tests to check h1 page title against clicked link * fix syntax err in table of contents when running in cypress open * package-lock * Fix page titles that were incorrect - caught in tests
1 parent 2f9b5d5 commit 0f0f038

File tree

18 files changed

+5112
-5080
lines changed

18 files changed

+5112
-5080
lines changed

cypress/integration/i18n_spec.js

-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ describe('i18n', () => {
77
cy.url().should('contain', 'why-cypress')
88
})
99

10-
it('uses English in Command Line guide', () => {
11-
cy.visit('/guides/guides/command-line.html')
12-
cy.document().its('documentElement.lang').should('equal', 'en')
13-
cy.get('meta[property="og:title"]').invoke('attr', 'content').should('equal', 'Command Line')
14-
cy.contains('h1', 'Command Line')
15-
})
16-
1710
context('language select', () => {
1811
it('selects English by default', () => {
1912
cy.get('#lang-select').find('option')

cypress/integration/page_header_spec.js

+52
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,60 @@
1+
const YAML = require('yamljs')
2+
const _ = require('lodash')
3+
14
describe('Page Header', () => {
25
beforeEach(() => {
36
cy.server()
47
})
58

9+
it('displays correct page title', function () {
10+
cy.wrap(this.langValues).each(function (lang) {
11+
let sidebarYaml = 'source/_data/sidebar.yml'
12+
let visitUrlPrefix = ''
13+
14+
if (lang !== 'en') {
15+
sidebarYaml = `source/${lang}/_data/sidebar.yml`
16+
visitUrlPrefix = lang
17+
}
18+
19+
cy.wrap(this.MAIN_NAV).each((nav) => {
20+
// the Plugin docs doesn't have a sidebar
21+
// the API docs don't really need translations (since it's all commands)
22+
if (nav.name === 'Plugins' || nav.name === 'API') return
23+
24+
cy.readFile(sidebarYaml)
25+
.then(function (yamlString) {
26+
this.navName = _.toLower(nav.name)
27+
28+
this.sidebar = YAML.parse(yamlString)
29+
this.sidebarTitles = _.keys(this.sidebar[this.navName])
30+
31+
this.sidebarLinkNames = _.reduce(this.sidebar[this.navName], (memo, nestedObj) => memo.concat(_.keys(nestedObj))
32+
, [])
33+
34+
this.sidebarLinks = _.reduce(this.sidebar[this.navName], (memo, nestedObj) => memo.concat(_.values(nestedObj))
35+
, [])
36+
37+
cy.visit(`${visitUrlPrefix}${nav.path}.html`)
38+
39+
cy.get('.sidebar-link')
40+
.each(($linkElement) => {
41+
cy.request(`${$linkElement[0].href}`).its('body')
42+
.then((body) => {
43+
const page = _.last($linkElement[0].href.split('/'))
44+
45+
if (page !== 'assertions.html') {
46+
const $body = Cypress.$(body)
47+
const $h1 = $body.find('h1.article-title')
48+
49+
expect($h1.text(), `Page title '${$h1.text()}' in ${page} matches translated title in ${lang}.yml`).to.eq($linkElement.text().trim())
50+
}
51+
})
52+
})
53+
})
54+
})
55+
})
56+
})
57+
658
it('should have link to edit doc', function () {
759
cy.wrap(this.MAIN_NAV).each((nav) => {
860
let path = `${nav.path}.html`

cypress/integration/sidebar_spec.js

-6
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ context('Sidebar', () => {
2020
})
2121

2222
context('Titles and links', () => {
23-
beforeEach(() => {
24-
25-
})
26-
2723
it('displays titles and links in sidebar', function () {
2824
cy.wrap(this.langValues).each(function (lang) {
2925
let sidebarYaml = 'source/_data/sidebar.yml'
@@ -71,8 +67,6 @@ context('Sidebar', () => {
7167
})
7268
})
7369
})
74-
75-
7670
})
7771
})
7872
})

cypress/integration/table_of_contents.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const GUIDES_PATH = '/guides/overview/why-cypress.html'
33
const API_PATH = '/api/api/table-of-contents'
44

55
describe('Table of Contents', () => {
6-
beforeEach(() => {
6+
beforeEach(function () {
77
//# skip running this test if we are in interactive mode
88
if (Cypress.config('isInteractive')) {
99
this.skip()

0 commit comments

Comments
 (0)