1
0
mirror of synced 2025-12-23 21:07:12 -05:00

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:
Robert Sese
2021-09-22 15:33:56 -05:00
committed by GitHub
parent e4c120dfd1
commit 27eaff7caa
2 changed files with 25 additions and 1 deletions

View File

@@ -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()

View File

@@ -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'