From f8446590cb02e887ada4f99a279e34cbecbc8b31 Mon Sep 17 00:00:00 2001 From: WMDE-Fisch Date: Mon, 30 May 2016 14:36:48 +0200 Subject: [PATCH] Use parsed comment instead of custom parsing Bug: T135740 Change-Id: I49757b5bcf2c47f459538bd4383325882a15336f --- modules/ext.RevisionSlider.Revision.js | 18 ++------ .../ext.RevisionSlider.RevisionListView.js | 21 ++++++---- tests/RevisionSlider.Revision.test.js | 42 +++++++++++-------- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/modules/ext.RevisionSlider.Revision.js b/modules/ext.RevisionSlider.Revision.js index 6ccb3c78..21ccc339 100644 --- a/modules/ext.RevisionSlider.Revision.js +++ b/modules/ext.RevisionSlider.Revision.js @@ -67,22 +67,12 @@ return this.parsedComment; }, - getComment: function () { - return this.comment; + hasEmptyComment: function () { + return this.getComment().trim().length === 0; }, - getSection: function () { - var comment = this.getComment(); - comment = comment.match( - new RegExp( '(/\\* [^\\*]* \\*/)', 'gi' ) - ); - if ( !comment ) { - return ''; - } - return comment[ 0 ].replace( - new RegExp( ' \\*/|/\\* ', 'gi' ), - '' - ); + getComment: function () { + return this.comment; }, formatDate: function ( rawDate ) { diff --git a/modules/ext.RevisionSlider.RevisionListView.js b/modules/ext.RevisionSlider.RevisionListView.js index f3f36441..ccb51d67 100644 --- a/modules/ext.RevisionSlider.RevisionListView.js +++ b/modules/ext.RevisionSlider.RevisionListView.js @@ -61,19 +61,26 @@ mw.msg( 'revisionslider-label-user', mw.html.escape( rev.getUser() ) ) ) ) : '', - rev.getComment() ? - $( '' ).append( - $( '

' ).append( $( '' ).text( - mw.msg( 'revisionslider-label-comment', mw.html.escape( rev.getComment() ) ) - ) ) - ) - : '', + this.makeCommentLine( rev ), $( '

' ).text( mw.msg( 'revisionslider-label-article-size', mw.msg( 'revisionslider-revision-bytes', rev.getSize() ) ) ), rev.isMinor() ? $( '

' ).text( mw.message( 'minoredit' ).text() ) : '' ); return $tooltip.html(); + }, + + makeCommentLine: function ( rev ) { + if ( rev.hasEmptyComment() ) { + return ''; + } + + return $( '' ).append( + $( '

' ).append( + $( '' ).html( + mw.msg( 'revisionslider-label-comment', rev.getParsedComment() ) + ) ) + ); } } ); diff --git a/tests/RevisionSlider.Revision.test.js b/tests/RevisionSlider.Revision.test.js index 1d9ed95e..19c7a5bb 100644 --- a/tests/RevisionSlider.Revision.test.js +++ b/tests/RevisionSlider.Revision.test.js @@ -66,24 +66,6 @@ assert.equal( rev.isMinor(), true ); } ); - QUnit.test( 'get Revision with section', function ( assert ) { - var data = { - comment: '/* section */ comment' - }, - rev = new mw.libs.revisionSlider.Revision( data ); - - assert.equal( rev.getSection(), 'section' ); - } ); - - QUnit.test( 'get Revision without section', function ( assert ) { - var data = { - comment: 'no section comment' - }, - rev = new mw.libs.revisionSlider.Revision( data ); - - assert.equal( rev.getSection(), '' ); - } ); - QUnit.test( 'get and set relative size', function ( assert ) { var size = 5, rev = new mw.libs.revisionSlider.Revision( {} ); @@ -124,5 +106,29 @@ assert.equal( rev.getFormattedDate(), '12:27, 26 Apr 2016' ); } ); + QUnit.test( 'hasEmptyComment comment with whitespaces', function ( assert ) { + var rev = new mw.libs.revisionSlider.Revision( { + comment: ' ' + } ); + + assert.ok( rev.hasEmptyComment() ); + } ); + + QUnit.test( 'hasEmptyComment comment with chars', function ( assert ) { + var rev = new mw.libs.revisionSlider.Revision( { + comment: ' comment ' + } ); + + assert.notOk( rev.hasEmptyComment() ); + } ); + + QUnit.test( 'hasEmptyComment comment with unicode chars', function ( assert ) { + var rev = new mw.libs.revisionSlider.Revision( { + comment: 'ברוכים' + } ); + + assert.notOk( rev.hasEmptyComment() ); + } ); + } )( mediaWiki );