@@ -6,6 +6,7 @@ import { loadPages } from '../../lib/page-data.js'
66import CspParse from 'csp-parse'
77import { productMap } from '../../lib/all-products.js'
88import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
9+ import { getPathWithoutVersion } from '../../lib/path-utils.js'
910import { describe , jest } from '@jest/globals'
1011
1112const AZURE_STORAGE_URL = 'githubdocs.azureedge.net'
@@ -79,21 +80,24 @@ describe('server', () => {
7980
8081 test ( 'renders the Enterprise homepages with links to expected products in both the sidebar and page body' , async ( ) => {
8182 const enterpriseProducts = [
82- `/en/ enterprise-server@${ enterpriseServerReleases . latest } ` ,
83- '/en/ enterprise-cloud@latest' ,
83+ `enterprise-server@${ enterpriseServerReleases . latest } ` ,
84+ 'enterprise-cloud@latest' ,
8485 ]
8586
86- enterpriseProducts . forEach ( async ( ep ) => {
87- const $ = await getDOM ( ep )
87+ for ( const ep of enterpriseProducts ) {
88+ const $ = await getDOM ( `/en/ ${ ep } ` )
8889 const sidebarItems = $ ( '[data-testid=sidebar] li a' ) . get ( )
8990 const sidebarTitles = sidebarItems . map ( ( el ) => $ ( el ) . text ( ) . trim ( ) )
9091 const sidebarHrefs = sidebarItems . map ( ( el ) => $ ( el ) . attr ( 'href' ) )
91- const productItems = $ ( '[data-testid=product] div a' ) . get ( )
92- const productTitles = productItems . map ( ( el ) => $ ( el ) . text ( ) . trim ( ) )
93- const productHrefs = productItems . map ( ( el ) => $ ( el ) . attr ( 'href' ) )
92+ const productItems = activeProducts . filter (
93+ ( prod ) => prod . external || prod . versions . includes ( ep )
94+ )
95+ const productTitles = productItems . map ( ( prod ) => prod . name )
96+ const productHrefs = productItems . map ( ( prod ) =>
97+ prod . external ? prod . href : `/en/${ ep } ${ getPathWithoutVersion ( prod . href ) } `
98+ )
9499
95100 const titlesInProductsButNotSidebar = lodash . difference ( productTitles , sidebarTitles )
96-
97101 const hrefsInProductsButNotSidebar = lodash . difference ( productHrefs , sidebarHrefs )
98102
99103 expect (
@@ -104,7 +108,7 @@ describe('server', () => {
104108 hrefsInProductsButNotSidebar . length ,
105109 `Found hrefs missing from sidebar: ${ hrefsInProductsButNotSidebar . join ( ', ' ) } `
106110 ) . toBe ( 0 )
107- } )
111+ }
108112 } )
109113
110114 test ( 'sets Content Security Policy (CSP) headers' , async ( ) => {
0 commit comments