Handle learning track URL redirects (#21613)
* Handle redirects for learning tracks * Test for learning track URL redirects * Test latest Enterprise version Co-authored-by: Rachael Sewell <rachmari@github.com> Co-authored-by: Rachael Sewell <rachmari@github.com>
This commit is contained in:
@@ -21,7 +21,19 @@ export default async function learningTrack(req, res, next) {
|
||||
const currentLearningTrack = { trackName }
|
||||
|
||||
const guidePath = getPathWithoutLanguage(getPathWithoutVersion(req.pagePath))
|
||||
const guideIndex = track.guides.findIndex((path) => path === guidePath)
|
||||
let guideIndex = track.guides.findIndex((path) => path === guidePath)
|
||||
|
||||
if (guideIndex < 0) {
|
||||
// Also check if the learning track URL is now a redirect to the requested
|
||||
// page, we still want to render the learning track banner in that case.
|
||||
for (const redirect of req.context.page.redirect_from) {
|
||||
track.guides.forEach((path, i) => {
|
||||
if (path === redirect) {
|
||||
guideIndex = i
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (guideIndex < 0) return noTrack()
|
||||
|
||||
|
||||
@@ -50,6 +50,18 @@ describe.skip('navigation banner', () => {
|
||||
})
|
||||
})
|
||||
|
||||
test('render navigation banner when url is a redirect to a learning track URL', async () => {
|
||||
const $ = await getDOM(
|
||||
'/enterprise/admin/enterprise-management/enabling-automatic-update-checks?learn=upgrade_your_instance'
|
||||
)
|
||||
expect($('[data-testid=learning-track-nav]')).toHaveLength(1)
|
||||
const $navLinks = $('[data-testid=learning-track-nav] a')
|
||||
expect($navLinks).toHaveLength(1)
|
||||
$navLinks.each((i, elem) => {
|
||||
expect($(elem).attr('href')).toEqual(expect.stringContaining('?learn=upgrade_your_instance'))
|
||||
})
|
||||
})
|
||||
|
||||
test('does not include banner when url does not include `learn` param', async () => {
|
||||
const $ = await getDOM(
|
||||
'/en/actions/guides/setting-up-continuous-integration-using-workflow-templates'
|
||||
|
||||
Reference in New Issue
Block a user