Support enterpriseServerVersions in Liquid statements (#16058)
* remove outdated and redundant context.enterpriseVersions and add new context.enterpriseServerVersions * update references from context.enterpriseVersions -> context.enterpriseServerReleases * add test * also test oldest supported enterprise version in addition to the latest * Script to update not-free-pro-team conditionals (#16060) * script to update not-free-pro-team conditionals * change string to regex so we can do replace all * remove stray test.only * Update middleware/context.js Co-authored-by: James M. Greene <JamesMGreene@github.com> * Update tests/unit/page.js Co-authored-by: James M. Greene <JamesMGreene@github.com> * Update tests/unit/page.js Co-authored-by: James M. Greene <JamesMGreene@github.com> * Update tests/fixtures/page-versioned-for-all-enterprise-releases.md Co-authored-by: James M. Greene <JamesMGreene@github.com> Co-authored-by: James M. Greene <JamesMGreene@github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const path = require('path')
|
||||
const cheerio = require('cheerio')
|
||||
const Page = require('../../lib/page')
|
||||
const allVersionIds = Object.keys(require('../../lib/all-versions'))
|
||||
const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
|
||||
const nonEnterpriseDefaultVersion = require('../../lib/non-enterprise-default-version')
|
||||
// get the `free-pro-team` segment of `free-pro-team@latest`
|
||||
@@ -121,6 +122,43 @@ describe('Page class', () => {
|
||||
const $ = cheerio.load(rendered)
|
||||
expect($('a[href="/capistrano"]').length).toBe(1)
|
||||
})
|
||||
|
||||
// Most of our Liquid versioning tests are in https://github.com/docs/render-content,
|
||||
// But they don't have access to our currently supported versions, which we're testing here.
|
||||
// This test ensures that this works as expected: {% if enterpriseServerVersions contains currentVersion %}
|
||||
test('renders the expected Enterprise Server versioned content', async () => {
|
||||
const page = new Page({
|
||||
relativePath: 'page-versioned-for-all-enterprise-releases.md',
|
||||
basePath: path.join(__dirname, '../fixtures'),
|
||||
languageCode: 'en'
|
||||
})
|
||||
// set version to the latest enteprise version
|
||||
const context = {
|
||||
currentVersion: `enterprise-server@${enterpriseServerReleases.latest}`,
|
||||
currentLanguage: 'en',
|
||||
enterpriseServerVersions: allVersionIds.filter(id => id.startsWith('enterprise-server@'))
|
||||
}
|
||||
let rendered = await page.render(context)
|
||||
let $ = cheerio.load(rendered)
|
||||
expect($.text()).toBe('This text should render on any actively supported version of Enterprise Server')
|
||||
expect($.text()).not.toBe('This text should only render on non-Enterprise')
|
||||
|
||||
// change version to the oldest enterprise version, re-render, and test again;
|
||||
// the results should be the same
|
||||
context.currentVersion = `enterprise-server@${enterpriseServerReleases.oldestSupported}`
|
||||
rendered = await page.render(context)
|
||||
$ = cheerio.load(rendered)
|
||||
expect($.text()).toBe('This text should render on any actively supported version of Enterprise Server')
|
||||
expect($.text()).not.toBe('This text should only render on non-Enterprise')
|
||||
|
||||
// change version to non-enterprise, re-render, and test again;
|
||||
// the results should be the opposite
|
||||
context.currentVersion = nonEnterpriseDefaultVersion
|
||||
rendered = await page.render(context)
|
||||
$ = cheerio.load(rendered)
|
||||
expect($.text()).not.toBe('This text should render on any actively supported version of Enterprise Server')
|
||||
expect($.text()).toBe('This text should only render on non-Enterprise')
|
||||
})
|
||||
})
|
||||
|
||||
test('preserves `languageCode`', () => {
|
||||
|
||||
Reference in New Issue
Block a user