Skip to content

Commit 4be15f7

Browse files
authored
account for paths with or without version (#17443)
1 parent f9b1823 commit 4be15f7

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

lib/liquid-tags/link.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const Liquid = require('liquid')
44
const liquid = new Liquid.Engine()
55
const LiquidTag = require('./liquid-tag')
66
const findPage = require('../find-page')
7-
const { getPathWithoutLanguage } = require('../path-utils')
7+
const { getPathWithoutLanguage, getPathWithoutVersion } = require('../path-utils')
88
const getApplicableVersions = require('../get-applicable-versions')
99
const removeFPTFromPath = require('../remove-fpt-from-path')
1010

@@ -74,7 +74,7 @@ module.exports = class Link extends LiquidTag {
7474
}
7575

7676
// add language code and version
77-
fullPath = removeFPTFromPath(path.posix.join('/', ctx.currentLanguage, ctx.currentVersion, getPathWithoutLanguage(fullPath)))
77+
fullPath = removeFPTFromPath(path.posix.join('/', ctx.currentLanguage, ctx.currentVersion, getPathWithoutLanguage(getPathWithoutVersion(fullPath))))
7878

7979
// find the page based on the full path
8080
const page = findPage(fullPath, ctx.pages, ctx.redirects)

lib/path-utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ function getPathWithoutLanguage (href) {
2222

2323
// Remove the version segment from the path
2424
function getPathWithoutVersion (href) {
25-
return href.replace(`/${getVersionStringFromPath(href)}`, '')
25+
const versionFromPath = getVersionStringFromPath(href)
26+
27+
// If the derived version is not found in the list of all versions, just return the HREF
28+
return allVersions[versionFromPath]
29+
? href.replace(`/${getVersionStringFromPath(href)}`, '')
30+
: href
2631
}
2732

2833
// Return the version segment in a path

tests/browser/browser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* global page, browser */
22
const sleep = require('await-sleep')
33
const querystring = require('querystring')
4+
const { latest } = require('../../lib/enterprise-server-releases')
45

56
describe('homepage', () => {
67
jest.setTimeout(60 * 1000)
@@ -235,6 +236,17 @@ describe('card filters', () => {
235236
expect(shownCards.length).toBeGreaterThan(0)
236237
})
237238

239+
it('works with select input on an Enterprise version', async () => {
240+
await page.goto(`http://localhost:4001/en/enterprise-server@${latest}/actions/guides`)
241+
await page.select('.js-filter-card-filter-dropdown[name="type"]', 'overview')
242+
const shownCards = await page.$$('.js-filter-card:not(.d-none)')
243+
const shownCardsAttrib = await page.$$eval('.js-filter-card:not(.d-none)', cards =>
244+
cards.map(card => card.dataset.type)
245+
)
246+
shownCardsAttrib.map(attrib => expect(attrib).toBe('overview'))
247+
expect(shownCards.length).toBeGreaterThan(0)
248+
})
249+
238250
it('shows more cards', async () => {
239251
await page.goto('http://localhost:4001/en/actions')
240252
const maxCards = await page.$eval('.js-filter-card-show-more', btn => parseInt(btn.dataset.jsFilterCardMax))

0 commit comments

Comments
 (0)