Skip to content

Commit

Permalink
Added unit test cases for markupParser utils (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavj2111 authored Oct 14, 2024
1 parent 99c92f4 commit acfdaf4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
45 changes: 45 additions & 0 deletions __tests__/utils/markupParser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect, it, describe, beforeEach, jest } from "@jest/globals";
import { parseMarkupMessage } from "../../src/utils/markupParser";

describe("", ()=>{
beforeEach(()=>{
jest.clearAllMocks();
});

it("should be able to parse a plain string without tags", ()=>{
const result = "This is a plain string";
const message = parseMarkupMessage(result);

expect(message).toEqual(["T", "h", "i", "s", " ", "i", "s", " ", "a", " ", "p", "l", "a", "i", "n", " ", "s", "t", "r", "i", "n", "g"]);
});

it("should be able to parse a plain string with tags", ()=>{
const result = "<div>This is a plain string</div>";
const message = parseMarkupMessage(result);

expect(message).toEqual(["<div>", "T", "h", "i", "s", " ", "i", "s", " ", "a", " ", "p", "l", "a", "i", "n", " ", "s", "t", "r", "i", "n", "g", "</div>"]);
});

it("should be able to parse nested tags", ()=>{
const result = "<div> This contains a <bold>Bold</bold> tag</div>";
const message = parseMarkupMessage(result);

expect(message).toEqual(["<div>", " ", "T", "h", "i", "s", " ", "c", "o", "n", "t", "a", "i", "n", "s", " ", "a", " ", "<bold>", "B", "o", "l", "d", "</bold>", " ", "t", "a", "g", "</div>"]);
});

it("should be able to parse attributes in tags", ()=>{
const result = "<a href=`http://www.example.com`>Link</a>";
const message= parseMarkupMessage(result);

expect(message).toEqual(["<a href=`http://www.example.com`>", "L", "i", "n", "k", "</a>"] );
});

it("should be able to parse unclosed tags", ()=>{
const result = "<div> This tag is unclosed";
const message = parseMarkupMessage(result);

expect(message).toEqual(["<div>", " ", "T", "h", "i", "s", " ", "t", "a", "g", " ", "i", "s", " ", "u", "n", "c", "l", "o", "s", "e", "d"] );
});


})
2 changes: 1 addition & 1 deletion __tests__/utils/messageBuilder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";

import { expect, it, describe, beforeEach, jest } from "@jest/globals";
import { createMessage } from "../../src/utils/messageBuilder";
import { generateSecureUUID } from "../../src/utils/idGenerator";

Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit acfdaf4

Please sign in to comment.