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

Add navigation test for notification center

Henriette Darge14145be4c98d
diff --git a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center-page.component.ts b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center-page.component.ts
index 0b2c194e990..ed5ab42f2bc 100644
--- a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center-page.component.ts
+++ b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center-page.component.ts
@@ -111,10 +111,12 @@ export class InAppNotificationCenterPageComponent extends UntilDestroyedMixin im
}
// For shared template compliance
- updateTitleName(val:string):void {} // eslint-disable-line class-methods-use-this, no-unused-vars
+ // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
+ updateTitleName(val:string):void {}
// For shared template compliance
- changeChangesFromTitle(val:string):void {} // eslint-disable-line class-methods-use-this, no-unused-vars
+ // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
+ changeChangesFromTitle(val:string):void {}
private backButtonFn():void {
if (this.backRoute) {
diff --git a/spec/features/notifications/navigation_spec.rb b/spec/features/notifications/navigation_spec.rb
new file mode 100644
index 00000000000..08bc5616e89
--- /dev/null
+++ b/spec/features/notifications/navigation_spec.rb
@@ -0,0 +1,96 @@
+require 'spec_helper'
+require 'support/components/notifications/center'
+
+describe "Notification center navigation", type: :feature, js: true do
+ shared_let(:project) { FactoryBot.create :project }
+ shared_let(:work_package) { FactoryBot.create :work_package, project: project }
+ shared_let(:second_work_package) { FactoryBot.create :work_package, project: project }
+ shared_let(:recipient) do
+ FactoryBot.create :user,
+ member_in_project: project,
+ member_with_permissions: %i[view_work_packages]
+ end
+ shared_let(:notification) do
+ FactoryBot.create :notification,
+ recipient: recipient,
+ project: project,
+ resource: work_package,
+ journal: work_package.journals.last
+ end
+
+ shared_let(:second_notification) do
+ FactoryBot.create :notification,
+ recipient: recipient,
+ project: project,
+ resource: second_work_package,
+ journal: work_package.journals.last
+ end
+
+ let(:center) { ::Components::Notifications::Center.new }
+ let(:activity_tab) { ::Components::WorkPackages::Activities.new(work_package) }
+ let(:split_screen) { ::Pages::SplitWorkPackage.new work_package }
+
+ describe 'the back button brings me back to where I came from' do
+ current_user { recipient }
+ let(:navigation_helper) { ::Notifications::NavigationHelper.new(center, notification, work_package) }
+
+ it 'when coming from a rails based page' do
+ visit home_path
+
+ navigation_helper.open_and_close_the_center
+ expect(page).to have_current_path home_path
+
+ navigation_helper.open_center_and_navigate_within
+ expect(page).to have_current_path home_path
+
+ # Todo Implement (#38564)
+ # navigation_helper.open_center_and_navigate_out
+ # expect(current_path).to eq home_path
+ end
+
+ it 'when coming from an angular page' do
+ visit project_work_package_path(project, work_package, state: 'activity')
+
+ navigation_helper.open_and_close_the_center
+ expect(page).to have_current_path project_work_package_path(project, work_package, state: 'activity')
+
+ navigation_helper.open_center_and_navigate_within
+ expect(page).to have_current_path project_work_package_path(project, work_package, state: 'activity')
+
+ # Todo: Implement (#38564)
+ # navigation_helper.open_center_and_navigate_out
+ # visit project_work_package_path(project, work_package, state: 'activity')
+ end
+ end
+
+ describe 'the path updates accordingly' do
+ current_user { recipient }
+
+ it 'when navigating between the tabs' do
+ visit home_path
+ center.open
+ center.expect_bell_count 2
+ expect(page).to have_current_path "/notifications"
+
+ # Details view of WP opens with activity tab
+ center.click_item notification
+ split_screen.expect_open
+ expect(page).to have_current_path "/notifications/details/#{work_package.id}/activity"
+
+ # Switch to the relations tab
+ split_screen.switch_to_tab tab: 'relations'
+ expect(page).to have_current_path "/notifications/details/#{work_package.id}/relations"
+
+ # Navigate to full view and back
+ wp_full = split_screen.switch_to_fullscreen
+ expect(page).to have_current_path "/work_packages/#{work_package.id}/relations"
+
+ wp_full.go_back
+ expect(page).to have_current_path "/notifications/details/#{work_package.id}/relations"
+
+ # Close the split screen
+ split_screen.close
+ expect(page).to have_current_path "/notifications"
+ end
+ end
+end
diff --git a/spec/features/notifications/notification_center/notification_center_spec.rb b/spec/features/notifications/notification_center/notification_center_spec.rb
index c62df9a3cef..e7683bd4adc 100644
--- a/spec/features/notifications/notification_center/notification_center_spec.rb
+++ b/spec/features/notifications/notification_center/notification_center_spec.rb
@@ -19,12 +19,12 @@ describe "Notification center", type: :feature, js: true do
end
shared_let(:second_notification) do
- FactoryBot.create :notification,
- recipient: recipient,
- project: project,
- resource: second_work_package,
- journal: work_package.journals.last
- end
+ FactoryBot.create :notification,
+ recipient: recipient,
+ project: project,
+ resource: second_work_package,
+ journal: work_package.journals.last
+ end
let(:center) { ::Components::Notifications::Center.new }
let(:activity_tab) { ::Components::WorkPackages::Activities.new(work_package) }
diff --git a/spec/support/components/notifications/center.rb b/spec/support/components/notifications/center.rb
index 1969aadd892..e9665554867 100644
--- a/spec/support/components/notifications/center.rb
+++ b/spec/support/components/notifications/center.rb
@@ -48,6 +48,10 @@ module Components
click_button 'Mark all as read'
end
+ def show_all
+ click_button 'All'
+ end
+
def click_item(notification)
text = notification.resource.is_a?(WorkPackage) ? notification.resource.subject : notification.subject
within_item(notification) do
diff --git a/spec/support/notifications/navigation_helper.rb b/spec/support/notifications/navigation_helper.rb
new file mode 100644
index 00000000000..e83f1158e76
--- /dev/null
+++ b/spec/support/notifications/navigation_helper.rb
@@ -0,0 +1,55 @@
+class Notifications::NavigationHelper
+ attr_reader :center,
+ :notification,
+ :work_package
+
+ def initialize(center, notification, work_package)
+ @center = center
+ @notification = notification
+ @work_package = work_package
+ end
+
+ def open_and_close_the_center
+ # Open the notification center and close it directly
+ center.open
+ center.expect_work_package_item notification
+
+ center.close
+ end
+
+ def open_center_and_navigate_within
+ # Open the notification center and close it directly
+ center.open
+ center.show_all
+ center.expect_work_package_item notification
+
+ # Open a notification
+ center.click_item notification
+ split_screen = ::Pages::SplitWorkPackage.new work_package
+ split_screen.expect_tab :activity
+ split_screen.switch_to_tab tab: 'relations'
+
+ center.close
+ end
+
+ def open_center_and_navigate_out
+ # Open the notification center and close it directly
+ center.open
+ center.show_all
+ center.expect_work_package_item notification
+
+ # Open a notification
+ center.click_item notification
+ split_screen = ::Pages::SplitWorkPackage.new work_package
+ split_screen.expect_tab :activity
+
+ # Switch to WP full view and back
+ wp_full = split_screen.switch_to_fullscreen
+ wp_full.expect_tab :activity
+
+ wp_full.go_back
+ split_screen.expect_open
+
+ center.close
+ end
+end