jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/405290 )
Change subject: Change the behavior of search term fields.
......................................................................
Change the behavior of search term fields.
Bug: T181296
Change-Id: I935fcdd537f02526bb09176c21bcf321376cb771
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M modules/ext.advancedSearch.AdvancedOptionsBuilder.js
M modules/ui/ext.advancedSearch.ArbitraryWordInput.js
M tests/qunit/ui/ArbitraryWordInput.test.js
M tests/selenium/pageobjects/search.page.js
M tests/selenium/specs/advancedsearch.js
8 files changed, 178 insertions(+), 27 deletions(-)
Approvals:
Gabriel Birke: Looks good to me, approved
jenkins-bot: Verified
diff --git a/extension.json b/extension.json
index 41ba98b..a06274f 100644
--- a/extension.json
+++ b/extension.json
@@ -110,7 +110,7 @@
"advancedsearch-optgroup-text",
"advancedsearch-optgroup-structure",
"advancedsearch-optgroup-files",
- "advancedSearch-placeholder-commas"
+ "advancedSearch-placeholder-exact-text"
],
"dependencies": [
"ext.advancedSearch.ui.ArbitraryWordInput"
diff --git a/i18n/en.json b/i18n/en.json
index dc5463a..1d2cfb8 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -33,7 +33,7 @@
"advancedsearch-help-filew": ";Description\n:These fields allow you to
specify the width of the file.\n;Be aware of the following\n:* This is only
applicable to file types that have width and height, like videos and
images.\n;Help
page\n:[https://www.mediawiki.org/wiki/Help:CirrusSearch#File_measures
Filemeasures]\n;Syntax-equivalent in the normal search\n:Numbers with
<code>filew</code> before them like <code>filew:>800</code>.",
"advancedsearch-help-fileh": ";Description\n:These fields allow you to
specify the height of the file.\n;Be aware of the following\n:* This is only
applicable to file types that have width and height, like videos and
images.\n;Help
page\n:[https://www.mediawiki.org/wiki/Help:CirrusSearch#File_measures
Filemeasures]\n;Syntax-equivalent in the normal search\n:Numbers with
<code>fileh</code> before them like <code>fileh:>600</code>.",
- "advancedSearch-placeholder-commas": "Type words separated by comma
e.g. cats, goats, ...",
+ "advancedSearch-placeholder-exact-text": "Put exact words in quotes:
\"cat loves goat\"",
"advancedsearch-filetype-section-types": "General file types",
"advancedsearch-filetype-section-image": "Image formats",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index bfd63fb..dab425a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -33,7 +33,7 @@
"advancedsearch-help-filetype": "Help text shown in a dialog for the
field for file type",
"advancedsearch-help-filew": "Help text shown in a dialog for the field
for file width in pixels",
"advancedsearch-help-fileh": "Help text shown in a dialog for the field
for file height in pixels",
- "advancedSearch-placeholder-commas": "Placeholder text shown in fields
that accept multiple values separated by commas",
+ "advancedSearch-placeholder-exact-text": "Placeholder that is shown for
the field exact words",
"advancedsearch-filetype-section-types": "Label for the file type
section",
"advancedsearch-filetype-section-image": "Label for the image format
section",
"advancedsearch-filetype-section-video": "Label for the video format
section",
diff --git a/modules/ext.advancedSearch.AdvancedOptionsBuilder.js
b/modules/ext.advancedSearch.AdvancedOptionsBuilder.js
index b12c630..ae94de1 100644
--- a/modules/ext.advancedSearch.AdvancedOptionsBuilder.js
+++ b/modules/ext.advancedSearch.AdvancedOptionsBuilder.js
@@ -188,33 +188,58 @@
group: 'text',
id: 'plain',
formatter: function ( val ) {
- return val;
- }
- },
- {
- group: 'text',
- id: 'phrase',
- formatter: function ( val ) {
if ( Array.isArray( val ) ) {
- return $.map( val,
enforceQuotes ).join( ' ' );
+ return val.join( ' ' );
}
- return enforceQuotes( val );
+ return val;
},
init: function () {
return new
mw.libs.advancedSearch.ui.ArbitraryWordInput(
self.state,
{
- optionId:
'phrase',
- placeholder:
mw.msg( 'advancedSearch-placeholder-commas' )
+ optionId:
'plain',
+ id:
'advancedSearchOption-plain'
}
);
}
},
{
group: 'text',
+ id: 'phrase',
+ formatter: function ( val ) {
+ return val;
+ },
+ init: function () {
+ return new
mw.libs.advancedSearch.ui.TextInput(
+ self.state,
+ {
+ id:
'advancedSearchOption-phrase',
+ optionId:
'phrase',
+ placeholder:
mw.msg( 'advancedSearch-placeholder-exact-text' )
+ }
+ );
+ }
+
+ },
+ {
+ group: 'text',
id: 'not',
formatter: function ( val ) {
- return '-' + optionalQuotes(
val );
+ if ( Array.isArray( val ) ) {
+ return val.map(
function ( el ) {
+ return '-' + el;
+ } ).join( ' ' );
+ }
+ return '-' + val;
+ },
+ init: function () {
+ return new
mw.libs.advancedSearch.ui.ArbitraryWordInput(
+ self.state,
+ {
+ optionId: 'not',
+ id:
'advancedSearchOption-not'
+ }
+ );
}
},
{
@@ -231,7 +256,7 @@
self.state,
{
optionId: 'or',
- placeholder:
mw.msg( 'advancedSearch-placeholder-commas' )
+ id:
'advancedSearchOption-or'
}
);
}
@@ -259,7 +284,10 @@
init: function () {
return new
mw.libs.advancedSearch.ui.TemplateSearch(
self.state,
- { optionId:
'hastemplate' }
+ {
+ optionId:
'hastemplate',
+ id:
'advancedSearchOption-hastemplate'
+ }
);
},
customEventHandling: true
@@ -290,6 +318,7 @@
new
mw.libs.advancedSearch.dm.FileTypeOptionProvider( mw.config.get(
'advancedSearch.mimeTypes' ) ),
{
optionId:
'filetype',
+ id:
'advancedSearchOption-filetype',
name:
'advancedSearchOption-filetype'
}
);
@@ -307,7 +336,8 @@
return new
mw.libs.advancedSearch.ui.ImageDimensionInput(
self.state,
{
- optionId:
'filew'
+ optionId:
'filew',
+ id:
'advancedSearchOption-filew'
}
);
},
@@ -324,7 +354,8 @@
return new
mw.libs.advancedSearch.ui.ImageDimensionInput(
self.state,
{
- optionId:
'fileh'
+ optionId:
'fileh',
+ id:
'advancedSearchOption-fileh'
}
);
},
diff --git a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
index 30e2813..01f60e6 100644
--- a/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
+++ b/modules/ui/ext.advancedSearch.ArbitraryWordInput.js
@@ -53,7 +53,7 @@
};
mw.libs.advancedSearch.ui.ArbitraryWordInput.prototype.buildTagsFromInput =
function () {
- var segments = this.input.getValue().split( ',' );
+ var segments = this.input.getValue().split( /[, ]/ );
if ( segments.length > 1 ) {
var self = this;
diff --git a/tests/qunit/ui/ArbitraryWordInput.test.js
b/tests/qunit/ui/ArbitraryWordInput.test.js
index c1f1573..aa55ffa 100644
--- a/tests/qunit/ui/ArbitraryWordInput.test.js
+++ b/tests/qunit/ui/ArbitraryWordInput.test.js
@@ -79,31 +79,33 @@
assert.equal( input.getTextForPlaceholder(), '' );
} );
- QUnit.test( 'Text with commas gets turned into tags', function ( assert
) {
+ QUnit.test( 'Text with commas and spaces gets turned into tags',
function ( assert ) {
var input = new ArbitraryWordInput( new Model(), {} );
- input.input.setValue( 'initial, comma separated, values' );
+ input.input.setValue( 'initial,comma,separated values' );
input.buildTagsFromInput();
assert.deepEqual(
input.getValue(),
[
'initial',
- 'comma separated',
+ 'comma',
+ 'separated',
'values'
]
);
} );
- QUnit.test( 'Extra commas do not cause empty tag creation', function (
assert ) {
+ QUnit.test( 'Extra commas and spaces do not cause empty tag creation',
function ( assert ) {
var input = new ArbitraryWordInput( new Model(), {} );
- input.input.setValue( ',initial,, comma separated, values,,' );
+ input.input.setValue( ',initial,, comma separated, values,,'
);
input.buildTagsFromInput();
assert.deepEqual(
input.getValue(),
[
'initial',
- 'comma separated',
+ 'comma',
+ 'separated',
'values'
]
);
diff --git a/tests/selenium/pageobjects/search.page.js
b/tests/selenium/pageobjects/search.page.js
index 3e3a77b..a21af0a 100644
--- a/tests/selenium/pageobjects/search.page.js
+++ b/tests/selenium/pageobjects/search.page.js
@@ -4,6 +4,21 @@
class SearchPage extends Page {
get searchContainer() { return browser.element(
'.mw-advancedSearch-container' ); }
+ get searchTheseWords() { return browser.element(
'#advancedSearchOption-plain' ); }
+ get searchTheseWordsTagLabel() { return browser.element(
'#advancedSearchOption-plain .oo-ui-tagItemWidget > .oo-ui-labelElement-label'
); }
+ get searchExactText() { return browser.element(
'#advancedSearchOption-phrase input' ); }
+ get searchNotTheseWords() { return browser.element(
'#advancedSearchOption-not' ); }
+ get searchNotTheseWordsTagLabel() { return browser.element(
'#advancedSearchOption-not .oo-ui-tagItemWidget > .oo-ui-labelElement-label' );
}
+ get searchOneWord() { return browser.element(
'#advancedSearchOption-or' ); }
+ get searchOneWordTagLabel() { return browser.element(
'#advancedSearchOption-or .oo-ui-tagItemWidget > .oo-ui-labelElement-label' ); }
+ get searchExpandablePane() { return browser.element(
'.mw-advancedSearch-expandablePane' ); }
+ formWasSubmitted() { return browser.getUrl().match(
/\?advancedSearchOption-original=/ ) !== null; }
+ getSearchURL() {
+ let search = browser.getUrl().split( '&' ).filter( function (
part ) {
+ return part.match( /^search=/ );
+ } );
+ return decodeURIComponent( search[ 0 ] );
+ }
open() {
super.open( 'Special:Search' );
diff --git a/tests/selenium/specs/advancedsearch.js
b/tests/selenium/specs/advancedsearch.js
index 315d529..286ea0b 100644
--- a/tests/selenium/specs/advancedsearch.js
+++ b/tests/selenium/specs/advancedsearch.js
@@ -6,6 +6,23 @@
describe( 'Advanced Search', function () {
+ function waitForAdvancedSearchToLoad() {
+ browser.waitForVisible( '.mw-advancedSearch-container', 5000 );
+ }
+
+ function testPillCreation( pillField, pillFieldLabels, input,
expectedLabels ) {
+ SearchPage.open();
+ waitForAdvancedSearchToLoad();
+
+ SearchPage.searchExpandablePane.click();
+ pillField.click();
+ browser.keys( input );
+ pillFieldLabels.getText().map( function ( text, idx ) {
+ assert( text === expectedLabels[ idx ] );
+ } );
+
+ }
+
it( 'has the advanced search extension installed', function () {
SpecialPage.open();
@@ -17,8 +34,94 @@
it( 'inserts advanced search elements on search page', function () {
SearchPage.open();
-
+ waitForAdvancedSearchToLoad();
assert( SearchPage.searchContainer.isVisible() );
+ } );
+
+ it( 'finds no placeholders for "These words" "None of these words" and
"One of these words"', function () {
+
+ SearchPage.open();
+ waitForAdvancedSearchToLoad();
+
+ assert( SearchPage.searchTheseWords.element( 'input'
).getAttribute( 'placeholder' ) === '' );
+ assert( SearchPage.searchNotTheseWords.element( 'input'
).getAttribute( 'placeholder' ) === '' );
+ assert( SearchPage.searchOneWord.element( 'input'
).getAttribute( 'placeholder' ) === '' );
+
+ } );
+
+ it( 'finds placeholder for "Exactly this text".', function () {
+
+ SearchPage.open();
+ waitForAdvancedSearchToLoad();
+ assert( SearchPage.searchExactText.getAttribute( 'placeholder'
) !== '' );
+
+ } );
+
+ it( 'displays "These words" as a pill field ', function () {
+
+ testPillCreation( SearchPage.searchTheseWords,
SearchPage.searchTheseWordsTagLabel, 'test test2,', [ 'test', 'test2' ] );
+
+ } );
+
+ it( 'displays "One of these words" as a pill field', function () {
+
+ testPillCreation( SearchPage.searchOneWord,
SearchPage.searchOneWordTagLabel, 'testäöü test2äß, testme3\uE007', [
'testäöü', 'test2äß', 'testme3' ] );
+
+ } );
+
+ it( 'displays "None of these words" as a pill field', function () {
+
+ testPillCreation( SearchPage.searchNotTheseWords,
SearchPage.searchNotTheseWordsTagLabel, 'test, test2,', [ 'test', 'test2' ] );
+
+ } );
+
+ it( 'submits the search on enter when there is no text in "These Words"
field', function () {
+ SearchPage.open();
+ waitForAdvancedSearchToLoad();
+
+ SearchPage.searchExpandablePane.click();
+ SearchPage.searchTheseWords.click();
+ browser.keys( '\uE007' );
+ assert( SearchPage.formWasSubmitted() );
+
+ } );
+
+ it( 'does not submit the search on enter when there is text in "These
Words" field', function () {
+ SearchPage.open();
+ waitForAdvancedSearchToLoad();
+
+ SearchPage.searchExpandablePane.click();
+ SearchPage.searchTheseWords.click();
+ browser.keys( 'test\uE007' );
+ assert( !SearchPage.formWasSubmitted() );
+
+ } );
+
+ it( 'submits the search on double enter when there is text in "These
Words" field', function () {
+ SearchPage.open();
+ waitForAdvancedSearchToLoad();
+
+ SearchPage.searchExpandablePane.click();
+ SearchPage.searchTheseWords.click();
+ browser.keys( 'test\uE007\uE007' );
+ assert( SearchPage.formWasSubmitted() );
+
+ } );
+
+ it( 'submits the search with the correct search terms from all the pill
fields', function () {
+ SearchPage.open();
+ waitForAdvancedSearchToLoad();
+
+ SearchPage.searchExpandablePane.click();
+ SearchPage.searchTheseWords.click();
+ browser.keys( 'test,' );
+ SearchPage.searchNotTheseWords.click();
+ browser.keys( 'test3 ' );
+ SearchPage.searchOneWord.click();
+ browser.keys( 'test4 test5' );
+ SearchPage.searchExactText.setValue( '"test1 test2"\uE007' );
+
+ assert( SearchPage.getSearchURL() ===
'search=test+"test1+test2"+-test3+test4+OR+test5' );
} );
--
To view, visit https://gerrit.wikimedia.org/r/405290
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I935fcdd537f02526bb09176c21bcf321376cb771
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/AdvancedSearch
Gerrit-Branch: master
Gerrit-Owner: Tonina Zhelyazkova <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Andrew-WMDE <[email protected]>
Gerrit-Reviewer: Gabriel Birke <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits