From b695d27817d8e0b5453a4a471a3fafdd3c592f09 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 22 Apr 2017 17:19:05 -0700 Subject: [PATCH] Add test for htmlTextHelper --- tests/lib/html-text-helper-test.js | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/lib/html-text-helper-test.js diff --git a/tests/lib/html-text-helper-test.js b/tests/lib/html-text-helper-test.js new file mode 100644 index 00000000..c61b3d16 --- /dev/null +++ b/tests/lib/html-text-helper-test.js @@ -0,0 +1,52 @@ +/** + * @fileoverview Unit test for browser/lib/htmlTextHelper + */ +const test = require('ava') +const htmlTextHelper = require('browser/lib/htmlTextHelper') + +// Unit test +test('htmlTextHelper#decodeEntities should return encoded text (string)', t => { + // [input, expected] + const testCases = [ + ['<a href=', 'Boostnote"], + ["<\\?php\n var = 'hoge';", "<\\?php\n var = 'hoge';"], + ["&", "&"], + ] + + testCases.forEach(testCase => { + const [input, expected] = testCase; + t.is(htmlTextHelper.decodeEntities(input), expected, `Test for decodeEntities() input: ${input} expected: ${expected}`); + }) +}) + +test('htmlTextHelper#decodeEntities() should return decoded text (string)', t => { + // [input, expected] + const testCases = [ + ['Boostnote", '<a href='https://boostnote.io'>Boostnote'], + [" { + const [input, expected] = testCase; + t.is(htmlTextHelper.encodeEntities(input), expected, `Test for encodeEntities() input: ${input} expected: ${expected}`); + }) +}) + +// Integration test +test(t => { + const testCases = [ + "var test = 'test'", + "Boostnote", + "", + ] + + testCases.forEach(testCase => { + const encodedText = htmlTextHelper.encodeEntities(testCase) + const decodedText = htmlTextHelper.decodeEntities(encodedText) + t.is(decodedText, testCase, `Integration test for encodedText() and decodedText()`); + }) +})