Test content
+diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 51514d145e..59725d48fa 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -24,6 +24,7 @@ Changelog
* Fix: Ensure that JS slugify function strips Unicode characters disallowed by Django slug validation (Atif Khan)
* Fix: Do not show notices about root / unroutable pages when searching or filtering in the page explorer (Matt Westcott)
* Fix: Resolve contrast issue for page deletion warning (Sanjeev Holla S)
+ * Fix: Make sure content metrics falls back to body element only when intended (Sage Abdullah)
* Docs: Upgrade Sphinx to 7.3 (Matt Westcott)
* Docs: Document how to customize date/time format settings (Vince Salvino)
* Docs: Create a new documentation section for deployment and move fly.io deployment from the tutorial to this section (Vince Salvino)
@@ -49,6 +50,7 @@ Changelog
* Fix: Fix various instances of `USE_THOUSAND_SEPARATOR` formatting numbers where formatting is invalid (Sébastien Corbin, Matt Westcott)
* Fix: Fix broken link to user search (Shlomo Markowitz)
+ * Fix: Make sure content metrics falls back to body element only when intended (Sage Abdullah)
* Docs: Clarify process for UserViewSet customisation (Sage Abdullah)
diff --git a/client/src/controllers/PreviewController.ts b/client/src/controllers/PreviewController.ts
index 502c34c10e..e4ece271f3 100644
--- a/client/src/controllers/PreviewController.ts
+++ b/client/src/controllers/PreviewController.ts
@@ -22,7 +22,7 @@ const runContentChecks = async () => {
axe.registerPlugin(wagtailPreviewPlugin);
const contentMetrics = await getPreviewContentMetrics({
- targetElement: 'main, [role="main"], body',
+ targetElement: 'main, [role="main"]',
});
// This requires Wagtail's preview plugin for axe to be registered in the
diff --git a/client/src/includes/contentMetrics.test.ts b/client/src/includes/contentMetrics.test.ts
index 9e55df2cd6..7437f7f30a 100644
--- a/client/src/includes/contentMetrics.test.ts
+++ b/client/src/includes/contentMetrics.test.ts
@@ -1,4 +1,8 @@
-import { getWordCount, getReadingTime } from './contentMetrics';
+import {
+ getWordCount,
+ getReadingTime,
+ contentMetricsPluginInstance,
+} from './contentMetrics';
describe.each`
text | lang | wordCount
@@ -38,3 +42,50 @@ describe.each`
expect(getReadingTime(lang, wordCount)).toBe(readingTime);
});
});
+
+describe('contentMetricsPluginInstance', () => {
+ let originalInnerText;
+ beforeAll(() => {
+ originalInnerText = Object.getOwnPropertyDescriptor(
+ HTMLElement.prototype,
+ 'innerText',
+ );
+ });
+
+ beforeEach(() => {
+ document.body.innerHTML = `
+ Test content