Browse Source

Test cases added for compileHTML

develop
arunkumar 4 years ago
parent
commit
ccc841658f
  1. 97
      test/compileHTML.test.js

97
test/compileHTML.test.js

@ -1,14 +1,85 @@
const expect = require("chai").expect; const expect = require("chai").expect;
const CompileText = require("../lib/compileText"); const CompileHTML = require("../lib/compileHTML");
// describe("Compile AST to HTML String", function () { describe("Compile AST to HTML String", function () {
// it("Simple AST", function () { it("Simple AST", function () {
// const ast = [ const ast = [
// { type: 'bold', children: [ 'arun' ] }, { type: "bold", children: ["my"] },
// { type: 'text', children: [ 'bold' ] }, { type: "text", children: ["simple"] },
// { type: 'text', children: [ 'son' ] } { type: "italics", children: ["AST"] },
// ]; ];
// const expectedOutput = const expectedOutput =
// expect(CompileText(ast)).to.eql("TheKINGMaker"); '<p><span class="bold">my</span><span class="text">simple</span><span class="italics">AST</span></p>';
// }); expect(CompileHTML(ast)).to.eql(expectedOutput);
// }); });
it("Nested AST", function () {
const ast = [
{
type: "bold",
children: [
"Bold",
{
type: "italics",
children: [
"Italics",
{
type: "strikethrough",
children: [
"strikethrough",
{ type: "underline", children: ["underline"] },
"strikethrough",
],
},
"Italics",
],
},
"Bold",
],
},
];
const expectedOutput =
'<p><span class="bold">Bold<span class="italics">Italics<span class="strikethrough">strikethrough<span class="underline">underline</span>strikethrough</span>Italics</span>Bold</span></p>';
expect(CompileHTML(ast)).to.eql(expectedOutput);
});
it("Link AST", function () {
const ast = [
{ type: "url", children: ["The Feathers"], url: "feathers.studio" },
];
const expectedOutput =
'<p><a href="feathers.studio" class="url">The Feathers</a></p>';
expect(CompileHTML(ast)).to.eql(expectedOutput);
});
it("Formatted Link AST - 1", function () {
const ast = [
{
type: "url",
children: [{ type: "bold", children: ["The Feathers"] }],
url: "feathers.studio",
},
];
const expectedOutput =
'<p><a href="feathers.studio" class="url"><span class="bold">The Feathers</span></a></p>';
expect(CompileHTML(ast)).to.eql(expectedOutput);
});
it("Formatted Link AST - 2", function () {
const ast = [
{
type: "url",
children: [
{
type: "bold",
children: ["The ", { type: "underline", children: ["Feathers"] }],
},
],
url: "feathers.studio",
},
];
const expectedOutput =
'<p><a href="feathers.studio" class="url"><span class="bold">The <span class="underline">Feathers</span></span></a></p>';
expect(CompileHTML(ast)).to.eql(expectedOutput);
});
});

Loading…
Cancel
Save