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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Make some feature specs faster
Christophe Bliarda698b2eca34d
diff --git a/spec/features/work_packages/table/queries/filter_spec.rb b/spec/features/work_packages/table/queries/filter_spec.rbindex 596a8d9d93e..cfe545ea1c6 100644--- a/spec/features/work_packages/table/queries/filter_spec.rb+++ b/spec/features/work_packages/table/queries/filter_spec.rb@@ -147,7 +147,7 @@ describe 'filter work packages', js: true dofilters.open_autocompleter :statusexpect(page).to have_selector('.ng-option', text: closed_status.name)- expect(page).to have_no_selector('.ng-option', text: status.name)+ expect(page).not_to have_selector('.ng-option', text: status.name)endenddiff --git a/spec/support/components/projects/top_menu.rb b/spec/support/components/projects/top_menu.rbindex 81ee859e852..8c443b1f29d 100644--- a/spec/support/components/projects/top_menu.rb+++ b/spec/support/components/projects/top_menu.rb@@ -52,7 +52,7 @@ module Componentsenddef expect_closed- page.raise_if_found(autocompleter_selector)+ expect(page).not_to have_selector(autocompleter_selector)enddef search(query)diff --git a/spec/support/components/work_packages/filters.rb b/spec/support/components/work_packages/filters.rbindex 26f02aa458b..1cce717dafc 100644--- a/spec/support/components/work_packages/filters.rb+++ b/spec/support/components/work_packages/filters.rb@@ -128,7 +128,7 @@ module Componentselsif valueexpect_value(id, Array(value))else- expect(page).to have_no_selector("#values-#{id}")+ expect(page).not_to have_selector("#values-#{id}")endend@@ -148,8 +148,8 @@ module Componentsid = selector || name.downcaseretry_block do- page.raise_if_found_select("operators-#{id}")- page.raise_if_found_select("values-#{id}")+ expect(page).not_to have_select("operators-#{id}")+ expect(page).not_to have_select("values-#{id}")endend@@ -164,21 +164,24 @@ module Componentsenddef open_autocompleter(id)- input = page.all("#filter_#{id} .advanced-filters--filter-value .ng-input input").first-- if input- input.click- input- end+ with_filter_input_element(id, &:click)enddef close_autocompleter(id)- input = open_autocompleter(id)- input&.send_keys :escape+ with_filter_input_element(id) do |input|+ input.send_keys :escape+ endendprotected+ def with_filter_input_element(id)+ filter_value_element = page.find("#filter_#{id} .advanced-filters--filter-value", match: :first)+ return unless filter_value_element.has_selector?(".ng-input input", wait: false)++ yield filter_value_element.find(".ng-input input")+ end+def filter_buttonfind(button_selector)end@@ -193,6 +196,7 @@ module Componentsdef set_value(id, value)retry_block do+ # wait for filter to be presentfilter_element = page.find("#filter_#{id}")if filter_element.has_selector?("[data-qa-selector='op-multi-date-picker']", wait: false)datepicker = Components::WorkPackageDatepicker.new@@ -221,9 +225,11 @@ module Componentsenddef expect_missing_value(id, value)- if page.has_selector?("#filter_#{id} .ng-select-container")+ # wait for filter to be present+ filter_element = page.find("#filter_#{id}")+ if filter_element.has_selector?(".ng-select-container", wait: false)Array(value).each do |val|- dropdown = search_autocomplete page.find("#filter_#{id}"),+ dropdown = search_autocomplete filter_element,query: val,results_selector: '.ng-dropdown-panel-items'expect(dropdown).not_to have_selector('.ng-option', text: val)@@ -232,8 +238,9 @@ module Componentsenddef expect_value_placeholder(id)- if page.has_selector?("#filter_#{id} .ng-select-container")- expect(page).to have_selector("#filter_#{id} .ng-placeholder", text: I18n.t('js.placeholders.selection'))+ filter_element = page.find("#filter_#{id}")+ if filter_element.has_selector?(".ng-select-container", wait: false)+ expect(filter_element).to have_selector(".ng-placeholder", text: I18n.t('js.placeholders.selection'))elseraise "Non ng-select may not have placeholders currently"end@@ -245,15 +252,17 @@ module Componentsvalue.each do |v|expect(page).to have_selector("#values-#{id} .ng-value-label", text: v)end- elsif page.has_selector?("#filter_#{id} [data-qa-selector='op-multi-date-picker']")+ elsif page.has_selector?("#filter_#{id} [data-qa-selector='op-multi-date-picker']", wait: false)+ expected_value =+ if value[1]+ "#{value[0]} - #{value[1]}"+ elsif value[0]+ value[0].to_s+ else+ "-"+ endinput = page.find("#filter_#{id} [data-qa-selector='op-multi-date-picker'] input")- if value[1]- expect(input.value).to eql("#{value[0]} - #{value[1]}")- elsif value[0]- expect(input.value).to eql("#{value[0]}")- else- expect(input.value).to eql("-")- end+ expect(input.value).to eql(expected_value)elsepage.all('input').each_with_index do |input, index|expect(input.value).to eql(value[index])diff --git a/spec/support/matchers/raise_if_found.rb b/spec/support/matchers/raise_if_found.rbdeleted file mode 100644index d78978163a9..00000000000--- a/spec/support/matchers/raise_if_found.rb+++ /dev/null@@ -1,50 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2023 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-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 COPYRIGHT and LICENSE files for more details.-#++--# Extending Capybara to check or raise for an element--module Capybara- class Session- def raise_if_found(condition, *args, **kw_args)- raise_if_has_selector?(:has_selector?, condition, *args, **kw_args)- end-- def raise_if_found_field(condition, *args, **kw_args)- raise_if_has_selector?(:has_field?, condition, *args, **kw_args)- end-- def raise_if_found_select(condition, *args, **kw_args)- raise_if_has_selector?(:has_select?, condition, *args, **kw_args)- end-- def raise_if_has_selector?(method, condition, *args, **kw_args)- found = public_send(method, condition, *args, **kw_args)- raise "Expected not to find field #{condition}" if found- end- end-enddiff --git a/spec/support/pages/work_packages/work_packages_table.rb b/spec/support/pages/work_packages/work_packages_table.rbindex e4a58ecae9f..b09d6297ca0 100644--- a/spec/support/pages/work_packages/work_packages_table.rb+++ b/spec/support/pages/work_packages/work_packages_table.rb@@ -107,7 +107,7 @@ module Pagesretry_block(args: { tries: 3, base_interval: 5 }) dowithin(table_container) dowork_packages.each do |wp|- page.raise_if_found(".wp-row-#{wp.id} td.subject", text: wp.subject, wait: 1)+ expect(page).not_to have_selector(".wp-row-#{wp.id} td.subject", text: wp.subject)endendenddiff --git a/spec/support/shared/selenium_workarounds.rb b/spec/support/shared/selenium_workarounds.rbindex b91fc3a4bda..15ae46c3137 100644--- a/spec/support/shared/selenium_workarounds.rb+++ b/spec/support/shared/selenium_workarounds.rb@@ -31,12 +31,18 @@# https://bugs.chromium.org/p/chromedriver/issues/detail?id=1771module SeleniumWorkaroundsdef ensure_value_is_input_correctly(input, value:)- # Wait a bit to insert the value- sleep(0.5)- input.set value- sleep(0.5)+ correctly_set = false+ # Wait longer and longer to set the value, until it is set correctly.+ # The bug may be fixed by now...+ [0, 0.5, 1].each do |waiting_time|+ sleep(waiting_time)+ input.set value+ sleep(waiting_time)- found_value = input.value- raise "Found value #{found_value}, but expected #{value}." unless found_value == value+ correctly_set = (input.value == value)+ break if correctly_set+ end++ raise "Found value #{found_value}, but expected #{value}." unless correctly_setendend