diff --git a/spec/features/work_packages/details/details_toolbar_spec.rb b/spec/features/work_packages/details/details_toolbar_spec.rb new file mode 100644 index 0000000000..fcf341c70c --- /dev/null +++ b/spec/features/work_packages/details/details_toolbar_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' +require 'features/work_packages/work_packages_page' + +describe 'Work package details toolbar', js: true, selenium: true do + let(:project) { FactoryGirl.create :project_with_types, is_public: true } + let!(:work_package) { FactoryGirl.create :work_package, project: project } + let(:work_packages_page) { WorkPackagesPage.new(project) } + + describe 'toggle watch state' do + let(:user) { FactoryGirl.create :admin } + before do + login_as(user) + work_packages_page.visit_index(work_package) + end + + it 'toggles the watch state' do + expect(work_package.watcher_users).not_to include(user) + expect(page).to have_selector('.work-packages--details-toolbar button', text: 'Watch') + within '.work-packages--details-toolbar' do + click_button 'Watch' + end + + wait_until_requests_completed! + + expect(work_package.reload.watcher_users).to include(user) + expect(page).to have_selector('.work-packages--details-toolbar button', text: 'Unwatch') + end + end +end diff --git a/spec/support/shared/wait_until_requests_completed.rb b/spec/support/shared/wait_until_requests_completed.rb new file mode 100644 index 0000000000..50ae657869 --- /dev/null +++ b/spec/support/shared/wait_until_requests_completed.rb @@ -0,0 +1,43 @@ +#-- copyright +# OpenProject is a project management system. +# Copyright (C) 2012-2015 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: +# Copyright (C) 2006-2013 Jean-Philippe Lang +# Copyright (C) 2010-2013 the ChiliProject Team +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +# Method to manually wait for an asynchronous request (through jQuery) to complete. +# This applies to all requests through resources as well. +# +# Note: Use this only if there are no other means of detecting the sucessful +# completion of said request. +# + +def wait_until_requests_completed! + Timeout.timeout(Capybara.default_wait_time) do + loop do + active = page.evaluate_script('jQuery.active') + break if active == 0 + end + end +end