Jeroen De Dauw has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/387159 )

Change subject: Added extra tests
......................................................................

Added extra tests

https://phabricator.wikimedia.org/T173563

Change-Id: I9415a96b77ce16b4e0ddfeb1eeef4c53fccee9cc
---
M modules/ui/ext.advancedSearch.ArbitraryWordInput.js
M tests/qunit/ui/ArbitraryWordInput.test.js
2 files changed, 36 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AdvancedSearch 
refs/changes/59/387159/1

diff --git a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js 
b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
index e7a6305..c68fb4f 100644
--- a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
+++ b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
@@ -71,8 +71,10 @@
                        var self = this;
 
                        segments.map( function ( segment ) {
-                               if ( self.isAllowedData( segment ) ) {
-                                       self.addTag( segment );
+                               var trimmedSegment = segment.trim();
+
+                               if ( self.isAllowedData( trimmedSegment ) ) {
+                                       self.addTag( trimmedSegment );
                                }
                        } );
 
diff --git a/tests/qunit/ui/ArbitraryWordInput.test.js 
b/tests/qunit/ui/ArbitraryWordInput.test.js
index 96d9eb4..27e4886 100644
--- a/tests/qunit/ui/ArbitraryWordInput.test.js
+++ b/tests/qunit/ui/ArbitraryWordInput.test.js
@@ -31,4 +31,36 @@
                assert.equal( input.getTextForPlaceholder(), '' );
        } );
 
+       function getTagsFromInput( inputText ) {
+               var input = new ArbitraryWordInput( new Model(), {} );
+               input.input.setValue( inputText );
+               input.buildTagsFromInput();
+
+               return input.getItems().map( function ( item ) {
+                       return item.getData();
+               } );
+       }
+
+       QUnit.test( 'Text with commas gets turned into tags', function ( assert 
) {
+               assert.deepEqual(
+                       getTagsFromInput( 'initial, comma separated, values' ),
+                       [
+                               'initial',
+                               'comma separated',
+                               'values'
+                       ]
+               );
+       } );
+
+       QUnit.test( 'Extra commas do not cause empty tag creation', function ( 
assert ) {
+               assert.deepEqual(
+                       getTagsFromInput( ',initial,, comma separated, 
values,,' ),
+                       [
+                               'initial',
+                               'comma separated',
+                               'values'
+                       ]
+               );
+       } );
+
 }( mediaWiki ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9415a96b77ce16b4e0ddfeb1eeef4c53fccee9cc
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AdvancedSearch
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>

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

Reply via email to