From 324785f36a6b4d3c8bf528868b40eb3d9d14bcb3 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 5 Dec 2022 16:54:42 +0100 Subject: [PATCH 1/3] MOBILE-4176 grades: Keep new lines --- .../mod/bigbluebuttonbn/components/index/index.ts | 2 +- src/addons/mod/wiki/pages/edit/edit.ts | 2 +- src/core/components/mark-required/mark-required.ts | 2 +- src/core/features/filter/services/filter.ts | 2 +- src/core/features/grades/services/grades-helper.ts | 12 +++++------- .../features/question/services/question-helper.ts | 2 +- src/core/services/utils/text.ts | 10 +++++++--- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/addons/mod/bigbluebuttonbn/components/index/index.ts b/src/addons/mod/bigbluebuttonbn/components/index/index.ts index b90a7adb9..2129af495 100644 --- a/src/addons/mod/bigbluebuttonbn/components/index/index.ts +++ b/src/addons/mod/bigbluebuttonbn/components/index/index.ts @@ -181,7 +181,7 @@ export class AddonModBBBIndexComponent extends CoreCourseModuleMainActivityCompo return { type: playbackAnchor?.innerText ?? Translate.instant('addon.mod_bigbluebuttonbn.view_recording_format_presentation'), - name: CoreTextUtils.cleanTags(String(recordingData.recording), true), + name: CoreTextUtils.cleanTags(String(recordingData.recording), { singleLine: true }), url: playbackAnchor?.href ?? '', details, expanded: false, diff --git a/src/addons/mod/wiki/pages/edit/edit.ts b/src/addons/mod/wiki/pages/edit/edit.ts index 93b95b0bf..7e9500256 100644 --- a/src/addons/mod/wiki/pages/edit/edit.ts +++ b/src/addons/mod/wiki/pages/edit/edit.ts @@ -87,7 +87,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy, CanLeave { this.userId = CoreNavigator.getRouteNumberParam('userId'); let pageTitle = CoreNavigator.getRouteParam('pageTitle'); - pageTitle = pageTitle ? CoreTextUtils.cleanTags(pageTitle.replace(/\+/g, ' '), true) : ''; + pageTitle = pageTitle ? CoreTextUtils.cleanTags(pageTitle.replace(/\+/g, ' '), { singleLine: true }) : ''; this.canEditTitle = !pageTitle; this.title = pageTitle ? diff --git a/src/core/components/mark-required/mark-required.ts b/src/core/components/mark-required/mark-required.ts index a0c5de654..d486ca322 100644 --- a/src/core/components/mark-required/mark-required.ts +++ b/src/core/components/mark-required/mark-required.ts @@ -62,7 +62,7 @@ export class CoreMarkRequiredComponent implements OnInit, AfterViewInit { if (this.coreMarkRequired) { // Add the "required" to the aria-label. const ariaLabel = this.element.getAttribute('aria-label') || - CoreTextUtils.cleanTags(this.element.innerHTML, true); + CoreTextUtils.cleanTags(this.element.innerHTML, { singleLine: true }); if (ariaLabel) { this.element.setAttribute('aria-label', ariaLabel + ' ' + this.requiredLabel); } diff --git a/src/core/features/filter/services/filter.ts b/src/core/features/filter/services/filter.ts index d9f63cf50..737852d06 100644 --- a/src/core/features/filter/services/filter.ts +++ b/src/core/features/filter/services/filter.ts @@ -222,7 +222,7 @@ export class CoreFilterProvider { } if (options.clean) { - text = CoreTextUtils.cleanTags(text, options.singleLine); + text = CoreTextUtils.cleanTags(text, { singleLine: options.singleLine }); } if (options.shortenLength && options.shortenLength > 0) { diff --git a/src/core/features/grades/services/grades-helper.ts b/src/core/features/grades/services/grades-helper.ts index d75a4e9e0..50e9cef5a 100644 --- a/src/core/features/grades/services/grades-helper.ts +++ b/src/core/features/grades/services/grades-helper.ts @@ -137,15 +137,13 @@ export class CoreGradesHelperProvider { row.rowclass += itemNameColumn.class.indexOf('hidden') >= 0 ? ' hidden' : ''; row.rowclass += itemNameColumn.class.indexOf('dimmed_text') >= 0 ? ' dimmed_text' : ''; - if (useLegacyLayout) { - content = content.replace(/<\/span>/gi, '\n'); - content = CoreTextUtils.cleanTags(content); - } else { - // The activity type won't be included in the webservice response if behat is running. - content = CoreAppProvider.isAutomated() ? content : content.replace(/]+>.+?<\/span>/i, ''); - content = CoreTextUtils.cleanTags(content, true); + if (!useLegacyLayout && !CoreAppProvider.isAutomated()) { + // Activity name is only included in the webservice response from the latest version when behat is not running. + content = content.replace(/]+>.+?<\/span>/i, ''); } + content = content.replace(/<\/span>/gi, '\n'); + content = CoreTextUtils.cleanTags(content, { trim: true }); name = 'gradeitem'; } else if (name === 'grade') { // Add the pass/fail class if present. diff --git a/src/core/features/question/services/question-helper.ts b/src/core/features/question/services/question-helper.ts index adc06f075..cfc9e35cc 100644 --- a/src/core/features/question/services/question-helper.ts +++ b/src/core/features/question/services/question-helper.ts @@ -415,7 +415,7 @@ export class CoreQuestionHelperProvider { // Check anchor is valid. if (anchor.href && content) { - content = CoreTextUtils.cleanTags(content, true).trim(); + content = CoreTextUtils.cleanTags(content, { singleLine: true, trim: true }); attachments.push({ filename: content, fileurl: anchor.href, diff --git a/src/core/services/utils/text.ts b/src/core/services/utils/text.ts index 4b90eaae9..24065d5cc 100644 --- a/src/core/services/utils/text.ts +++ b/src/core/services/utils/text.ts @@ -277,10 +277,12 @@ export class CoreTextUtilsProvider { * Clean HTML tags. * * @param text The text to be cleaned. - * @param singleLine True if new lines should be removed (all the text in a single line). + * @param options Processing options. + * @param options.singleLine True if new lines should be removed (all the text in a single line). + * @param options.trim True if text should be trimmed. * @returns Clean text. */ - cleanTags(text: string | undefined, singleLine?: boolean): string { + cleanTags(text: string | undefined, options: { singleLine?: boolean; trim?: boolean } = {}): string { if (!text) { return ''; } @@ -289,8 +291,10 @@ export class CoreTextUtilsProvider { text = text.replace(/(<([^>]+)>)/ig, ''); // Then, we rely on the browser. We need to wrap the text to be sure is HTML. text = this.convertToElement(text).textContent || ''; + // Trim text + text = options.trim ? text.trim() : text; // Recover or remove new lines. - text = this.replaceNewLines(text, singleLine ? ' ' : '
'); + text = this.replaceNewLines(text, options.singleLine ? ' ' : '
'); return text; } From 655e604576b22229069a6f18209daf13d68a27d4 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 12 Dec 2022 10:51:27 +0100 Subject: [PATCH 2/3] MOBILE-4081 behat: Improve flaky tests --- local_moodleappbehat/tests/behat/behat_app.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/local_moodleappbehat/tests/behat/behat_app.php b/local_moodleappbehat/tests/behat/behat_app.php index a5af4a3ca..168bfa9d5 100644 --- a/local_moodleappbehat/tests/behat/behat_app.php +++ b/local_moodleappbehat/tests/behat/behat_app.php @@ -621,6 +621,9 @@ class behat_app extends behat_app_helper { }); $this->wait_for_pending_js(); + + // Wait for UI to settle after refreshing. + $this->getSession()->wait(300); } /** From 032d0a1a3b0689ed90c747ca14c345df60ada325 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Mon, 12 Dec 2022 12:03:53 +0100 Subject: [PATCH 3/3] MOBILE-4081 core: Update upgrade notes --- upgrade.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/upgrade.txt b/upgrade.txt index ad26a714e..809b24292 100644 --- a/upgrade.txt +++ b/upgrade.txt @@ -7,6 +7,8 @@ information provided here is intended especially for developers. - --addon-messages-* CSS3 variables have been renamed to --core-messages-* - The database constants in CoreSite (WS_CACHE_TABLE, CONFIG_TABLE, LAST_VIEWED_TABLE) and the DBRecord types have been moved to src/core/services/database. - The component will no longer detect changes of properties inside the extraData object, it will only detect changes if the object itself changes. +- CSS variable declarations have been moved to the `html` selector instead of using `body` and `:root`. +- The second argument of `CoreTextUtilsProvider.cleanTags` has been converted into an object with boolean flags. === 4.0.0 ===