Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Rewrite flickering search controller specs to feature specs

Dombi Attila98f8c5720cb5
diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb
index ebe75bd9c13..814335e0d73 100644
--- a/spec/controllers/search_controller_spec.rb
+++ b/spec/controllers/search_controller_spec.rb
@@ -138,16 +138,6 @@ describe SearchController do
it { expect(assigns(:results_count)).to be_a(Hash) }
it { expect(assigns(:results_count)['work_packages']).to be(3) }
end
-
- describe '#view' do
- render_views
-
- it 'marks closed work packages' do
- assert_select 'dt.work_package-closed' do
- assert_select 'a', text: Regexp.new(work_package_2.status.name)
- end
- end
- end
end
context 'when searching in project and its subprojects' do
@@ -194,8 +184,6 @@ describe SearchController do
version: 3)
end
- before { allow_any_instance_of(Journal).to receive_messages(predecessor: note_1) }
-
before do
get :index, params: { q: 'note' }
end
@@ -215,21 +203,7 @@ describe SearchController do
it { expect(assigns(:results)).to include work_package_1 }
- describe '#view', skip: "This test will be rewritten as a feature spec." do
- render_views
-
- it 'highlights last note' do
- assert_select 'dt.work_package-note + dd' do
- assert_select '.description', text: note_2.notes
- end
- end
-
- it 'links to work package with anchor to highlighted note' do
- assert_select 'dt.work_package-note' do
- assert_select 'a', href: work_package_path(work_package_1, anchor: 'note-2')
- end
- end
- end
+ it { expect(assigns(:tokens)).to include 'note' }
end
end
end
diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb
index 7a0cf1577a3..67dcaf3de09 100644
--- a/spec/features/search_spec.rb
+++ b/spec/features/search_spec.rb
@@ -213,6 +213,23 @@ describe 'Search', js: true, with_mail: false, with_settings: { per_page_options
table.expect_work_package_subject(work_packages[1].subject)
end
end
+
+ context 'when a work package is closed' do
+ let(:params) { [{ q: query, scope: 'all' }] }
+ let(:run_visit) { false }
+ let(:work_package) { work_packages.last }
+
+ before do
+ work_package.update(status: create(:closed_status))
+ visit search_path(*params)
+ end
+
+ it 'marks the closed work package' do
+ within 'dt.work_package-closed' do
+ expect(page).to have_link(text: Regexp.new(work_package.status.name))
+ end
+ end
+ end
end
context 'for project search' do
@@ -381,6 +398,36 @@ describe 'Search', js: true, with_mail: false, with_settings: { per_page_options
end
end
+ describe 'search for notes' do
+ let(:work_package) { work_packages[0] }
+ let!(:note_one) do
+ create(:work_package_journal,
+ journable_id: work_package.id,
+ notes: 'Test note 1',
+ version: 2)
+ end
+ let!(:note_two) do
+ create(:work_package_journal,
+ journable_id: work_package.id,
+ notes: 'Special note 2',
+ version: 3)
+ end
+
+ it 'highlights last note' do
+ global_search.search 'note'
+ global_search.submit_in_global_scope
+
+ within('dt.work_package-note + dd') do
+ expect(page).to have_selector(".description", text: note_two.notes)
+ end
+
+ # links to work package with anchor to highlighted note
+ within('dt.work_package-note') do
+ expect(page).to have_link(href: work_package_path(work_package, anchor: 'note-2'))
+ end
+ end
+ end
+
describe 'search for projects' do
let!(:searched_for_project) { create(:project, name: 'Searched for project') }
let!(:other_project) { create(:project, name: 'Other project') }