Skip to content

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

Define base spec for multi-anchor support

Kabiru Mwenja45139fda187c
diff --git a/app/components/work_packages/activities_tab/journals/item_component.html.erb b/app/components/work_packages/activities_tab/journals/item_component.html.erb
index 832900e2444..2a0c5aa86ca 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/item_component.html.erb
@@ -8,7 +8,11 @@
render(border_box_container(
id: "activity-anchor-#{journal_container_id}",
padding: :condensed,
- "aria-label": I18n.t("activities.work_packages.activity_tab.commented")
+ "aria-label": I18n.t("activities.work_packages.activity_tab.commented"),
+ data: {
+ "anchor-activity-id": journal.sequence_version,
+ "anchor-comment-id": journal.id,
+ }
)) do |border_box_component|
border_box_component.with_header(px: 2, py: 1, data: { test_selector: "op-journal-notes-header" }) do
flex_layout(align_items: :center, justify_content: :space_between) do |header_container|
diff --git a/app/components/work_packages/activities_tab/shared_helpers.rb b/app/components/work_packages/activities_tab/shared_helpers.rb
index 65e4984dc5a..4615eaf3525 100644
--- a/app/components/work_packages/activities_tab/shared_helpers.rb
+++ b/app/components/work_packages/activities_tab/shared_helpers.rb
@@ -50,10 +50,11 @@ module WorkPackages
underline: false,
font_size: :small,
data: {
+ test_selector: "activity-anchor-link",
turbo: false,
action: "click->work-packages--activities-tab--index#setAnchor:prevent",
"work-packages--activities-tab--index-id-param": journal_activity_id(journal),
- "work-packages--activities-tab--index-anchor-name-param": anchor_name
+ "work-packages--activities-tab--index-anchor-name-param": activity_anchor_name
}
)) do
"##{journal_activity_id(journal)}"
@@ -69,10 +70,10 @@ module WorkPackages
end
def activity_anchor(journal)
- "##{anchor_name}-#{journal_activity_id(journal)}"
+ "##{activity_anchor_name}-#{journal_activity_id(journal)}"
end
- def anchor_name
+ def activity_anchor_name
OpenProject::FeatureDecisions.work_package_comment_id_url_active? ? "comment" : "activity"
end
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
index cc919a20ada..264d526bba0 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
@@ -5,10 +5,15 @@ import {
import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+enum AnchorType {
+ Comment = 'comment',
+ Activity = 'activity',
+}
+
interface CustomEventWithIdParam extends Event {
params:{
id:string;
- anchorName:string;
+ anchorName:AnchorType;
};
}
@@ -351,19 +356,19 @@ export default class IndexController extends Controller {
}
private handleInitialScroll() {
- // Ex. [ "#comment-80", "comment", "80" ]
- const activityIdMatch = window.location.hash.match(/#(comment|activity)-(\d+)/);
+ const anchorTypeRegex = new RegExp(`#(${AnchorType.Comment}|${AnchorType.Activity})-(\\d+)`);
+ const activityIdMatch = window.location.hash.match(anchorTypeRegex); // Ex. [ "#comment-80", "comment", "80" ]
if (activityIdMatch && activityIdMatch.length === 3) {
- this.scrollToActivity(activityIdMatch[2]);
+ this.scrollToActivity(activityIdMatch[1] as AnchorType, activityIdMatch[2]);
} else if (this.sortingValue === 'asc' && (!this.isMobile() || this.isWithinNotificationCenter())) {
this.scrollToBottom();
}
}
- private tryScroll(activityId:string, attempts:number, maxAttempts:number) {
+ private tryScroll(activityAnchorName:AnchorType, activityId:string, attempts:number, maxAttempts:number) {
const scrollableContainer = this.getScrollableContainer();
- const activityElement = document.getElementById(`activity-anchor-${activityId}`);
+ const activityElement = document.querySelector(`[data-anchor-${activityAnchorName}-id="${activityId}"]`);
const topPadding = 70;
if (activityElement && scrollableContainer) {
@@ -377,13 +382,13 @@ export default class IndexController extends Controller {
scrollableContainer.scrollTop = relativeTop - topPadding;
}, 50);
} else if (attempts < maxAttempts) {
- setTimeout(() => this.tryScroll(activityId, attempts + 1, maxAttempts), 1000);
+ setTimeout(() => this.tryScroll(activityAnchorName, activityId, attempts + 1, maxAttempts), 1000);
}
}
- private scrollToActivity(activityId:string) {
+ private scrollToActivity(activityAnchorName:AnchorType, activityId:string) {
const maxAttempts = 20; // wait max 20 seconds for the activity to be rendered
- this.tryScroll(activityId, 0, maxAttempts);
+ this.tryScroll(activityAnchorName, activityId, 0, maxAttempts);
}
private tryScrollToBottom(attempts:number = 0, maxAttempts:number = 20) {
@@ -434,7 +439,7 @@ export default class IndexController extends Controller {
const activityId = event.params.id;
const anchorName = event.params.anchorName;
- this.scrollToActivity(activityId);
+ this.scrollToActivity(anchorName, activityId);
window.location.hash = `#${anchorName}-${activityId}`;
}
diff --git a/spec/features/activities/work_package/activities_spec.rb b/spec/features/activities/work_package/activities_spec.rb
index 7693eddde18..75c57f3d365 100644
--- a/spec/features/activities/work_package/activities_spec.rb
+++ b/spec/features/activities/work_package/activities_spec.rb
@@ -886,30 +886,70 @@ RSpec.describe "Work package activity", :js, with_flag: { primerized_work_packag
context "when sorting set to asc" do
let!(:admin_preferences) { create(:user_preference, user: admin, others: { comments_sorting: :asc }) }
- before do
- visit project_work_package_path(project, work_package.id, "activity", anchor: "activity-1")
- wp_page.wait_for_activity_tab
+ context "with #activity- anchor" do
+ before do
+ visit project_work_package_path(project, work_package.id, "activity", anchor: "activity-1")
+ wp_page.wait_for_activity_tab
+ end
+
+ it "scrolls to the comment specified in the URL", :aggregate_failures do
+ wait_for_auto_scrolling_to_finish
+ activity_tab.expect_journal_container_at_position(50) # would be at the bottom if no anchor would be provided
+
+ activity_tab.expect_activity_anchor_link(text: "#1")
+ end
end
- it "scrolls to the comment specified in the URL", :aggregate_failures do
- sleep 1 # wait for auto scrolling to finish
- activity_tab.expect_journal_container_at_position(50) # would be at the bottom if no anchor would be provided
+ context "with #comment- anchor",
+ with_flag: { primerized_work_package_activities: true, work_package_comment_id_url: true } do
+ before do
+ visit project_work_package_path(project, work_package.id, "activity", anchor: "comment-1")
+ wp_page.wait_for_activity_tab
+ end
+
+ it "scrolls to the comment specified in the URL", :aggregate_failures do
+ wait_for_auto_scrolling_to_finish
+ activity_tab.expect_journal_container_at_position(50) # would be at the bottom if no anchor would be provided
+
+ # activity_tab.expect_no_activity_anchor_link TODO: Enable once timestamps converted to anchors
+ end
end
end
context "when sorting set to desc" do
let!(:admin_preferences) { create(:user_preference, user: admin, others: { comments_sorting: :desc }) }
- before do
- visit project_work_package_path(project, work_package.id, "activity", anchor: "activity-1")
- wp_page.wait_for_activity_tab
+ context "with #activity- anchor" do
+ before do
+ visit project_work_package_path(project, work_package.id, "activity", anchor: "activity-1")
+ wp_page.wait_for_activity_tab
+ end
+
+ it "scrolls to the comment specified in the URL", :aggregate_failures do
+ wait_for_auto_scrolling_to_finish
+ activity_tab.expect_journal_container_at_bottom # would be at the top if no anchor would be provided
+
+ activity_tab.expect_activity_anchor_link(text: "#1")
+ end
end
- it "scrolls to the comment specified in the URL", :aggregate_failures do
- sleep 1 # wait for auto scrolling to finish
- activity_tab.expect_journal_container_at_bottom # would be at the top if no anchor would be provided
+ context "with #comment- anchor",
+ with_flag: { primerized_work_package_activities: true, work_package_comment_id_url: true } do
+ before do
+ visit project_work_package_path(project, work_package.id, "activity", anchor: "comment-1")
+ wp_page.wait_for_activity_tab
+ end
+
+ it "scrolls to the comment specified in the URL", :aggregate_failures do
+ wait_for_auto_scrolling_to_finish
+ activity_tab.expect_journal_container_at_bottom # would be at the top if no anchor would be provided
+
+ # activity_tab.expect_no_activity_anchor_link TODO: Enable once timestamps converted to anchors
+ end
end
end
+
+ def wait_for_auto_scrolling_to_finish = sleep(1)
end
context "when sorting set to asc" do
diff --git a/spec/support/components/work_packages/activities.rb b/spec/support/components/work_packages/activities.rb
index 462496f1494..926ee0a82fe 100644
--- a/spec/support/components/work_packages/activities.rb
+++ b/spec/support/components/work_packages/activities.rb
@@ -155,6 +155,14 @@ module Components
end
end
+ def expect_activity_anchor_link(text:)
+ expect(page).to have_test_selector("activity-anchor-link", text:)
+ end
+
+ def expect_no_activity_anchor_link
+ expect(page).not_to have_test_selector("activity-anchor-link")
+ end
+
def add_comment(text: nil, save: true)
if page.find_test_selector("op-open-work-package-journal-form-trigger")
open_new_comment_editor