From e3395e3a9d683f62fb67e4d7b54381aad73e7a9e Mon Sep 17 00:00:00 2001 From: Clement Ho Date: Mon, 14 Nov 2016 16:55:38 -0600 Subject: [PATCH] Add specs for clear search button --- spec/features/issues/search_bar_spec.rb | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 spec/features/issues/search_bar_spec.rb diff --git a/spec/features/issues/search_bar_spec.rb b/spec/features/issues/search_bar_spec.rb new file mode 100644 index 00000000000..1d632671fe2 --- /dev/null +++ b/spec/features/issues/search_bar_spec.rb @@ -0,0 +1,55 @@ +require 'rails_helper' + +describe 'Search bar', feature: true do + include WaitForAjax + + let!(:project) { create(:project) } + let!(:group) { create(:group) } + let!(:user) { create(:user) } + + before do + project.team << [user, :master] + group.add_developer(user) + login_as(user) + create(:issue, project: project) + + visit namespace_project_issues_path(project.namespace, project) + end + + describe 'clear search button', js: true do + it 'clears text' do + search_text = 'search_text' + filtered_search = find('.filtered-search') + filtered_search.set(search_text) + + expect(filtered_search.value).to eq(search_text) + find('.filtered-search-input-container .clear-search').click + expect(filtered_search.value).to eq('') + end + + it 'hides by default' do + expect(page).to have_css('.clear-search', visible: false) + end + + it 'hides after clicked' do + filtered_search = find('.filtered-search') + filtered_search.set('a') + find('.filtered-search-input-container .clear-search').click + expect(page).to have_css('.clear-search', visible: false) + end + + it 'hides when there is no text' do + filtered_search = find('.filtered-search') + filtered_search.set('a') + filtered_search.set('') + expect(page).to have_css('.clear-search', visible: false) + end + + it 'shows when there is text' do + filtered_search = find('.filtered-search') + filtered_search.set('a') + + expect(page).to have_css('.clear-search', visible: true) + end + end +end