@juzi/wechaty
Version:
Wechaty is a RPA SDK for Chatbot Makers.
97 lines • 4.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Wechaty Chatbot SDK - https://github.com/wechaty/wechaty
*
* @copyright 2016 Huan LI (李卓桓) <https://github.com/huan>, and
* Wechaty Contributors <https://github.com/wechaty>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
const tstest_1 = require("tstest");
const xml_js_1 = require("./xml.js");
(0, tstest_1.test)('stripHtml()', async (t) => {
const HTML_BEFORE_STRIP = 'Outer<html>Inner</html>';
const HTML_AFTER_STRIP = 'OuterInner';
const strippedHtml = (0, xml_js_1.stripHtml)(HTML_BEFORE_STRIP);
t.equal(strippedHtml, HTML_AFTER_STRIP, 'should strip html as expected');
});
(0, tstest_1.test)('unescapeHtml()', async (t) => {
const HTML_BEFORE_UNESCAPE = ''|"|>|<|&';
// eslint-disable-next-line
const HTML_AFTER_UNESCAPE = `'|"|>|<|&`;
const unescapedHtml = (0, xml_js_1.unescapeHtml)(HTML_BEFORE_UNESCAPE);
t.equal(unescapedHtml, HTML_AFTER_UNESCAPE, 'should unescape html as expected');
});
(0, tstest_1.test)('plainText()', async (t) => {
const PLAIN_BEFORE = '&<html>&</html>&<img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />';
const PLAIN_AFTER = '&&&[流汗]';
const text = (0, xml_js_1.plainText)(PLAIN_BEFORE);
t.equal(text, PLAIN_AFTER, 'should convert plain text as expected');
});
(0, tstest_1.test)('digestEmoji()', async (t) => {
const EMOJI_XML = [
'<img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />',
'<img class="qqemoji qqemoji13" text="[呲牙]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />',
'<img class="emoji emoji1f44d" text="_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />',
'<span class="emoji emoji1f334"></span>',
];
const EMOJI_AFTER_DIGEST = [
'[流汗]',
'[呲牙]',
'',
'[emoji1f334]',
];
for (let i = 0; i < EMOJI_XML.length; i++) {
const emojiDigest = (0, xml_js_1.digestEmoji)(EMOJI_XML[i]);
t.equal(emojiDigest, EMOJI_AFTER_DIGEST[i], 'should digest emoji string ' + i + ' as expected');
}
});
(0, tstest_1.test)('unifyEmoji()', async (t) => {
const ORIGNAL_XML_LIST = [
[
[
'<img class="emoji emoji1f602" text="_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />',
'<span class="emoji emoji1f602"></span>',
],
'<emoji code="emoji1f602"/>',
],
];
ORIGNAL_XML_LIST.forEach(([xmlList, expectedEmojiXml]) => {
xmlList.forEach(xml => {
const unifiedXml = (0, xml_js_1.unifyEmoji)(xml);
t.equal(unifiedXml, expectedEmojiXml, 'should convert the emoji xml to the expected unified xml');
});
});
});
(0, tstest_1.test)('stripEmoji()', async (t) => {
const EMOJI_STR = [
[
'ABC<img class="emoji emoji1f4a4" text="[流汗]_web" src="/zh_CN/htmledition/v2/images/spacer.gif" />DEF',
'ABCDEF',
],
[
'UVW<span class="emoji emoji1f334"></span>XYZ',
'UVWXYZ',
],
];
EMOJI_STR.forEach(([emojiStr, expectResult]) => {
const result = (0, xml_js_1.stripEmoji)(emojiStr);
t.equal(result, expectResult, 'should strip to the expected str');
});
const empty = (0, xml_js_1.stripEmoji)(undefined);
t.equal(empty, '', 'should return empty string for `undefined`');
});
//# sourceMappingURL=xml.spec.js.map