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

Fix read status and add spec (#9410)

Oliver Günther15b0dc06a895
diff --git a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.html b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.html
index bb9e8efd65c..071f6f4f7ac 100644
--- a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.html
+++ b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.html
@@ -2,6 +2,7 @@
class="op-ian-item"
[class.op-ian-item_expanded]="notification.expanded"
attr.data-qa-selector="op-ian-notification-item-{{notification.id}}"
+ [attr.data-qa-ian-read]="notification.readIAN === true || undefined"
>
<button
type="button"
@@ -35,7 +36,7 @@
<span
[textContent]="workPackage.subject"
class="op-ian-item--work-package-subject"
- [class.-read]="notification.read"
+ [class.-read]="notification.readIAN"
>
</span>
</span>
@@ -76,6 +77,7 @@
<div
*ngIf="notification.expanded"
class="op-ian-item--details"
+ data-qa-selector="op-ian-details"
>
<ng-container *ngIf="body.length > 0">
<div class="op-ian-item--body">
diff --git a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts
index fc5671725c5..47813566a4f 100644
--- a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts
+++ b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts
@@ -97,7 +97,7 @@ export class InAppNotificationEntryComponent implements OnInit {
}
toggleDetails():void {
- if (!this.notification.read) {
+ if (!this.notification.readIAN) {
this.inAppNotificationsService.markReadKeepAndExpanded(this.notification);
}
if (this.notification.expanded) {
diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notification.model.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notification.model.ts
index e3cdacd49f2..e570c862b13 100644
--- a/frontend/src/app/features/in-app-notifications/store/in-app-notification.model.ts
+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notification.model.ts
@@ -20,7 +20,8 @@ export interface InAppNotification {
createdAt:string;
updatedAt:string;
reason:string;
- read?:boolean;
+ readIAN:boolean|null;
+ readEmail:boolean|null;
details?:InAppNotificationDetail[];
// Mark a notification to be kept in the center even though it was saved as "read".
diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts
index 639e283a16c..44b0cabe150 100644
--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts
+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts
@@ -14,7 +14,7 @@ export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState
/** Get the unread items */
unread$ = this.selectAll({
- filterBy: ({ read }) => !read
+ filterBy: ({ readIAN }) => !readIAN
});
/** Get all items that shall be kept in the notification center */
diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts
index a0d64571c40..742244fb3e0 100644
--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts
+++ b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts
@@ -63,7 +63,7 @@ export class InAppNotificationsService {
@transaction()
add(inAppNotification:InAppNotification):void {
this.store.add(inAppNotification);
- this.store.update(state => ({ ...state, count: state.count + 1}));
+ this.store.update(state => ({ ...state, count: state.count + 1 }));
}
update(id:ID, inAppNotification:Partial<InAppNotification>):void {
@@ -73,11 +73,11 @@ export class InAppNotificationsService {
@transaction()
remove(id:ID):void {
this.store.remove(id);
- this.store.update(state => ({ ...state, count: state.count + 1}));
+ this.store.update(state => ({ ...state, count: state.count + 1 }));
}
setActiveFacet(facet:string) {
- this.store.update( state => ({ ...state, activeFacet: facet}));
+ this.store.update(state => ({ ...state, activeFacet: facet }));
}
markAllRead():void {
@@ -91,7 +91,7 @@ export class InAppNotificationsService {
)
.subscribe(() => {
applyTransaction(() => {
- this.store.update(null, { read: true });
+ this.store.update(null, { readIAN: true });
this.store.update({ count: 0 });
});
});
@@ -115,7 +115,7 @@ export class InAppNotificationsService {
{
expanded: false
}
- )
+ );
}
expand(notification:InAppNotification):void {
@@ -124,20 +124,21 @@ export class InAppNotificationsService {
{
expanded: true
}
- )
+ );
}
markReadKeepAndExpanded(notification:InAppNotification):void {
-
- this.apiV3Service.notifications.id(notification.id)
- .markRead()
-
+ this
+ .apiV3Service
+ .notifications
+ .id(notification.id)
+ .markRead()
.subscribe(() => {
applyTransaction(() => {
this.store.update(
notification.id,
{
- read: true,
+ readIAN: true,
keep: true
}
);
diff --git a/frontend/src/app/shared/components/modal/modal-header.component.html b/frontend/src/app/shared/components/modal/modal-header.component.html
index 532cd3e938f..c74d7c9d410 100644
--- a/frontend/src/app/shared/components/modal/modal-header.component.html
+++ b/frontend/src/app/shared/components/modal/modal-header.component.html
@@ -8,6 +8,7 @@
<button
class="op-modal--close-button"
type="button"
+ data-qa-selector="op-modal-close"
(click)="close.emit()"
[attr.aria-label]="text.closePopup"
>
diff --git a/spec/features/notifications/notification_bell_spec.rb b/spec/features/notifications/notification_center_spec.rb
similarity index 66%
rename from spec/features/notifications/notification_bell_spec.rb
rename to spec/features/notifications/notification_center_spec.rb
index 25ad3fac8be..0c467d0c4d8 100644
--- a/spec/features/notifications/notification_bell_spec.rb
+++ b/spec/features/notifications/notification_center_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'support/components/notifications/center'
-describe "Notification bell", type: :feature, js: true do
+describe "Notification center", type: :feature, js: true do
shared_let(:project) { FactoryBot.create :project }
shared_let(:work_package) { FactoryBot.create :work_package, project: project }
shared_let(:recipient) do
@@ -35,5 +35,26 @@ describe "Notification bell", type: :feature, js: true do
notification.reload
expect(notification.read_ian).to be_truthy
end
+
+ it 'can expand the notification to mark it as read' do
+ visit home_path
+ center.expect_bell_count 1
+ center.open
+
+ center.click_item notification
+ center.expect_expanded notification
+ center.expect_read_item notification
+
+ retry_block do
+ notification.reload
+ raise "Expected notification to be marked read" unless notification.read_ian
+ end
+
+ center.close
+ center.expect_bell_count 0
+
+ center.open
+ center.expect_empty
+ end
end
end
diff --git a/spec/support/components/notifications/center.rb b/spec/support/components/notifications/center.rb
index 81ed920f6e5..8b3713d3e18 100644
--- a/spec/support/components/notifications/center.rb
+++ b/spec/support/components/notifications/center.rb
@@ -39,16 +39,43 @@ module Components
expect_open
end
+ def close
+ page.find('button[data-qa-selector="op-modal-close"]').click
+ expect_closed
+ end
+
def mark_all_read
click_button 'Mark all as read'
end
+ def click_item(notification)
+ text = notification.resource.is_a?(WorkPackage) ? notification.resource.subject : notification.subject
+ within_item(notification) do
+ page.find('span', text: text, exact_text: true).click
+ end
+ end
+
+ def within_item(notification, &block)
+ page.within("[data-qa-selector='op-ian-notification-item-#{notification.id}']", &block)
+ end
+
def expect_item(notification, subject: notification.subject)
- page.within("[data-qa-selector='op-ian-notification-item-#{notification.id}']") do
+ within_item(notification) do
expect(page).to have_text subject
end
end
+ def expect_read_item(notification)
+ expect(page)
+ .to have_selector("[data-qa-selector='op-ian-notification-item-#{notification.id}'][data-qa-ian-read]")
+ end
+
+ def expect_expanded(notification)
+ within_item(notification) do
+ expect(page).to have_selector('[data-qa-selector="op-ian-details"]')
+ end
+ end
+
def expect_work_package_item(notification)
work_package = notification.resource
raise(ArgumentError, "Expected work package") unless work_package.is_a?(WorkPackage)
@@ -65,6 +92,10 @@ module Components
expect(page).to have_selector('op-in-app-notification-center')
end
+ def expect_empty
+ expect(page).to have_text I18n.t('js.notice_no_results_to_display')
+ end
+
def expect_bell_count(count)
if count == 0
expect(page).to have_no_selector('[data-qa-selector="op-ian-notifications-count"]')