Skip to content

Commit

Permalink
test(viewer): add text-template test case and example
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Kiefer committed Mar 29, 2023
1 parent a1e0bdb commit 75acf11
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
53 changes: 53 additions & 0 deletions packages/form-js-viewer/test/spec/Form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import disabledSchema from './disabled.json';
import schema from './form.json';
import schemaNoIds from './form.json';
import textSchema from './text.json';
import textTemplateSchema from './text-template.json';
import stress from './stress.json';

import {
Expand Down Expand Up @@ -329,6 +330,58 @@ describe('Form', function() {
});


it('should render templated text', async function() {

// given
const data = {
users: [
{
name: 'John',
age: 25,
twitter: 'JohnCena',
skills: [
'JavaScript',
'HTML',
'CSS'
]
},
{
name: 'Jane',
age: 30,
twitter:' KermitTheFrog',
skills: [
'C#',
'Kotlin',
'Java'
]
},
{
name: 'Bob',
age: 35,
twitter: 'bobdylan',
skills:[
'Rust',
'F#',
'Fortran'
]
}
],
currencySymbol: '$'
};

// when
const form = await createForm({
container,
schema: textTemplateSchema,
data
});

// then
expect(form).to.exist;

});


describe('empty', function() {

it('should render empty', async function() {
Expand Down
9 changes: 9 additions & 0 deletions packages/form-js-viewer/test/spec/text-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"components": [
{
"type": "text",
"text": "# Employees\n{{#loop users}}\n## {{name}}\n*Currently {{age}} years old, contact* [@{{twitter}}]({{\"https://twitter.com/\" + twitter}})\n### Skills\n{{#loop skills}}\n- {{this}}\n{{/loop}}\n{{/loop}}\n# Some conditions\n{{#if count(users) > 1}}There are multiple users{{/if}}\n{{#if false}}This should not display{{/if}}\n{{#if true}}This should display{{/if}}\n*Some italic text*\n**Some bold text**\n"
}
],
"type": "default"
}

0 comments on commit 75acf11

Please sign in to comment.