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
[36937] Fix navigation to active wiki item and add spec for it (#9264)
Oliver Güntherad07264c4f92
diff --git a/frontend/src/app/components/main-menu/main-menu-navigation.service.ts b/frontend/src/app/components/main-menu/main-menu-navigation.service.tsindex f09c975308d..4e4602c824c 100644--- a/frontend/src/app/components/main-menu/main-menu-navigation.service.ts+++ b/frontend/src/app/components/main-menu/main-menu-navigation.service.ts@@ -69,12 +69,11 @@ export class MainMenuNavigationService {// Wrap main itemthis.wrapMainItem();- // Scroll to the active item- const selected = jQuery('.main-item-wrapper a.selected');- if (selected.length > 0) {- selected[0].scrollIntoView();- }+ // Scroll to the active item or if none found, the active menu wrapper+ const selected = document.querySelector('.tree-menu--item.-selected') ||+ document.querySelector('.main-item-wrapper a.selected');+ selected?.scrollIntoView();// Recreate togglerconst toggler = this.recreateToggler();diff --git a/spec/features/wiki/wiki_page_navigation_spec.rb b/spec/features/wiki/wiki_page_navigation_spec.rbnew file mode 100644index 00000000000..83e79605865--- /dev/null+++ b/spec/features/wiki/wiki_page_navigation_spec.rb@@ -0,0 +1,61 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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 docs/COPYRIGHT.rdoc for more details.+#++++require 'spec_helper'++describe 'Wiki page navigation spec', type: :feature, js: true do+ shared_let(:admin) { FactoryBot.create :admin }+ current_user { admin }++ let(:project) { FactoryBot.create :project, enabled_module_names: %w[wiki] }+ let!(:wiki_page_55) do+ FactoryBot.create :wiki_page_with_content,+ wiki: project.wiki,+ title: 'Wiki Page No. 55'+ end+ let!(:wiki_pages) do+ FactoryBot.create_list(:wiki_page_with_content, 30, wiki: project.wiki)+ end++ # Always use the same user for the wiki pages+ # that otherwise gets created+ before do+ FactoryBot.set_factory_default(:author, admin)+ end++ it 'scrolls to the selected page on load (Regression #36937)' do+ visit project_wiki_path(project, wiki_page_55)++ expect(page).to have_selector('div.wiki-content')++ expect(page).to have_selector('.title-container h2', text: 'Wiki Page No. 55')++ # Expect scrolled to menu node+ expect_element_in_view page.find('.tree-menu--item.-selected', text: 'Wiki Page No. 55')+ end+enddiff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex ba334d7f4a7..86e0bf48db0 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -30,7 +30,12 @@ require File.expand_path('../config/environment', __dir__)require 'factory_bot_rails'require 'rspec/rails'require 'shoulda/matchers'++# Require test_prof helpers for better performance around factories/specs+# see https://test-prof.evilmartians.io for all options.require 'test_prof/recipes/rspec/before_all'+require 'test_prof/recipes/rspec/let_it_be'+require "test_prof/recipes/rspec/factory_default"# Requires supporting ruby files with custom matchers and macros, etc, in# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` arediff --git a/spec/support/shared/scroll_into_view_helpers.rb b/spec/support/shared/scroll_into_view_helpers.rbindex 3fbf98c7383..72c2d240d85 100644--- a/spec/support/shared/scroll_into_view_helpers.rb+++ b/spec/support/shared/scroll_into_view_helpers.rb@@ -41,3 +41,21 @@ def scroll_to_and_click(element)element.clickendend++def expect_element_in_view(element)+ script = <<-JS+ (function(el) {+ var rect = el.getBoundingClientRect();+ return (+ rect.top >= 0 && rect.left >= 0 &&+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&+ rect.right <= (window.innerWidth || document.documentElement.clientWidth)+ );+ })(arguments[0]);+ JS++ retry_block do+ result = page.evaluate_script(script, element.native)+ raise "Expected #{element} to be visible in window, but wasn't." unless result+ end+enddiff --git a/spec/support/shared_let.rb b/spec/support/shared_let.rbindex bb213f7954e..5992d89e3ac 100644--- a/spec/support/shared_let.rb+++ b/spec/support/shared_let.rb@@ -38,9 +38,6 @@## Since test-prof added `let_it_be` this is only a wrapper for it# before_all / let_it_be fixture-require 'test_prof/recipes/rspec/before_all'-require 'test_prof/recipes/rspec/let_it_be'-def shared_let(key, reload: true, refind: false, &block)let_it_be(key, reload: reload, refind: refind, &block)end