mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 10:16:26 +00:00
resolved conflict
This commit is contained in:
59
tests/lib/html-text-helper.test.js
Normal file
59
tests/lib/html-text-helper.test.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @fileoverview Unit test for browser/lib/htmlTextHelper
|
||||
*/
|
||||
const htmlTextHelper = require('browser/lib/htmlTextHelper')
|
||||
|
||||
// Unit test
|
||||
test('htmlTextHelper#decodeEntities should return encoded text (string)', () => {
|
||||
// [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';"],
|
||||
['&', '&'],
|
||||
['a$'', "a\\$'"]
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
expect(htmlTextHelper.decodeEntities(input)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
test('htmlTextHelper#decodeEntities() should return decoded text (string)', () => {
|
||||
// [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';'],
|
||||
["a$'", 'a$'']
|
||||
]
|
||||
|
||||
testCases.forEach(testCase => {
|
||||
const [input, expected] = testCase
|
||||
expect(htmlTextHelper.encodeEntities(input)).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
// Integration test
|
||||
test(() => {
|
||||
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)
|
||||
expect(decodedText).toBe(testCase)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user