OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/spec/support/pages/page.rb

131 lines
3.6 KiB

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
#
# 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-2017 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 docs/COPYRIGHT.rdoc for more details.
#++
module Pages
class Page
include Capybara::DSL
include RSpec::Matchers
include OpenProject::StaticRouting::UrlHelpers
def current_page?
URI.parse(current_url).path == path
end
def visit!
raise 'No path defined' unless path
visit path
self
end
def accept_alert_dialog!
alert_dialog.accept if selenium_driver?
end
def dismiss_alert_dialog!
alert_dialog.dismiss if selenium_driver?
end
def alert_dialog
page.driver.browser.switch_to.alert
end
def has_alert_dialog?
if selenium_driver?
begin
page.driver.browser.switch_to.alert
rescue ::Selenium::WebDriver::Error::NoSuchAlertError
false
end
end
end
def selenium_driver?
Capybara.current_session.driver.is_a?(Capybara::Selenium::Driver)
end
def set_items_per_page!(n)
Setting.per_page_options = "#{n}, 50, 100"
end
6 years ago
def expect_current_path(query_params = nil)
uri = URI.parse(current_url)
6 years ago
current_path = uri.path
current_path += '?' + uri.query if uri.query
6 years ago
expected_path = path
expected_path += "?#{query_params}" if query_params
expect(current_path).to eql expected_path
end
def expect_notification(type: :success, message:)
6 years ago
if notification_type == :angular
expect(page).to have_selector(".notification-box.-#{type}", text: message, wait: 20)
elsif type == :error
expect(page).to have_selector(".errorExplanation", text: message)
elsif type == :success
expect(page).to have_selector(".flash.notice", text: message)
6 years ago
else
raise NotImplementedError
end
end
def expect_and_dismiss_notification(type: :success, message:)
expect_notification(type: type, message: message)
dismiss_notification!
expect_no_notification(type: type, message: message)
end
def dismiss_notification!
if notification_type == :angular
page.find('.notification-box--close').click
else
page.find('.flash .icon-close').click
end
end
def expect_no_notification(type: :success, message: nil)
[32880] Display scheduling mode in work package view (full, split & table) (#8410) * Show icon next to start date depending on the scheduling mode * Show modal when opening date edit fields which shall be able to change the dates and the scheduling mode * Introduce flatpickr as a datepicker for the modal of the dateEditField * Use new datepicker within opDatePickerComponent * Reuse existing Datepicker class for better code abstraction * Set dates only when Instance is ready * Let augmentedDatePicker use generic DatePicker class, too. * Remove jQuery UI datepicker specific styles as they do not apply any more. * Use localized strings in new datepicker * Close datepicker only on click outside * Allow single and multi selection of dates and save changes * Update schedulingMode button correctly && remove unused method * Show combined field for start and end date within the WP single view * Show normal datepicker for most date fields and the modal with the extended datepicker only for startDate * Add datepicker edit field and component helper * Correctly save start and end date * Show correct default value for dateEditFields && Adapt some tests to new datepicker and combined date field * Fix date editor spec * Fix expecting datepicker for start/due date as milestone * Prevent overflow on body by using modal-portal class && make edit input for combinedDates visible again to show something in a create form * Only output one debounced change event for op datepicker * Show combined datepickerModal for dueDate in table, too && save correct scheduling value * Hide modal if the showing component gets destroyed * Correctly check for closed datepicker * Add spec for toggling scheduling mode * Fix setting dates to modal * Avoid too many (unnecessary) close events and use keydown instead * Fix date setting and add custom field date spec * Change layout of combined date picker modal * Switch from a range date picker to a multiple selection in order to be able to set only start or due date && Highlight date field that is changed next * Highlight range manually * Highlight dueDate initially when the user clicked on the due date field && handle special case that one of the values is not set yet. In this case we don't want to keep both values but only the newly clicked. * Move helper functions to own class && Improve the range selection to be able highlight ranges over multiple months && Prevent that a start date > due date can be chosen by setting minDate and maxDate * Adapt test to new way of changing the scheduling mode * Handle case that the user clicks on a already selected date and thus deselects it Co-authored-by: Oliver Günther <mail@oliverguenther.de>
4 years ago
if type.nil?
expect(page).to have_no_selector(".notification-box")
else
expect(page).to have_no_selector(".notification-box.-#{type}", text: message)
end
end
def path
nil
end
6 years ago
def notification_type
:angular
end
end
end