Skip to content

Commit

Permalink
fixed test and new test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sempai-07 committed Aug 6, 2023
1 parent 838a74b commit 8e312ef
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 290 deletions.
6 changes: 3 additions & 3 deletions test/collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,9 @@ test("Testing the `chunk` method - splits the collection into subcollections of
const result = collection.chunk(1);

expect(result).toEqual([
new Collection([[0, "value1"]]),
new Collection([[0, "value2"]]),
new Collection([[0, "value3"]]),
[0, "value1"],
[0, "value2"],
[0, "value3"],
]);
});

Expand Down
168 changes: 27 additions & 141 deletions test/html.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,168 +3,54 @@ const {
italic,
underline,
strikethrough,
code,
spoiler,
link,
image,
paragraph,
list,
codeBlock,
emoji,
inlineCode,
preFormattedCode,
preFormattedCodeWithLanguage,
} = require("../dist/index").html;

const { ParameterError } = require("../dist/errorcollection");

describe("bold", () => {
test("should format text as bold", () => {
const text = "Hello, world!";
const result = bold(text);
expect(result).toBe("<b>Hello, world!</b>");
describe('Text formatting functions', () => {
test('bold()', () => {
expect(bold('Hello')).toBe('<b>Hello</b>');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
bold();
}).toThrow(ParameterError);
test('italic()', () => {
expect(italic('Hello')).toBe('<i>Hello</i>');
});
});

describe("italic", () => {
test("should format text as italic", () => {
const text = "Hello, world!";
const result = italic(text);
expect(result).toBe("<i>Hello, world!</i>");
test('underline()', () => {
expect(underline('Hello')).toBe('<u>Hello</u>');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
italic();
}).toThrow(ParameterError);
test('strikethrough()', () => {
expect(strikethrough('Hello')).toBe('<s>Hello</s>');
});
});

describe("underline", () => {
test("should format text as underlined", () => {
const text = "Hello, world!";
const result = underline(text);
expect(result).toBe("<u>Hello, world!</u>");
test('spoiler()', () => {
expect(spoiler('Hello')).toBe('<span class="tg-spoiler">Hello</span>');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
underline();
}).toThrow(ParameterError);
test('link()', () => {
expect(link('ChatGPT', 'https://example.com')).toBe('<a href="https://example.com">ChatGPT</a>');
});
});

describe("strikethrough", () => {
test("should format text as strikethrough", () => {
const text = "Hello, world!";
const result = strikethrough(text);
expect(result).toBe("<s>Hello, world!</s>");
test('emoji()', () => {
expect(emoji('123', '😀')).toBe('<tg-emoji emoji-id="123">😀</tg-emoji>');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
strikethrough();
}).toThrow(ParameterError);
test('inlineCode()', () => {
expect(inlineCode('const a = 5;')).toBe('<code>const a = 5;</code>');
});
});

describe("code", () => {
test("should format text as inline code", () => {
const text = 'console.log("Hello, world!");';
const result = code(text);
expect(result).toBe('<code>console.log("Hello, world!");</code>');
test('preFormattedCode()', () => {
expect(preFormattedCode('const a = 5;', 'javascript')).toBe('<pre>const a = 5;</pre>');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
code();
}).toThrow(ParameterError);
});
});

describe("link", () => {
test("should create a hyperlink", () => {
const text = "OpenAI";
const url = "https://openai.com";
const result = link(text, url);
expect(result).toBe('<a href="https://openai.com">OpenAI</a>');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
link(undefined, "https://openai.com");
}).toThrow(ParameterError);
});

test("should throw ParameterError if url is missing", () => {
expect(() => {
link("OpenAI", undefined);
}).toThrow(ParameterError);
});
});

describe("image", () => {
test("should create an image element", () => {
const url = "https://example.com/image.jpg";
const alt = "Example Image";
const result = image(url, alt);
expect(result).toBe(
'<img src="https://example.com/image.jpg" alt="Example Image">',
test('preFormattedCodeWithLanguage()', () => {
expect(preFormattedCodeWithLanguage('const a = 5;', 'javascript')).toBe(
'<pre><code class="language-javascript">const a = 5;</code></pre>'
);
});

test("should throw ParameterError if url is missing", () => {
expect(() => {
image(undefined, "Example Image");
}).toThrow(ParameterError);
});
});

describe("paragraph", () => {
test("should create a paragraph element", () => {
const text = "This is a paragraph.";
const result = paragraph(text);
expect(result).toBe("This is a paragraph.\n\n");
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
paragraph();
}).toThrow(ParameterError);
});
});

describe("list", () => {
test("should create an unordered list", () => {
const items = ["Item 1", "Item 2", "Item 3"];
const result = list(items);
expect(result).toBe("* Item 1\n* Item 2\n* Item 3\n\n");
});

test("should create an ordered list", () => {
const items = ["Item 1", "Item 2", "Item 3"];
const result = list(items, true);
expect(result).toBe("1. Item 1\n1. Item 2\n1. Item 3\n\n");
});

test("should throw ParameterError if items is missing", () => {
expect(() => {
list(undefined);
}).toThrow(ParameterError);
});
});

describe("codeBlock", () => {
test("should create a code block element", () => {
const code = 'function sayHello() {\n console.log("Hello, world!");\n}';
const result = codeBlock(code);
expect(result).toBe(`<pre><code class="language-">${code}</code></pre>`);
});

test("should throw ParameterError if code is missing", () => {
expect(() => {
codeBlock();
}).toThrow(ParameterError);
});
});
166 changes: 20 additions & 146 deletions test/markdownv.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,168 +3,42 @@ const {
italic,
underline,
strikethrough,
code,
link,
image,
paragraph,
list,
spoiler,
inlineCode,
codeBlock,
codeBlockWithLanguage,
} = require("../dist/index").markdownv;

const { ParameterError } = require("../dist/errorcollection");

describe("bold", () => {
test("should format text as bold", () => {
const text = "Hello, world!";
const result = bold(text);
expect(result).toBe("**Hello, world!**");
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
bold();
}).toThrow(ParameterError);
});
});

describe("italic", () => {
test("should format text as italic", () => {
const text = "Hello, world!";
const result = italic(text);
expect(result).toBe("_Hello, world!_");
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
italic();
}).toThrow(ParameterError);
});
});

describe("underline", () => {
test("should format text as underlined", () => {
const text = "Hello, world!";
const result = underline(text);
expect(result).toBe("__Hello, world!__");
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
underline();
}).toThrow(ParameterError);
});
});

describe("strikethrough", () => {
test("should format text as strikethrough", () => {
const text = "Hello, world!";
const result = strikethrough(text);
expect(result).toBe("~~Hello, world!~~");
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
strikethrough();
}).toThrow(ParameterError);
});
});

describe("code", () => {
test("should format text as inline code", () => {
const text = 'console.log("Hello, world!");';
const result = code(text);
expect(result).toBe('```\nconsole.log("Hello, world!");\n```');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
code();
}).toThrow(ParameterError);
});
});

