@@ -6,8 +6,11 @@ import {
66 resolveInternalLinkKey ,
77 checkAssetLink ,
88 isAssetLink ,
9+ createLiquidContext ,
10+ extractLinksWithLiquid ,
911} from '../lib/extract-links'
1012import { latestStable } from '@/versions/lib/enterprise-server-releases'
13+ import { getFeaturesByVersion } from '@/versions/middleware/features'
1114import type { Page } from '@/types'
1215
1316describe ( 'extractLinksFromMarkdown' , ( ) => {
@@ -796,3 +799,29 @@ describe('resolveInternalLinkKey version precedence', () => {
796799 )
797800 } )
798801} )
802+
803+ describe ( 'extractLinksWithLiquid with createLiquidContext' , ( ) => {
804+ const fptFeatures = getFeaturesByVersion ( 'free-pro-team@latest' )
805+ const fptFeature = Object . keys ( fptFeatures ) . find ( ( name ) => fptFeatures [ name ] )
806+
807+ test ( 'renders version short names and feature flags for the version' , async ( ) => {
808+ expect ( fptFeature ) . toBeDefined ( )
809+ const content = `
810+ {% ifversion fpt %}[a](/x/fpt){% endif %}
811+ {% ifversion fpt or ghec %}[b](/x/b){% else %}[c](/x/c){% endif %}
812+ {% ifversion ${ fptFeature } %}[d](/x/feature){% endif %}
813+ `
814+ const result = await extractLinksWithLiquid ( content , createLiquidContext ( ) )
815+ const hrefs = result . internalLinks . map ( ( link ) => link . href )
816+
817+ expect ( hrefs ) . toEqual ( [ '/x/fpt' , '/x/b' , '/x/feature' ] )
818+ } )
819+
820+ test ( 'renders the matching branch for GHES' , async ( ) => {
821+ const content = `{% ifversion ghes %}[a](/x/ghes){% else %}[b](/x/other){% endif %}`
822+ const context = createLiquidContext ( `enterprise-server@${ latestStable } ` )
823+ const result = await extractLinksWithLiquid ( content , context )
824+
825+ expect ( result . internalLinks . map ( ( link ) => link . href ) ) . toEqual ( [ '/x/ghes' ] )
826+ } )
827+ } )
0 commit comments