mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 10:46:32 +00:00
Add test for htmlTextHelper
This commit is contained in:
52
tests/lib/html-text-helper-test.js
Normal file
52
tests/lib/html-text-helper-test.js
Normal file
@@ -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=', '<a href='],
|
||||||
|
['var test = 'test'', "var test = 'test'"],
|
||||||
|
['<a href='https://boostnote.io'>Boostnote', "<a href='https://boostnote.io'>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 = [
|
||||||
|
['<a href=', '<a href='],
|
||||||
|
["var test = 'test'", 'var test = 'test''],
|
||||||
|
["<a href='https://boostnote.io'>Boostnote", '<a href='https://boostnote.io'>Boostnote'],
|
||||||
|
["<?php\n var = 'hoge';", "<?php\n var = 'hoge';"],
|
||||||
|
]
|
||||||
|
|
||||||
|
testCases.forEach(testCase => {
|
||||||
|
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'",
|
||||||
|
"<a href='https://boostnote.io'>Boostnote",
|
||||||
|
"<Component styleName='test' />",
|
||||||
|
]
|
||||||
|
|
||||||
|
testCases.forEach(testCase => {
|
||||||
|
const encodedText = htmlTextHelper.encodeEntities(testCase)
|
||||||
|
const decodedText = htmlTextHelper.decodeEntities(encodedText)
|
||||||
|
t.is(decodedText, testCase, `Integration test for encodedText() and decodedText()`);
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user