From 571685d590142cae54e9e2ee01d5eefd8e1ec371 Mon Sep 17 00:00:00 2001 From: Augier Date: Mon, 16 Mar 2015 10:46:59 +0100 Subject: [PATCH] Fix the broken searchbar (#5787) --- .../javascripts/app/views/search_view.js | 6 ++-- features/desktop/search.feature | 33 +++++++++++++++++++ features/step_definitions/search_steps.rb | 9 +++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 features/desktop/search.feature create mode 100644 features/step_definitions/search_steps.rb diff --git a/app/assets/javascripts/app/views/search_view.js b/app/assets/javascripts/app/views/search_view.js index 3453a969e..aed2e54ca 100644 --- a/app/assets/javascripts/app/views/search_view.js +++ b/app/assets/javascripts/app/views/search_view.js @@ -58,11 +58,13 @@ app.views.Search = app.views.Base.extend({ }, selectItemCallback: function(evt, data, formatted){ + var self = this.context; + if(data.search === true){ - window.location = this.searchFormAction + '?' + this.searchInputName + '=' + data.name; + window.location = self.searchFormAction + '?' + self.searchInputName + '=' + data.name; } else{ // The actual result - this.options.element.val(formatted); + self.options.element.val(formatted); window.location = data.url ? data.url : '/tags/' + data.name.substring(1); } } diff --git a/features/desktop/search.feature b/features/desktop/search.feature new file mode 100644 index 000000000..da49164df --- /dev/null +++ b/features/desktop/search.feature @@ -0,0 +1,33 @@ +@javascript +Feature: search for users and hashtags + In order to find my friends on diaspora + As a user + I want search for them + +Background: + Given following users exist: + | username | email | + | Bob Jones | bob@bob.bob | + | Alice Smith | alice@alice.alice | + And I sign in as "bob@bob.bob" + +Scenario: search for a user and go to its profile + When I enter "Alice Sm" in the search input + Then I should see "Alice Smith" within ".ac_results" + + When I click on the first search result + Then I should see "Alice Smith" within ".profile_header #name" + +Scenario: search for a inexistent user and go to the search page + When I enter "Trinity" in the search input + Then I should see "Search for Trinity" within ".ac_even" + + When I click on the first search result + Then I should see "Users matching Trinity" within "#search_title" + +Scenario: search for a tag + When I enter "#Matrix" in the search input + Then I should see "#matrix" within ".ac_even" + + When I click on the first search result + Then I should be on the tag page for "matrix" diff --git a/features/step_definitions/search_steps.rb b/features/step_definitions/search_steps.rb new file mode 100644 index 000000000..fba8cf1e8 --- /dev/null +++ b/features/step_definitions/search_steps.rb @@ -0,0 +1,9 @@ +When /^I enter "([^"]*)" in the search input$/ do |search_term| + fill_in "q", :with => search_term +end + +When /^I click on the first search result$/ do + within(".ac_results") do + find("li", match: :first).click + end +end