Merge pull request #23663 from edx/ddumesnil/welcome-message-fix

Shorten Welcome Message fix
This commit is contained in:
Dillon Dumesnil
2020-04-08 08:13:06 -07:00
committed by GitHub
2 changed files with 9 additions and 0 deletions

View File

@@ -12,6 +12,10 @@
function clampHtmlByWords(root, wordsLeft) {
'use strict';
if (root.nodeName === 'SCRIPT' || root.nodeName === 'LINK') {
return wordsLeft; // early exit and ignore
}
var remaining = wordsLeft;
var nodes = Array.from(root.childNodes ? root.childNodes : []);
var words, chopped;

View File

@@ -3,6 +3,8 @@ import ReactDOM from 'react-dom';
import { clampHtmlByWords } from './clamp-html';
let container;
const scriptTag = '<script src="/asset-v1:edX+testX+1T2021+type@asset+block/script.js"></script>';
const stylesheet = '<link rel="stylesheet" type="text/css" href="/asset-v1:edX+testX+1T2021+type@asset+block/introjs.css">';
beforeEach(() => {
container = document.createElement("div");
@@ -25,6 +27,9 @@ describe('ClampHtml', () => {
['a <i>aa <em>aaa</em></i>', 2, 'a <i>aa…</i>'],
['a <i>aa <em>aaa</em> ab</i>', 3, 'a <i>aa <em>aaa…</em></i>'],
['a <i>aa ab</i> b c', 4, 'a <i>aa ab</i> b…'],
[scriptTag + 'a b c', 2, scriptTag + 'a b…'],
[stylesheet + 'a b c', 2, stylesheet + 'a b…'],
[scriptTag + stylesheet + 'a b c', 2, scriptTag + stylesheet + 'a b…'],
])('clamps by words: %s, %i', (input, wordsLeft, expected) => {
const div = ReactDOM.render(<div dangerouslySetInnerHTML={{ __html: input }} />, container);
clampHtmlByWords(div, wordsLeft);