More fixes for issues found by cheeks, as well as adding a test case for rendering app.

This commit is contained in:
mike12345567 2021-01-21 12:08:57 +00:00
parent 1dd0eb1327
commit 4deccae711
4 changed files with 57 additions and 1 deletions

View File

@ -1,6 +1,6 @@
const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
module.exports.FIND_HBS_REGEX = /{{[^}}]*}}/g module.exports.FIND_HBS_REGEX = /{{([^{}])+}}/g
module.exports.isAlphaNumeric = char => { module.exports.isAlphaNumeric = char => {
return char.match(ALPHA_NUMERIC_REGEX) return char.match(ALPHA_NUMERIC_REGEX)

View File

@ -11,6 +11,13 @@ describe("Test that the string processing works correctly", () => {
expect(output).toBe("templating is easy") expect(output).toBe("templating is easy")
}) })
it("should process a literal template", async () => {
const output = await processString("derp is {{{ adjective }}}", {
adjective: "derp"
})
expect(output).toBe("derp is derp")
})
it("should fail gracefully when wrong type passed in", async () => { it("should fail gracefully when wrong type passed in", async () => {
let error = null let error = null
try { try {

View File

@ -33,3 +33,19 @@ describe("Handling context properties with spaces in their name", () => {
expect(output).toBe("testcase 1") expect(output).toBe("testcase 1")
}) })
}) })
describe("attempt some complex problems", () => {
it("should be able to handle a very complex handlebars statement", async () => {
const context = {
"New Repeater": {
"Get Actors": {
"first_name": "Bob",
"last_name": "Bobert"
},
},
}
const hbs = "{{ New Repeater.Get Actors.first_name }} {{ New Repeater.Get Actors.last_name }}"
const output = await processString(hbs, context)
expect(output).toBe("Bob Bobert")
})
})

View File

@ -0,0 +1,33 @@
const { processString } = require("../src/index")
describe("specific test case for whether or not full app template can still be rendered", () => {
it("should be able to render the app template", async () => {
const template =
`<!doctype html>
<html>
<head>
{{{head}}}
</head>
<script>
window["##BUDIBASE_APP_ID##"] = "{{appId}}"
</script>
{{{body}}}
</html>`
const context = {
appId: "App1",
head: "<title>App</title>",
body: "<body><p>App things</p></body>"
}
const output = await processString(template, context)
expect(output).toBe(`<!doctype html>
<html>
<head>
<title>App</title>
</head>
<script>
window["##BUDIBASE_APP_ID##"] = "App1"
</script>
<body><p>App things</p></body>
</html>`)
})
})