describe("link", () => {
test("should create a hyperlink", () => {
const text = "OpenAI";
const url = "https://openai.com";
const result = link(text, url);
expect(result).toBe("[OpenAI](https://openai.com)");
describe('Text formatting functions', () => {
test('bold()', () => {
expect(bold('Hello')).toBe('*Hello*');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
link(undefined, "https://openai.com");
}).toThrow(ParameterError);
test('italic()', () => {
expect(italic('Hello')).toBe('_Hello_');
});

test("should throw ParameterError if url is missing", () => {
expect(() => {
link("OpenAI", undefined);
}).toThrow(ParameterError);
test('underline()', () => {
expect(underline('Hello')).toBe('__Hello__');
});
});

describe("image", () => {
test("should create an image element", () => {
const url = "https://example.com/image.jpg";
const alt = "Example Image";
const result = image(url, alt);
expect(result).toBe("![Example Image](https://example.com/image.jpg)");
test('strikethrough()', () => {
expect(strikethrough('Hello')).toBe('~Hello~');
});

test("should throw ParameterError if url is missing", () => {
expect(() => {
image(undefined, "Example Image");
}).toThrow(ParameterError);
test('spoiler()', () => {
expect(spoiler('Hello')).toBe('||Hello||');
});
});

describe("paragraph", () => {
test("should create a paragraph element", () => {
const text = "This is a paragraph.";
const result = paragraph(text);
expect(result).toBe("This is a paragraph.\n\n");
test('inlineCode()', () => {
expect(inlineCode('const a = 5;')).toBe('`const a = 5;`');
});

test("should throw ParameterError if text is missing", () => {
expect(() => {
paragraph();
}).toThrow(ParameterError);
});
});

describe("list", () => {
test("should create an unordered list", () => {
const items = ["Item 1", "Item 2", "Item 3"];
const result = list(items);
expect(result).toBe("1. Item 1\n2. Item 2\n3. Item 3\n\n");
});

test("should create an ordered list", () => {
const items = ["Item 1", "Item 2", "Item 3"];
const result = list(items, true);
expect(result).toBe("1. Item 1\n2. Item 2\n3. Item 3\n\n");
});

test("should throw ParameterError if items is missing", () => {
expect(() => {
list(undefined);
}).toThrow(ParameterError);
});
});

describe("codeBlock", () => {
test("should create a code block element", () => {
const code = 'function sayHello() {\n console.log("Hello, world!");\n}';
const result = codeBlock(code);
expect(result).toBe(
'```\nfunction sayHello() {\n console.log("Hello, world!");\n}\n```',
);
test('codeBlock()', () => {
expect(codeBlock('const a = 5;')).toBe('```\nconst a = 5;\n```');
});

test("should throw ParameterError if code is missing", () => {
expect(() => {
codeBlock();
}).toThrow(ParameterError);
test('codeBlockWithLanguage()', () => {
expect(codeBlockWithLanguage('const a = 5;', 'javascript')).toBe('```javascript\nconst a = 5;\n```');
});
});

0 comments on commit 8e312ef

Please sign in to comment.