1
0
mirror of synced 2025-12-31 06:02:42 -05:00
Files
docs/tests/unit/ghae-versioning.js

68 lines
1.6 KiB
JavaScript

import { allVersions } from '../../lib/all-versions.js'
import { liquid } from '#src/content-render/index.js'
import shortVersionsMiddleware from '../../middleware/contextualizers/short-versions.js'
const contextualize = (req) => {
req.context.currentVersionObj = req.context.allVersions[req.context.currentVersion]
shortVersionsMiddleware(req, null, () => {})
}
describe('ifversion conditionals', () => {
const req = {}
beforeAll(async () => {
req.context = {
allVersions,
currentVersion: 'github-ae@latest',
}
contextualize(req)
})
test('greater than', async () => {
const template = `
{% ifversion ghae > 3.2 %}
FOO
{% else %}
BAR
{% endif %}
`
const output = await liquid.parseAndRender(template, req.context)
expect(output.trim()).toBe('FOO')
})
test('less than', async () => {
const template = `
{% ifversion ghae < 3.2 %}
FOO
{% else %}
BAR
{% endif %}
`
const output = await liquid.parseAndRender(template, req.context)
expect(output.trim()).toBe('BAR')
})
test('Equal', async () => {
const template = `
{% ifversion ghae %}
FOO
{% else %}
BAR
{% endif %}
`
const output = await liquid.parseAndRender(template, req.context)
expect(output.trim()).toBe('FOO')
})
test('Not', async () => {
const template = `
{% ifversion not ghae %}
FOO
{% else %}
BAR
{% endif %}
`
const output = await liquid.parseAndRender(template, req.context)
expect(output.trim()).toBe('BAR')
})
})