jenkins-bot has submitted this change and it was merged.
Change subject: EditorApi: Check for sections
..
EditorApi: Check for sections
Don't try to access an undefined object.
Add tests for it.
Bug: 72521
Change-Id: I8b88bda22e2219cf65233fd6f0a6ee15444fac3d
---
M javascripts/modules/editor/EditorApi.js
M tests/qunit/modules/editor/test_EditorApi.js
2 files changed, 35 insertions(+), 1 deletion(-)
Approvals:
Jdlrobson: Looks good to me, approved
jenkins-bot: Verified
diff --git a/javascripts/modules/editor/EditorApi.js
b/javascripts/modules/editor/EditorApi.js
index 5585797..a74b0a2 100644
--- a/javascripts/modules/editor/EditorApi.js
+++ b/javascripts/modules/editor/EditorApi.js
@@ -192,7 +192,8 @@
if ( resp resp.parse resp.parse.text ) {
// section 0 haven't a section name so
skip
if ( self.sectionId !== 0
- resp.parse.sections
+ resp.parse.sections !==
undefined
+ resp.parse.sections[0] !==
undefined
resp.parse.sections[0].line !==
undefined
) {
sectionLine =
resp.parse.sections[0].line;
diff --git a/tests/qunit/modules/editor/test_EditorApi.js
b/tests/qunit/modules/editor/test_EditorApi.js
index 4efc082..b10868f 100644
--- a/tests/qunit/modules/editor/test_EditorApi.js
+++ b/tests/qunit/modules/editor/test_EditorApi.js
@@ -373,6 +373,39 @@
assert.ok( doneSpy.calledWith( 'h1Heading 1/h1h2Heading
2/h2ptest content/p' ) );
} );
+ QUnit.test( '#getPreview, check without sectionLine', 1, function(
assert ) {
+ var editorApi = new EditorApi( { title: 'Test', sectionId: 1 }
);
+ this.sandbox.stub( editorApi, 'post' ).returns(
$.Deferred().resolve( {
+ parse: {
+ title: test,
+ text: { *: test content },
+ sections: {}
+ }
+ } ) );
+
+ editorApi.getPreview( { text: test content } ).done(
function( text, sectionLine ) {
+ assert.strictEqual( sectionLine, '', 'Ok, no section
line returned' );
+ } );
+ } );
+
+ QUnit.test( '#getPreview, check with sectionLine', 1, function( assert
) {
+ var editorApi = new EditorApi( { title: 'Test', sectionId: 1 }
);
+ this.sandbox.stub( editorApi, 'post' ).returns(
$.Deferred().resolve( {
+ parse: {
+ title: test,
+ text: { *: test content },
+ sections: {
+ 0: { line: Testsection },
+ 1: { line: Testsection2 }
+ }
+ }
+ } ) );
+
+ editorApi.getPreview( { text: test content } ).done(
function( text, sectionLine ) {
+ assert.strictEqual( sectionLine, 'Testsection', 'Ok,
section line returned' );
+ } );
+ } );
+
QUnit.test( '#save, when token has expired', 2, function( assert ) {
var editorApi = new EditorApi( { title: 'MediaWiki:Test.css' }
);
--
To view, visit https://gerrit.wikimedia.org/r/168823
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8b88bda22e2219cf65233fd6f0a6ee15444fac3d
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow florian.schmidt.wel...@t-online.de
Gerrit-Reviewer: Awjrichards aricha...@wikimedia.org
Gerrit-Reviewer: Bmansurov bmansu...@wikimedia.org
Gerrit-Reviewer: Florianschmidtwelzow florian.schmidt.wel...@t-online.de
Gerrit-Reviewer: Jdlrobson jrob...@wikimedia.org
Gerrit-Reviewer: Kaldari rkald...@wikimedia.org
Gerrit-Reviewer: jenkins-bot
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits