Commit f932996e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-issue-tests' into 'master'

Improve issues filtering textfield

* make issue filter work visible
* update browser url so after page reload I don't loose my filter
* don't send a lot of requests - let user stop typing
* make tests finally pass!!!

See merge request !1063
parents fb6cd420 5f6eb09c
...@@ -43,25 +43,31 @@ ...@@ -43,25 +43,31 @@
$(".selected_issue").bind "change", Issues.checkChanged $(".selected_issue").bind "change", Issues.checkChanged
# Make sure we trigger ajax request only after user stop typing
initSearch: -> initSearch: ->
form = $("#issue_search_form") @timer = null
last_terms = ""
$("#issue_search").keyup -> $("#issue_search").keyup ->
terms = $(this).val() clearTimeout(@timer);
unless terms is last_terms @timer = setTimeout(Issues.filterResults, 500)
last_terms = terms
if terms.length >= 2 or terms.length is 0 filterResults: =>
$.ajax form = $("#issue_search_form")
type: "GET" search = $("#issue_search").val()
url: location.href $('.issues-holder').css("opacity", '0.5')
data: "issue_search=" + terms issues_url = form.attr('action') + '? '+ form.serialize()
complete: ->
$(".loading").hide() $.ajax
success: (data) -> type: "GET"
$('.issues-holder').html(data.html) url: form.attr('action')
Issues.reload() data: form.serialize()
dataType: "json" 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: -> checkChanged: ->
checked_issues = $(".selected_issue:checked") checked_issues = $(".selected_issue:checked")
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
%i.icon.icon-list %i.icon.icon-list
= form_tag project_issues_path(@project), method: :get, id: "issue_search_form", class: 'pull-left issue-search-form' do = 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 .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 :state, params['state']
= hidden_field_tag :scope, params['scope'] = hidden_field_tag :scope, params['scope']
= hidden_field_tag :assignee_id, params['assignee_id'] = hidden_field_tag :assignee_id, params['assignee_id']
......
...@@ -74,34 +74,34 @@ class ProjectIssues < Spinach::FeatureSteps ...@@ -74,34 +74,34 @@ class ProjectIssues < Spinach::FeatureSteps
end end
Given 'I fill in issue search with "Re"' do Given 'I fill in issue search with "Re"' do
fill_in 'issue_search', with: "Re" filter_issue "Re"
end end
Given 'I fill in issue search with "Bu"' do Given 'I fill in issue search with "Bu"' do
fill_in 'issue_search', with: "Bu" filter_issue "Bu"
end end
And 'I fill in issue search with ".3"' do And 'I fill in issue search with ".3"' do
fill_in 'issue_search', with: ".3" filter_issue ".3"
end end
And 'I fill in issue search with "Something"' do And 'I fill in issue search with "Something"' do
fill_in 'issue_search', with: "Something" filter_issue "Something"
end end
And 'I fill in issue search with ""' do And 'I fill in issue search with ""' do
fill_in 'issue_search', with: "" filter_issue ""
end end
Given 'project "Shop" has milestone "v2.2"' do Given 'project "Shop" has milestone "v2.2"' do
project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v2.2", project: project) milestone = create(:milestone, title: "v2.2", project: project)
3.times { create(:issue, project: project, milestone: milestone) } 3.times { create(:issue, project: project, milestone: milestone) }
end end
And 'project "Shop" has milestone "v3.0"' do And 'project "Shop" has milestone "v3.0"' do
project = Project.find_by(name: "Shop")
milestone = create(:milestone, title: "v3.0", project: project) milestone = create(:milestone, title: "v3.0", project: project)
3.times { create(:issue, project: project, milestone: milestone) } 3.times { create(:issue, project: project, milestone: milestone) }
...@@ -117,20 +117,20 @@ class ProjectIssues < Spinach::FeatureSteps ...@@ -117,20 +117,20 @@ class ProjectIssues < Spinach::FeatureSteps
end end
When 'I select first assignee from "Shop" project' do When 'I select first assignee from "Shop" project' do
project = Project.find_by(name: "Shop")
first_assignee = project.users.first first_assignee = project.users.first
select first_assignee.name, from: "assignee_id" select first_assignee.name, from: "assignee_id"
end end
Then 'I should see first assignee from "Shop" as selected assignee' do Then 'I should see first assignee from "Shop" as selected assignee' do
issues_assignee_selector = "#issue_assignee_id_chzn > a" issues_assignee_selector = "#issue_assignee_id_chzn > a"
project = Project.find_by(name: "Shop")
assignee_name = project.users.first.name assignee_name = project.users.first.name
page.find(issues_assignee_selector).should have_content(assignee_name) page.find(issues_assignee_selector).should have_content(assignee_name)
end end
And 'project "Shop" have "Release 0.4" open issue' do And 'project "Shop" have "Release 0.4" open issue' do
project = Project.find_by(name: "Shop")
create(:issue, create(:issue,
title: "Release 0.4", title: "Release 0.4",
project: project, project: project,
...@@ -140,7 +140,6 @@ class ProjectIssues < Spinach::FeatureSteps ...@@ -140,7 +140,6 @@ class ProjectIssues < Spinach::FeatureSteps
end end
And 'project "Shop" have "Tweet control" open issue' do And 'project "Shop" have "Tweet control" open issue' do
project = Project.find_by(name: "Shop")
create(:issue, create(:issue,
title: "Tweet control", title: "Tweet control",
project: project, project: project,
...@@ -148,7 +147,6 @@ class ProjectIssues < Spinach::FeatureSteps ...@@ -148,7 +147,6 @@ class ProjectIssues < Spinach::FeatureSteps
end end
And 'project "Shop" have "Release 0.3" closed issue' do And 'project "Shop" have "Release 0.3" closed issue' do
project = Project.find_by(name: "Shop")
create(:closed_issue, create(:closed_issue,
title: "Release 0.3", title: "Release 0.3",
project: project, project: project,
...@@ -189,25 +187,23 @@ class ProjectIssues < Spinach::FeatureSteps ...@@ -189,25 +187,23 @@ class ProjectIssues < Spinach::FeatureSteps
end end
step 'project \'Shop\' has issue \'Bugfix1\' with description: \'Description for issue1\'' do 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) issue = create(:issue, title: 'Bugfix1', description: 'Description for issue1', project: project)
end end
step 'project \'Shop\' has issue \'Feature1\' with description: \'Feature submitted for issue1\'' do 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) issue = create(:issue, title: 'Feature1', description: 'Feature submitted for issue1', project: project)
end end
step 'I fill in issue search with \'Description for issue1\'' do 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 end
step 'I fill in issue search with \'issue1\'' do step 'I fill in issue search with \'issue1\'' do
fill_in 'issue_search', with: 'issue1' filter_issue 'issue1'
end end
step 'I fill in issue search with \'Rock and roll\'' do 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 end
step 'I should see \'Bugfix1\' in issues' do step 'I should see \'Bugfix1\' in issues' do
...@@ -221,4 +217,15 @@ class ProjectIssues < Spinach::FeatureSteps ...@@ -221,4 +217,15 @@ class ProjectIssues < Spinach::FeatureSteps
step 'I should not see \'Bugfix1\' in issues' do step 'I should not see \'Bugfix1\' in issues' do
page.should_not have_content 'Bugfix1' page.should_not have_content 'Bugfix1'
end 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 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