@@ -68,140 +68,7 @@ describe('Page class', () => {
6868 } )
6969 } )
7070
71- describe . skip ( 'page.render(context)' , ( ) => {
72- test ( 'rewrites links to include the current language prefix and version' , async ( ) => {
73- const page = await Page . init ( opts )
74- const context = {
75- page : { version : `enterprise-server@${ enterpriseServerReleases . latest } ` } ,
76- currentVersion : `enterprise-server@${ enterpriseServerReleases . latest } ` ,
77- currentPath :
78- '/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches' ,
79- currentLanguage : 'en' ,
80- }
81- const rendered = await page . render ( context )
82- const $ = cheerio . load ( rendered )
83- expect (
84- page . markdown . includes (
85- '(/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)'
86- )
87- ) . toBe ( true )
88- expect (
89- page . markdown . includes (
90- '(/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)'
91- )
92- ) . toBe ( false )
93- expect (
94- $ (
95- 'a[href="/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests"]'
96- ) . length
97- ) . toBe ( 0 )
98- expect (
99- $ (
100- `a[href="/en/${ `enterprise-server@${ enterpriseServerReleases . latest } ` } /pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests"]`
101- ) . length
102- ) . toBeGreaterThan ( 0 )
103- } )
104-
105- // Much of this test is based on making sure we don't
106- // repeat the bug introduced in issue 1545.
107- test ( 'rewrites links correctly for unsupported enterprise-server links' , async ( ) => {
108- const page = await Page . init ( {
109- relativePath : 'page-with-deprecated-enterprise-links.md' ,
110- basePath : path . join ( __dirname , '../fixtures' ) ,
111- languageCode : 'en' ,
112- } )
113- const context = {
114- page : { version : `enterprise-server@${ enterpriseServerReleases . latest } ` } ,
115- currentVersion : `enterprise-server@${ enterpriseServerReleases . latest } ` ,
116- currentPath : '/en/page-with-deprecated-enterprise-links' ,
117- currentLanguage : 'en' ,
118- }
119- const rendered = await page . render ( context )
120- // That page only contains exactly 2 links. And we can know
121- // exactly what we expect each one to be.
122- const $ = cheerio . load ( rendered )
123- const first = $ ( 'a[href]' ) . first ( )
124- expect ( first . text ( ) ) . toBe ( 'Version 2.22' )
125- expect ( first . attr ( 'href' ) ) . toBe ( '/en/enterprise-server@2.22' )
126- const last = $ ( 'a[href]' ) . last ( )
127- expect ( last . text ( ) ) . toBe ( 'Version 3.2' )
128- expect ( last . attr ( 'href' ) ) . toBe ( '/en/enterprise-server@3.2' )
129- } )
130-
131- test ( 'rewrites links in the intro to include the current language prefix and version' , async ( ) => {
132- const page = await Page . init ( opts )
133- page . rawIntro =
134- '[Pull requests](/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)'
135- const context = {
136- page : { version : nonEnterpriseDefaultVersion } ,
137- currentVersion : nonEnterpriseDefaultVersion ,
138- currentPath :
139- '/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches' ,
140- currentLanguage : 'en' ,
141- }
142- // This is needed because unit tests are weird. The page.render()
143- // method is dependent on module global cache.
144- // We need to fudge the `currentPath` so it appears to be different.
145- context . currentPath += Math . random ( )
146- await page . render ( context )
147- const $ = cheerio . load ( page . intro )
148- expect (
149- $ (
150- 'a[href="/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests"]'
151- ) . length
152- ) . toBe ( 0 )
153- expect (
154- $ (
155- 'a[href="/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests"]'
156- ) . length
157- ) . toBeGreaterThan ( 0 )
158- } )
159-
160- test ( 'does not rewrite links that include deprecated enterprise release numbers' , async ( ) => {
161- const page = await Page . init ( {
162- relativePath :
163- 'admin/enterprise-management/updating-the-virtual-machine-and-physical-resources/migrating-from-github-enterprise-1110x-to-2123.md' ,
164- basePath : path . join ( __dirname , '../../content' ) ,
165- languageCode : 'en' ,
166- } )
167- const context = {
168- page : { version : `enterprise-server@${ enterpriseServerReleases . latest } ` } ,
169- currentVersion : `enterprise-server@${ enterpriseServerReleases . latest } ` ,
170- currentPath : `/en/enterprise-server@${ enterpriseServerReleases . latest } /admin/enterprise-management/migrating-from-github-enterprise-1110x-to-2123` ,
171- currentLanguage : 'en' ,
172- }
173- const rendered = await page . render ( context )
174- const $ = cheerio . load ( rendered )
175- expect (
176- page . markdown . includes (
177- '(/enterprise/11.10.340/admin/articles/upgrading-to-the-latest-release/)'
178- )
179- ) . toBe ( true )
180- expect (
181- $ (
182- `a[href="/en/enterprise-server@${ enterpriseServerReleases . latest } /11.10.340/admin/articles/upgrading-to-the-latest-release"]`
183- ) . length
184- ) . toBe ( 0 )
185- expect (
186- $ ( 'a[href="/en/enterprise/11.10.340/admin/articles/upgrading-to-the-latest-release"]' )
187- . length
188- ) . toBeGreaterThan ( 0 )
189- } )
190-
191- test ( 'does not rewrite links to external redirects' , async ( ) => {
192- const page = await Page . init ( opts )
193- page . markdown = `${ page . markdown } \n\nSee [Capistrano](/capistrano).`
194- const context = {
195- page : { version : nonEnterpriseDefaultVersion } ,
196- currentVersion : nonEnterpriseDefaultVersion ,
197- currentPath : `/en/${ nonEnterpriseDefaultVersion } /pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches` ,
198- currentLanguage : 'en' ,
199- }
200- const rendered = await page . render ( context )
201- const $ = cheerio . load ( rendered )
202- expect ( $ ( 'a[href="/capistrano"]' ) . length ) . toBe ( 1 )
203- } )
204-
71+ describe ( 'page.render(context)' , ( ) => {
20572 // Most of our Liquid versioning tests are in https://github.com/docs/render-content,
20673 // But they don't have access to our currently supported versions, which we're testing here.
20774 // This test ensures that this works as expected: {% if enterpriseServerVersions contains currentVersion %}
0 commit comments