jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/398184 )

Change subject: Add unit test for logging the warning if section validation 
fails
......................................................................


Add unit test for logging the warning if section validation fails

Bug: T182774
Change-Id: I4d1711b7f49fd43ae54d0b6ee56e850f9d039017
---
M lib/parsoidSectionsUsingSectionTags.js
M test/lib/parsoid/parsoid-sections-section-elements-tests.js
2 files changed, 24 insertions(+), 5 deletions(-)

Approvals:
  jenkins-bot: Verified
  Mholloway: Looks good to me, approved



diff --git a/lib/parsoidSectionsUsingSectionTags.js 
b/lib/parsoidSectionsUsingSectionTags.js
index c25b7e4..a30d537 100644
--- a/lib/parsoidSectionsUsingSectionTags.js
+++ b/lib/parsoidSectionsUsingSectionTags.js
@@ -135,6 +135,7 @@
     getSectionsText,
     testing: {
         parseSections: traverseDF,
-        shouldLogInvalidSectionWarning
+        shouldLogInvalidSectionWarning,
+        validatePreviousSection
     }
 };
diff --git a/test/lib/parsoid/parsoid-sections-section-elements-tests.js 
b/test/lib/parsoid/parsoid-sections-section-elements-tests.js
index ecfb94c..36d8644 100644
--- a/test/lib/parsoid/parsoid-sections-section-elements-tests.js
+++ b/test/lib/parsoid/parsoid-sections-section-elements-tests.js
@@ -4,8 +4,10 @@
 
 const assert = require('../../utils/assert.js');
 const domino = require('domino');
+const sinon = require('sinon');
 const parsoidSectionsUsingSectionTags = 
require('../../../lib/parsoidSectionsUsingSectionTags');
 const shouldWarn = 
parsoidSectionsUsingSectionTags.testing.shouldLogInvalidSectionWarning;
+const validatePreviousSection = 
parsoidSectionsUsingSectionTags.testing.validatePreviousSection;
 
 describe('lib:parsoid-sections (section elements)', function() {
 
@@ -126,9 +128,9 @@
         assert.ok(!shouldWarn(allSections[0]));
     });
 
-    it('should warn for non-lead section without heading tag', () => {
-        const allSections = [ { id: 0 }, { id: 1 } ];
-        assert.ok(shouldWarn(allSections[1]));
+    it('should warn for non-lead section without heading properties', () => {
+        const allSectionsWithoutHeadingProps = [ { id: 0 }, { id: 1 } ];
+        assert.ok(shouldWarn(allSectionsWithoutHeadingProps[1]));
     });
 
     it('should not warn if id & anchor are found for all sections after the 
lead section', () => {
@@ -136,7 +138,7 @@
         assert.ok(!shouldWarn(allSections[1]));
     });
 
-    it('should not warn for non-lead non-editable section without heading 
tag', () => {
+    it('should not warn for non-lead non-editable section without heading 
properties', () => {
         const allSections = [ { id: 0 }, { id: -1 } ];
         assert.ok(!shouldWarn(allSections[1]));
     });
@@ -149,4 +151,20 @@
     it('should throw if sectionObj is invalid', () => {
         assert.throws(() => { shouldWarn(undefined); }, /TypeError/);
     });
+
+    it('validatePreviousSection should log a warning if appropriate', () => {
+        const logger = {
+            log: sinon.stub()
+        };
+        const allSectionsWarn = [ { id: 0 }, { id: 1 } ];
+
+        validatePreviousSection(logger, allSectionsWarn);
+        assert.ok(logger.log.calledOnce);
+        assert.deepEqual(logger.log.args,
+            [[ 'warn', {
+                warning: 'invalid_section',
+                title: 'Found section without expected heading',
+                detail: 'Cannot find heading for section number 1.'
+            }]]);
+    });
 });

-- 
To view, visit https://gerrit.wikimedia.org/r/398184
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I4d1711b7f49fd43ae54d0b6ee56e850f9d039017
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Fjalapeno <cfl...@wikimedia.org>
Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Mhurd <mh...@wikimedia.org>
Gerrit-Reviewer: Ppchelko <ppche...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to