67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, test, vi } from 'vitest'
|
|
|
|
import { liquid } from '@/content-render/index'
|
|
import languages from '@/languages/lib/languages-server'
|
|
import { DataDirectory } from '@/tests/helpers/data-directory'
|
|
|
|
describe('liquid helper tags', () => {
|
|
vi.setConfig({ testTimeout: 60 * 1000 })
|
|
|
|
// Using 'any' type as context is a test fixture with dynamic properties set in beforeAll
|
|
const context: any = {}
|
|
// Using 'any' type as DataDirectory is from data-directory.ts which lacks type definitions
|
|
let dd: any
|
|
const enDirBefore = languages.en.dir
|
|
|
|
beforeAll(() => {
|
|
context.currentLanguage = 'en'
|
|
dd = new DataDirectory({
|
|
data: {
|
|
reusables: {
|
|
example: 'a rose by any other name\nwould smell as sweet',
|
|
},
|
|
},
|
|
})
|
|
languages.en.dir = dd.root
|
|
})
|
|
|
|
afterAll(() => {
|
|
dd.destroy()
|
|
languages.en.dir = enDirBefore
|
|
})
|
|
|
|
describe('indented_data_reference tag', () => {
|
|
test('without any number of spaces specified', async () => {
|
|
const template = '{% indented_data_reference reusables.example %}'
|
|
const expected = ` a rose by any other name
|
|
would smell as sweet`
|
|
const output = await liquid.parseAndRender(template, context)
|
|
expect(output).toBe(expected)
|
|
})
|
|
|
|
test('with 0 spaces specified', async () => {
|
|
const template = '{% indented_data_reference reusables.example spaces=0 %}'
|
|
const expected = `a rose by any other name
|
|
would smell as sweet`
|
|
const output = await liquid.parseAndRender(template, context)
|
|
expect(output).toBe(expected)
|
|
})
|
|
|
|
test('with 0 spaces specified and whitespace around equals sign', async () => {
|
|
const template = '{% indented_data_reference reusables.example spaces = 0 %}'
|
|
const expected = `a rose by any other name
|
|
would smell as sweet`
|
|
const output = await liquid.parseAndRender(template, context)
|
|
expect(output).toBe(expected)
|
|
})
|
|
|
|
test('with 5 spaces specified', async () => {
|
|
const template = '{% indented_data_reference reusables.example spaces=5 %}'
|
|
const expected = ` a rose by any other name
|
|
would smell as sweet`
|
|
const output = await liquid.parseAndRender(template, context)
|
|
expect(output).toBe(expected)
|
|
})
|
|
})
|
|
})
|