More fixes for issues found by cheeks, as well as adding a test case for rendering app.
This commit is contained in:
parent
eb627c52d8
commit
d3789c9069
|
@ -1,6 +1,6 @@
|
|||
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 => {
|
||||
return char.match(ALPHA_NUMERIC_REGEX)
|
||||
|
|
|
@ -11,6 +11,13 @@ describe("Test that the string processing works correctly", () => {
|
|||
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 () => {
|
||||
let error = null
|
||||
try {
|
||||
|
|
|
@ -33,3 +33,19 @@ describe("Handling context properties with spaces in their name", () => {
|
|||
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")
|
||||
})
|
||||
})
|
|
@ -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>`)
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue