From ccc841658fa64c28011d06642c3ebb44c2b6a03d Mon Sep 17 00:00:00 2001 From: arunkumar Date: Thu, 28 Jan 2021 11:00:25 +0530 Subject: [PATCH] Test cases added for compileHTML --- test/compileHTML.test.js | 97 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 13 deletions(-) diff --git a/test/compileHTML.test.js b/test/compileHTML.test.js index 903b626..5337183 100644 --- a/test/compileHTML.test.js +++ b/test/compileHTML.test.js @@ -1,14 +1,85 @@ const expect = require("chai").expect; -const CompileText = require("../lib/compileText"); - -// describe("Compile AST to HTML String", function () { -// it("Simple AST", function () { -// const ast = [ -// { type: 'bold', children: [ 'arun' ] }, -// { type: 'text', children: [ 'bold' ] }, -// { type: 'text', children: [ 'son' ] } -// ]; -// const expectedOutput = -// expect(CompileText(ast)).to.eql("TheKINGMaker"); -// }); -// }); +const CompileHTML = require("../lib/compileHTML"); + +describe("Compile AST to HTML String", function () { + it("Simple AST", function () { + const ast = [ + { type: "bold", children: ["my"] }, + { type: "text", children: ["simple"] }, + { type: "italics", children: ["AST"] }, + ]; + const expectedOutput = + '

mysimpleAST

'; + 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 = + '

BoldItalicsstrikethroughunderlinestrikethroughItalicsBold

'; + expect(CompileHTML(ast)).to.eql(expectedOutput); + }); + + it("Link AST", function () { + const ast = [ + { type: "url", children: ["The Feathers"], url: "feathers.studio" }, + ]; + const expectedOutput = + '

The Feathers

'; + 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 = + '

The Feathers

'; + 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 = + '

The Feathers

'; + expect(CompileHTML(ast)).to.eql(expectedOutput); + }); +});