Commit 5f6eb09c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve issue filtering. Make tests pass

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent e8f1331f
......@@ -43,25 +43,31 @@
$(".selected_issue").bind "change", Issues.checkChanged
# Make sure we trigger ajax request only after user stop typing
initSearch: ->
form = $("#issue_search_form")
last_terms = ""
@timer = null
$("#issue_search").keyup ->
terms = $(this).val()
unless terms is last_terms
last_terms = terms
if terms.length >= 2 or terms.length is 0
$.ajax
type: "GET"
url: location.href
data: "issue_search=" + terms
complete: ->
$(".loading").hide()
success: (data) ->
$('.issues-holder').html(data.html)
Issues.reload()
dataType: "json"
clearTimeout(@timer);
@timer = setTimeout(Issues.filterResults, 500)
filterResults: =>
form = $("#issue_search_form")
search = $("#issue_search").val()
$('.issues-holder').css("opacity", '0.5')
issues_url = form.attr('action') + '? '+ form.serialize()
$.ajax
type: "GET"
url: form.attr('action')
data: form.serialize()
complete: ->
$('.issues-holder').css("opacity", '1.0')
success: (data) ->
$('.issues-holder').html(data.html)
# Change url so if user reload a page - search results are saved
History.replaceState {page: issues_url}, document.title, issues_url
Issues.reload()
dataType: "json"
checkChanged: ->
checked_issues = $(".selected_issue:checked")
......
......@@ -24,7 +24,7 @@
%i.icon.icon-list
= form_tag project_issues_path(@project), method: :get, id: "issue_search_form", class: 'pull-left issue-search-form' do
.append-right-10.hidden-xs.hidden-sm
= search_field_tag :issue_search, nil, { placeholder: 'Filter by title or description', class: 'form-control issue_search search-text-input input-mn-300' }
= search_field_tag :issue_search, params[:issue_search], { placeholder: 'Filter by title or description', class: 'form-control issue_search search-text-input input-mn-300' }
= hidden_field_tag :state, params['state']
= hidden_field_tag :scope, params['scope']
= hidden_field_tag :assignee_id, params['assignee_id']
......
......@@ -74,34 +74,34 @@ class ProjectIssues < Spinach::FeatureSteps
end
Given 'I fill in issue search with "Re"' do
fill_in 'issue_search', with: "Re"
filter_issue "Re"
end
Given 'I fill in issue search with "Bu"' do
fill_in 'issue_search', with: "Bu"
filter_issue "Bu"
end
And 'I fill in issue search with ".3"' do
fill_in 'issue_search', with: ".3"
filter_issue ".3"
end
And 'I fill in issue search with "Something"' do
fill_in 'issue_search', with: "Something"
filter_issue "Something"
end
And 'I fill in issue search with ""' do
fill_in 'issue_search', with: ""
filter_issue ""
end
Given 'project "Shop" has milestone "v2.2"' do
project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v2.2", project: project)
3.times { create(:issue, project: project, milestone: milestone) }
end
And 'project "Shop" has milestone "v3.0"' do
project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v3.0", project: project)
3.times { create(:issue, project: project, milestone: milestone) }
......@@ -117,20 +117,20 @@ class ProjectIssues < Spinach::FeatureSteps
end
When 'I select first assignee from "Shop" project' do
project = Project.find_by(name: "Shop")
first_assignee = project.users.first
select first_assignee.name, from: "assignee_id"
end
Then 'I should see first assignee from "Shop" as selected assignee' do
issues_assignee_selector = "#issue_assignee_id_chzn > a"
project = Project.find_by(name: "Shop")
assignee_name = project.users.first.name
page.find(issues_assignee_selector).should have_content(assignee_name)
end
And 'project "Shop" have "Release 0.4" open issue' do
project = Project.find_by(name: "Shop")
create(:issue,
title: "Release 0.4",
project: project,
......@@ -140,7 +140,6 @@ class ProjectIssues < Spinach::FeatureSteps
end
And 'project "Shop" have "Tweet control" open issue' do
project = Project.find_by(name: "Shop")
create(:issue,
title: "Tweet control",
project: project,
......@@ -148,7 +147,6 @@ class ProjectIssues < Spinach::FeatureSteps
end
And 'project "Shop" have "Release 0.3" closed issue' do
project = Project.find_by(name: "Shop")
create(:closed_issue,
title: "Release 0.3",
project: project,
......@@ -189,25 +187,23 @@ class ProjectIssues < Spinach::FeatureSteps
end
step 'project \'Shop\' has issue \'Bugfix1\' with description: \'Description for issue1\'' do
project = Project.find_by(name: 'Shop')
issue = create(:issue, title: 'Bugfix1', description: 'Description for issue1', project: project)
end
step 'project \'Shop\' has issue \'Feature1\' with description: \'Feature submitted for issue1\'' do
project = Project.find_by(name: 'Shop')
issue = create(:issue, title: 'Feature1', description: 'Feature submitted for issue1', project: project)
end
step 'I fill in issue search with \'Description for issue1\'' do
fill_in 'issue_search', with: 'Description for issue'
filter_issue 'Description for issue'
end
step 'I fill in issue search with \'issue1\'' do
fill_in 'issue_search', with: 'issue1'
filter_issue 'issue1'
end
step 'I fill in issue search with \'Rock and roll\'' do
fill_in 'issue_search', with: 'Description for issue'
filter_issue 'Description for issue'
end
step 'I should see \'Bugfix1\' in issues' do
......@@ -221,4 +217,15 @@ class ProjectIssues < Spinach::FeatureSteps
step 'I should not see \'Bugfix1\' in issues' do
page.should_not have_content 'Bugfix1'
end
def filter_issue(text)
fill_in 'issue_search', with: text
# make sure AJAX request finished
URI.parse(current_url).request_uri == project_issues_path(project, issue_search: text)
end
def project
@project ||= Project.find_by(name: 'Shop')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment