awjrichards has submitted this change and it was merged.

Change subject: Add new diff test case for simple insertion
......................................................................


Add new diff test case for simple insertion

Also avoid adding empty del or ins elements in clean diff

Change-Id: I97ed3eaf6756cf2fe8a30ab4f768eb9f1b34b1eb
---
M javascripts/specials/mobilediff.js
M tests/js/specials/mobilediff.js
2 files changed, 14 insertions(+), 5 deletions(-)

Approvals:
  awjrichards: Verified; Looks good to me, approved



diff --git a/javascripts/specials/mobilediff.js 
b/javascripts/specials/mobilediff.js
index 5ae3f46..e987821 100644
--- a/javascripts/specials/mobilediff.js
+++ b/javascripts/specials/mobilediff.js
@@ -3,11 +3,15 @@
        function makePrettyDiff( $diff ) {
                var $diffclone = $diff.clone();
 
-               if ( $diff.children( 'ins' ).length === 0 ) { // if just a 
delete do nothing
+               // simple case where just an insert or just a delete
+               if ( $diff.children( 'ins' ).length === 0 || $diff.children( 
'del' ).length === 0 ) {
                        $diff.empty().addClass( 'prettyDiff' );
-                       $diffclone.find( 'del' ).each( function() {
-                               $( this ).clone().appendTo( $diff );
-                               $( '<br>' ).appendTo( $diff );
+                       $diffclone.find( 'del,ins' ).each( function() {
+                               $el = $( this ).clone();
+                               if ( $el.text() ) { // don't add empty elements
+                                       $el.appendTo( $diff );
+                                       $( '<br>' ).appendTo( $diff );
+                               }
                        } );
                        return $diff;
                } else if ( $diff.children().length > 1 ) { // if there is only 
one line it is not a complicated diff
diff --git a/tests/js/specials/mobilediff.js b/tests/js/specials/mobilediff.js
index 502c438..26f2d15 100644
--- a/tests/js/specials/mobilediff.js
+++ b/tests/js/specials/mobilediff.js
@@ -21,7 +21,12 @@
                ],
                [
                        $( '<div id="mw-mf-minidiff"><del></del><del>== 
Fliberty gibbit ==</del><del>Foobar!</del></div>' ),
-                       '<del></del><br><del>== Fliberty gibbit 
==</del><br><del>Foobar!</del><br>'
+                       '<del>== Fliberty gibbit 
==</del><br><del>Foobar!</del><br>'
+               ],
+               [
+                       // no deletions
+                       $( '<div id="mw-mf-minidiff"><ins></ins><ins>French duo 
Daft Punk weren\'t named in the initial announcement, but added the festival to 
a list of shows on its official Vevo page on March 27. &lt;ref&gt;{{cite news| 
url= 
http://www.3news.co.nz/Daft-Punk-website-shows-Coachella-date/tabid/418/articleID/292127/Default.aspx|work=3
 News NZ |title= Daft Punk website shows Coachella date| date=March 28, 
2013}}&lt;/ref&gt;</ins></div></div>' ),
+                       '<ins>French duo Daft Punk weren\'t named in the 
initial announcement, but added the festival to a list of shows on its official 
Vevo page on March 27. &lt;ref&gt;{{cite news| url= 
http://www.3news.co.nz/Daft-Punk-website-shows-Coachella-date/tabid/418/articleID/292127/Default.aspx|work=3
 News NZ |title= Daft Punk website shows Coachella date| date=March 28, 
2013}}&lt;/ref&gt;</ins><br>'
                ]
        ];
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I97ed3eaf6756cf2fe8a30ab4f768eb9f1b34b1eb
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: awjrichards <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to