Skip to content

Commit 0991083

Browse files
committed
fix: course update iframe
(cherry picked from commit 657b146)
1 parent 1c025f0 commit 0991083

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/course-home/outline-tab/LmsHtmlFragment.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const LmsHtmlFragment = ({
2929
const iframe = useRef(null);
3030
function resetIframeHeight() {
3131
if (iframe?.current?.contentWindow?.document?.body) {
32-
iframe.current.height = iframe.current.contentWindow.document.body.scrollHeight;
32+
iframe.current.height = iframe.current.contentWindow.document.body.parentNode.scrollHeight;
3333
}
3434
}
3535

src/course-home/outline-tab/OutlineTab.test.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ describe('Outline Tab', () => {
257257
});
258258
});
259259

260+
it('ignores comments and misformatted HTML', async () => {
261+
setTabData({
262+
welcome_message_html: '<p class="additional-spaces-in-tag" >'
263+
+ '<!-- Even if the welcome_message_html length is above the limit because of comments, we hope it will not be shortened. -->'
264+
+ '<!-- Even if the welcome_message_html length is above the limit because of comments, we hope it will not be shortened. -->'
265+
+ 'Test welcome message that happens to be longer than one hundred words because of comments but displayed content is less.'
266+
+ 'It should not be shortened.'
267+
+ '<!-- Even if the welcome_message_html length is above the limit because of comments, we hope it will not be shortened. -->'
268+
+ '<!-- Even if the welcome_message_html length is above the limit because of comments, we hope it will not be shortened. -->'
269+
+ '</p>',
270+
});
271+
await fetchAndRender();
272+
const showMoreButton = screen.queryByRole('button', { name: 'Show More' });
273+
expect(showMoreButton).not.toBeInTheDocument();
274+
});
275+
260276
it('does not display if no update available', async () => {
261277
setTabData({ welcome_message_html: null });
262278
await fetchAndRender();

src/course-home/outline-tab/widgets/WelcomeMessage.jsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useMemo } from 'react';
22
import PropTypes from 'prop-types';
33

44
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
@@ -18,8 +18,22 @@ const WelcomeMessage = ({ courseId, intl }) => {
1818

1919
const [display, setDisplay] = useState(true);
2020

21-
const shortWelcomeMessageHtml = truncate(welcomeMessageHtml, 100, { byWords: true, keepWhitespaces: true });
22-
const messageCanBeShortened = shortWelcomeMessageHtml.length < welcomeMessageHtml.length;
21+
// welcomeMessageHtml can contain comments or malformatted HTML which can impact the length that determines
22+
// messageCanBeShortened. We clean it by calling truncate with a length of welcomeMessageHtml.length which
23+
// will not result in a truncation but a formatting into 'truncate-html' canonical format.
24+
const cleanedWelcomeMessageHtml = useMemo(
25+
() => truncate(welcomeMessageHtml, welcomeMessageHtml.length, { keepWhitespaces: true }),
26+
[welcomeMessageHtml],
27+
);
28+
const shortWelcomeMessageHtml = useMemo(
29+
() => truncate(cleanedWelcomeMessageHtml, 100, { byWords: true, keepWhitespaces: true }),
30+
[cleanedWelcomeMessageHtml],
31+
);
32+
const messageCanBeShortened = useMemo(
33+
() => (shortWelcomeMessageHtml.length < cleanedWelcomeMessageHtml.length),
34+
[cleanedWelcomeMessageHtml, shortWelcomeMessageHtml],
35+
);
36+
2337
const [showShortMessage, setShowShortMessage] = useState(messageCanBeShortened);
2438
const dispatch = useDispatch();
2539

@@ -63,7 +77,7 @@ const WelcomeMessage = ({ courseId, intl }) => {
6377
className="inline-link"
6478
data-testid="long-welcome-message-iframe"
6579
key="full-html"
66-
html={welcomeMessageHtml}
80+
html={cleanedWelcomeMessageHtml}
6781
title={intl.formatMessage(messages.welcomeMessage)}
6882
/>
6983
)}

0 commit comments

Comments
 (0)