Manybubbles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/78383


Change subject: Basic regression test for highlighting found terms
......................................................................

Basic regression test for highlighting found terms

Change-Id: I37b480460415630ebedbaeab9519f9894e2e0bfd
---
A tests/browser/features/full_text_highlighting.feature
M tests/browser/features/step_definitions/search_steps.rb
M tests/browser/features/support/build_pages.rb
M tests/browser/features/support/pages/search_results_page.rb
4 files changed, 36 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/83/78383/1

diff --git a/tests/browser/features/full_text_highlighting.feature 
b/tests/browser/features/full_text_highlighting.feature
new file mode 100644
index 0000000..9bcc687
--- /dev/null
+++ b/tests/browser/features/full_text_highlighting.feature
@@ -0,0 +1,16 @@
+Feature: Full text search highlighting
+  @setup_main
+  Scenario Outline: Found words are highlighted
+    Given I am at a random page
+    When I search for <term>
+    Then I am on a page titled Search results
+    And <highlighted_title> is the highlighted title of the first search result
+    And <highlighted_text> is the highlighted text of the first search result
+  Examples:
+    | term                       | highlighted_title        | highlighted_text 
                    |
+    | two words                  | *Two* *Words*            | ffnonesenseword 
catapult pickles     |
+    | pickles                    | Two Words                | ffnonesenseword 
catapult *pickles*   |
+    | ffnonesenseword pickles    | Two Words                | 
*ffnonesenseword* catapult *pickles* |
+    | two words catapult pickles | *Two* *Words*            | ffnonesenseword 
*catapult* *pickles* |
+    | template:test pickle       | Template:Template *Test* | *pickles*        
                    |
+    | Africa test                | *África*                 | for *testing*    
                    |
\ No newline at end of file
diff --git a/tests/browser/features/step_definitions/search_steps.rb 
b/tests/browser/features/step_definitions/search_steps.rb
index d72a88b..a20846f 100644
--- a/tests/browser/features/step_definitions/search_steps.rb
+++ b/tests/browser/features/step_definitions/search_steps.rb
@@ -100,6 +100,12 @@
     end
   end
 end
+Then(/^(.*) is the highlighted title of the first search result$/) do 
|highlighted|
+  on(SearchResultsPage).first_result_highlighted_title.should == highlighted
+end
+Then(/^(.*) is the highlighted text of the first search result$/) do 
|highlighted|
+  on(SearchResultsPage).first_result_highlighted_text.should == highlighted
+end
 Then(/^(.+) is( not)? in the search results$/) do |title, not_searching|
   found = false
   on(SearchResultsPage).results.each do |result|
diff --git a/tests/browser/features/support/build_pages.rb 
b/tests/browser/features/support/build_pages.rb
index 7dab7ab..ae906d8 100644
--- a/tests/browser/features/support/build_pages.rb
+++ b/tests/browser/features/support/build_pages.rb
@@ -6,7 +6,7 @@
       And a page named Template:Template Test exists with contents pickles
       And a page named Catapult exists with contents ♙ asdf 
[[Category:Weaponry]]
       And a page named Amazing Catapult exists with contents test 
[[Category:Weaponry]]
-      And a page named Two Words exists with contents catapult 
{{Template_Test}} [[Category:TwoWords]]
+      And a page named Two Words exists with contents ffnonesenseword catapult 
{{Template_Test}} [[Category:TwoWords]]
       And a page named África exists with contents for testing
       And a page named Rdir exists with contents #REDIRECT [[Two Words]]
       And a page named AlphaBeta exists with contents [[Category:Alpha]] 
[[Category:Beta]]
diff --git a/tests/browser/features/support/pages/search_results_page.rb 
b/tests/browser/features/support/pages/search_results_page.rb
index 21e4399..1c94ea6 100644
--- a/tests/browser/features/support/pages/search_results_page.rb
+++ b/tests/browser/features/support/pages/search_results_page.rb
@@ -6,6 +6,7 @@
   text_field(:search, id: 'searchText')
   h1(:title, id: 'firstHeading')
   div(:first_result, :class => 'mw-search-result-heading')
+  div(:first_result_text, :class => 'searchresult')
   button(:simple_search_button, value: 'Search')
   text_field(:search_input, name: 'search')
   div(:suggestion_wrapper, class: 'searchdidyoumean')
@@ -15,4 +16,16 @@
   def results
     @browser.divs(:class => 'mw-search-result-heading')
   end
+  def first_result_highlighted_title
+    get_highlighted_text(first_result_element.link_element)
+  end
+  def first_result_highlighted_text
+    get_highlighted_text(first_result_text_element)
+  end
+  private
+
+  def get_highlighted_text(element)
+    result = element.element.attribute_value('innerHTML').strip
+    result.gsub('<span class="searchmatch">', '*').gsub('</span>', '*')
+  end
 end

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I37b480460415630ebedbaeab9519f9894e2e0bfd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>

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

Reply via email to