From d14f3fb13b085ebe18f2d0cdae308978b12d1343 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 15 Oct 2021 00:07:19 +0200 Subject: [PATCH] Add spec file --- tests/motd.spec.js | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/motd.spec.js diff --git a/tests/motd.spec.js b/tests/motd.spec.js new file mode 100644 index 0000000..5b3249c --- /dev/null +++ b/tests/motd.spec.js @@ -0,0 +1,53 @@ +const mcmotd = require('../src/motdparsernode') + +describe('JSON Parser', () => { + test('parses a json-motd to a html div', async() => { + let motd = await mcmotd.jsonToHtml({"text":"","extra":[{"text":"Hypixel Network ","extra":[{"text":"","extra":[{"text":"1.8/1.9/1.10/1.11/1.12 ","extra":[{"text":"","extra":[{"text":"NEW PTL GAME:","extra":[{"text":"","extra":[{"text":" THE BRIDGE","extra":[],"bold":true}],"color":"acqua"}],"bold":true}],"color":"yellow"}],"color":"red"}],"color":"gray"}],"color":"green"}]}) + expect(motd).toBeString() + expect(motd).toStartWith('') + }) + + test('parses an array-motd to a html div', async() => { + let motd = await mcmotd.jsonToHtml([{"text":"test"},{"text":"","extra":[{"text":"Hypixel Network ","extra":[{"text":"","extra":[{"text":"1.8/1.9/1.10/1.11/1.12 ","extra":[{"text":"","extra":[{"text":"NEW PTL GAME:","extra":[{"text":"","extra":[{"text":" THE BRIDGE","extra":[],"bold":true}],"color":"acqua"}],"bold":true}],"color":"yellow"}],"color":"red"}],"color":"gray"}],"color":"green"}]}]) + expect(motd).toBeString() + expect(motd).toStartWith('') + }) + + test('calls the callback function if passed as second argument', (done) => { + function callback(_err, result) { + try { + expect(result).toBeString() + expect(result).toStartWith('') + done() + } catch(error) { + done(error) + } + } + mcmotd.jsonToHtml({"text": "test"}, callback) + }) +}) + +describe('Text to JSON converter', () => { + test('converts text to an object', async() => { + let json = await mcmotd.textToJson("§aHypixel Network §7§c1.8/1.9/1.10/1.11/1.12 §e§lNEW PTL GAME:§b§l THE BRIDGE") + console.log(JSON.stringify(json)) + expect(json).toBeObject() + expect(json).toHaveProperty('text') + expect(json).toHaveProperty('extra') + }) +}) + +describe('motd converter', () => { + test('converts both text and objects (json) to a html string', async() => { + let text = await mcmotd.toHtml("§aHypixel Network §7§c1.8/1.9/1.10/1.11/1.12 §e§lNEW PTL GAME:§b§l THE BRIDGE") + let obj = await mcmotd.toHtml({"text": "test"}) + let reg = /^$/ + expect(text).toBeString() + expect(obj).toBeString() + expect(text).toMatch(reg) + expect(obj).toMatch(reg) + }) +}) \ No newline at end of file