From ff01fd38f2ca6b359b7fd24662129c743be75548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 15 Nov 2016 10:16:49 +0100 Subject: [PATCH] Extend watcher tests --- .../work_packages/tabs/watcher_tab_spec.rb | 12 +++-------- spec/requests/api/v3/watcher_resource_spec.rb | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/spec/features/work_packages/tabs/watcher_tab_spec.rb b/spec/features/work_packages/tabs/watcher_tab_spec.rb index 29cc5e231f..1f5697d39d 100644 --- a/spec/features/work_packages/tabs/watcher_tab_spec.rb +++ b/spec/features/work_packages/tabs/watcher_tab_spec.rb @@ -49,7 +49,7 @@ describe 'Watcher tab', js: true, selenium: true do end shared_examples 'watchers tab' do - include_context 'ui-select helpers' + include_context 'typeahead helpers' before do login_as(user) @@ -59,14 +59,8 @@ describe 'Watcher tab', js: true, selenium: true do it 'modifying the watcher list modifies the watch button' do # Add user as watcher - trigger = find('.work-package--watchers-lookup .inplace-editing--trigger-container') - trigger.click - - input = find('input.ui-select-search') - input.click - input.send_keys [user.name, :return] - - find('.inplace-edit--control--save a').click + typeahead = find('.wp-watcher--autocomplete') + select_typeahead(typeahead, query: user.firstname, select_text: user.name) # Expect the addition of the user to toggle WP watch button expect(page).to have_selector('.work-package--watcher-name', count: 1, text: user.name) diff --git a/spec/requests/api/v3/watcher_resource_spec.rb b/spec/requests/api/v3/watcher_resource_spec.rb index dd017e4de8..e01574a9be 100644 --- a/spec/requests/api/v3/watcher_resource_spec.rb +++ b/spec/requests/api/v3/watcher_resource_spec.rb @@ -43,6 +43,8 @@ describe 'API v3 Watcher resource', type: :request do let(:work_package) { FactoryGirl.create(:work_package, project: project) } let(:available_watcher) { FactoryGirl.create :user, + firstname: 'Something', + lastname: 'Strange', member_in_project: project, member_through_role: view_work_packages_role } @@ -228,6 +230,7 @@ describe 'API v3 Watcher resource', type: :request do let(:available_watchers_path) { api_v3_paths.available_watchers work_package.id } before do + available_watcher get available_watchers_path end @@ -244,5 +247,23 @@ describe 'API v3 Watcher resource', type: :request do expect(subject.status).to eql(403) end end + + describe 'searching for a user' do + let(:available_watchers_path) { + path = api_v3_paths.available_watchers work_package.id + filters = %([{ "name": { "operator": "~", "values": ["#{query}"] } }]) + "#{path}?filters=#{filters}" + } + + context 'that does not exist' do + let(:query) { 'asdfasdfasdfasdf' } + it_behaves_like 'API V3 collection response', 0, 0, 'User' + end + + context 'that does exist' do + let(:query) { 'strange' } + it_behaves_like 'API V3 collection response', 1, 1, 'User' + end + end end end