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
Add spec for notifications side menu and fix some linting issues
Henriette Darge3b263f4b414c
diff --git a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.tsindex 8942684cd7f..5b7a6b5698a 100644--- a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts@@ -100,8 +100,8 @@ export class InAppNotificationCenterComponent extends UntilDestroyedMixin implemngOnInit():void {this.storeService.setFacet('unread');this.storeService.setFilters({- filter: this.uiRouterGlobals.params.filter,- name: this.uiRouterGlobals.params.name,+ filter: this.uiRouterGlobals.params.filter, // eslint-disable-line @typescript-eslint/no-unsafe-assignment+ name: this.uiRouterGlobals.params.name, // eslint-disable-line @typescript-eslint/no-unsafe-assignment});}}diff --git a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.html b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.htmlindex d3903b96aa8..4a22adc23e4 100644--- a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.html+++ b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.html@@ -1 +1,4 @@-<op-sidemenu [items]="menuItems$ | async"></op-sidemenu>+<op-sidemenu+ [items]="menuItems$ | async"+ data-qa-selector="op-sidemenu"+></op-sidemenu>diff --git a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.tsindex 220104fc7d3..cf7d22db5b3 100644--- a/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/menu/menu.component.ts@@ -61,7 +61,7 @@ export class IanMenuComponent implements OnInit {map((items) => items.map((item) => ({...item,- title: (item.projectHasParent ? '...' : '') + item.value,+ title: (item.projectHasParent ? '... ' : '') + item.value,href: this.getHrefForFilters({ filter: 'project', name: idFromLink(item._links.valueLink[0].href) }),})).sort((a, b) => {diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.tsindex 81c474f4d0d..c32f60f1f88 100644--- a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.query.ts@@ -33,11 +33,11 @@ export class IanMenuQuery extends Query<IanMenuState> {this.select('notificationsByProject'),this.projectsForNotifications$,]).pipe(- map(([notifications, projects]) => notifications.map(notification => {- const project = projects.find(project => project.id === idFromLink(notification._links.valueLink[0].href));+ map(([notifications, projects]) => notifications.map((notification) => {+ const project = projects.find((p) => p.id.toString() === idFromLink(notification._links.valueLink[0].href));return {...notification,- projectHasParent: project?._links.parent.href ? true : false,+ projectHasParent: !!project?._links.parent.href,};})),);diff --git a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.tsindex 1e5833685e2..c1bcfac1798 100644--- a/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts+++ b/frontend/src/app/features/in-app-notifications/center/menu/state/ian-menu.store.ts@@ -1,7 +1,5 @@import { Store, StoreConfig } from '@datorama/akita';import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import { NOTIFICATIONS_MAX_SIZE } from 'core-app/core/state/in-app-notifications/in-app-notification.model';-import { Project } from 'core-app/core/state/projects/project.model';export interface IanMenuGroupingData {value:string;diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.tsindex c242ccb1410..ea6bdb609bd 100644--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.ts+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.ts@@ -8,11 +8,12 @@ import {IanCenterState,IanCenterStore,} from 'core-app/features/in-app-notifications/center/state/ian-center.store';-import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import {+ ApiV3ListFilter,+ Apiv3ListParameters,+} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';-import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';-import { INotificationPageQueryParameters } from 'core-app/features/in-app-notifications/in-app-notifications.routes';import { selectCollectionAsEntities$ } from 'core-app/core/state/collection-store';export class IanCenterQuery extends Query<IanCenterState> {diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.tsindex ab573699be6..aec31b913c6 100644--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts@@ -50,7 +50,7 @@ export class IanCenterService {) {}- setFilters(filters:INotificationPageQueryParameters) {+ setFilters(filters:INotificationPageQueryParameters):void {this.store.update({ filters });this.debouncedReload();}@@ -90,7 +90,7 @@ export class IanCenterService {}}- private debouncedReload = _.debounce(this.reload.bind(this));+ private debouncedReload = _.debounce(() => { this.reload(); });private reload() {this.resourceService@@ -100,7 +100,7 @@ export class IanCenterService {switchMap((results) => from(this.sideLoadInvolvedWorkPackages(results._embedded.elements))),).subscribe();- };+ }private sideLoadInvolvedWorkPackages(elements:InAppNotification[]):Promise<unknown> {const { cache } = this.apiV3Service.work_packages;diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.tsindex 00d6b7d8d2f..8644fd55457 100644--- a/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.ts+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.ts@@ -9,7 +9,7 @@ export interface IanCenterState {pageSize:number;};activeFacet:InAppNotificationFacet;- filters: INotificationPageQueryParameters;+ filters:INotificationPageQueryParameters;/** Number of elements not showing after max values loaded */notLoaded:number;diff --git a/frontend/src/app/features/in-app-notifications/in-app-notifications.routes.ts b/frontend/src/app/features/in-app-notifications/in-app-notifications.routes.tsindex 9af9562e12c..dde72356faa 100644--- a/frontend/src/app/features/in-app-notifications/in-app-notifications.routes.ts+++ b/frontend/src/app/features/in-app-notifications/in-app-notifications.routes.ts@@ -36,7 +36,7 @@ import { WorkPackagesBaseComponent } from 'core-app/features/work-packages/routiexport interface INotificationPageQueryParameters {filter?:string;name?:string;-};+}export const IAN_ROUTES:Ng2StateDeclaration[] = [{diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-allowed.validator.ts b/frontend/src/app/features/invite-user-modal/project-selection/project-allowed.validator.tsindex 18656220324..0084138fe77 100644--- a/frontend/src/app/features/invite-user-modal/project-selection/project-allowed.validator.ts+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-allowed.validator.ts@@ -8,7 +8,7 @@ export const ProjectAllowedValidator = (currentUserService:CurrentUserService) =(control:AbstractControl) =>currentUserService.hasCapabilities$('memberships/create',- idFromLink(control.value.href),+ idFromLink(control.value.href)).pipe(take(1),map((isAllowed) => (isAllowed ? null : { lackingPermission: true })),diff --git a/frontend/src/app/shared/components/sidemenu/sidemenu.component.html b/frontend/src/app/shared/components/sidemenu/sidemenu.component.htmlindex f30aef39d59..da1e6409161 100644--- a/frontend/src/app/shared/components/sidemenu/sidemenu.component.html+++ b/frontend/src/app/shared/components/sidemenu/sidemenu.component.html@@ -24,10 +24,12 @@><liclass="op-sidemenu--item"+ data-qa-selector="op-sidemenu--item"*ngFor="let item of items"><aclass="op-sidemenu--item-action"+ [attr.data-qa-selector]="'op-sidemenu--item-action--' + item.title.split(' ').join('')"[href]="item.href"*ngIf="!item.children">diff --git a/spec/features/notifications/notification_center/notification_center_sidemenu_spec.rb b/spec/features/notifications/notification_center/notification_center_sidemenu_spec.rbnew file mode 100644index 00000000000..72b573fc08b--- /dev/null+++ b/spec/features/notifications/notification_center/notification_center_sidemenu_spec.rb@@ -0,0 +1,144 @@+require 'spec_helper'+require 'support/components/notifications/center'++describe "Notification center sidemenu", type: :feature, js: true, with_settings: { journal_aggregation_time_minutes: 0 } do+ shared_let(:project) { FactoryBot.create :project }+ shared_let(:project2) { FactoryBot.create :project }+ shared_let(:project3) { FactoryBot.create :project, parent: project2 }++ shared_let(:recipient) do+ FactoryBot.create :user,+ member_in_projects: [project, project2, project3],+ member_with_permissions: %i[view_work_packages]+ end+ shared_let(:other_user) { FactoryBot.create(:user) }++ shared_let(:work_package) { FactoryBot.create :work_package, project: project, author: other_user }+ shared_let(:work_package2) { FactoryBot.create :work_package, project: project2, author: other_user }+ shared_let(:work_package3) { FactoryBot.create :work_package, project: project3, author: other_user }+ shared_let(:work_package4) { FactoryBot.create :work_package, project: project3, author: other_user }++ shared_let(:notification) do+ FactoryBot.create :notification,+ recipient: recipient,+ project: project,+ resource: work_package,+ reason_ian: :watched+ end++ shared_let(:notification2) do+ FactoryBot.create :notification,+ recipient: recipient,+ project: project2,+ resource: work_package2,+ reason_ian: :assigned+ end++ shared_let(:notification3) do+ FactoryBot.create :notification,+ recipient: recipient,+ project: project3,+ resource: work_package3,+ reason_ian: :responsible+ end++ shared_let(:notification4) do+ FactoryBot.create :notification,+ recipient: recipient,+ project: project3,+ resource: work_package4,+ reason_ian: :mentioned+ end++ let(:center) { ::Components::Notifications::Center.new }+ let(:side_menu) { ::Components::Notifications::Sidemenu.new }++ describe 'showing the correct data:' do+ before do+ login_as recipient+ visit notifications_center_path+ end++ it 'updates the numbers when a notification is read' do+ side_menu.expect_open++ # Expect standard filters+ side_menu.expect_item_with_count 'Inbox', 4+ side_menu.expect_item_with_count 'Assigned', 1+ side_menu.expect_item_with_count '@mentioned', 1+ side_menu.expect_item_with_count 'Accountable', 1+ side_menu.expect_item_with_count 'Watching', 1++ # Expect project filters+ side_menu.expect_item_with_count project.name, 1+ side_menu.expect_item_with_count project2.name, 1+ side_menu.expect_item_with_count "... #{project3.name}", 2++ # Reading a notification...+ center.mark_notification_as_read notification++ # ... will change the filter counts+ side_menu.expect_item_with_count 'Inbox', 3+ side_menu.expect_item_with_count 'Assigned', 1+ side_menu.expect_item_with_count '@mentioned', 1+ side_menu.expect_item_with_count 'Accountable', 1+ side_menu.expect_item_with_no_count 'Watching'++ # ... and show only those projects with a notification+ side_menu.expect_item_not_visible project.name+ side_menu.expect_item_with_count project2.name, 1+ side_menu.expect_item_with_count project3.name, 2++ # Marking all as read+ center.mark_all_read+ side_menu.expect_item_with_no_count 'Inbox'+ side_menu.expect_item_with_no_count 'Assigned'+ side_menu.expect_item_with_no_count '@mentioned'+ side_menu.expect_item_with_no_count 'Accountable'+ side_menu.expect_item_with_no_count 'Watching'++ side_menu.expect_item_not_visible project.name+ side_menu.expect_item_not_visible project2.name+ side_menu.expect_item_not_visible project3.name+ end++ it 'updates the content when a filter is clicked' do+ # All notifications are shown+ center.expect_work_package_item notification, notification2, notification3, notification4++ # Filter for "Watching"+ side_menu.click_item 'Watching'+ center.expect_work_package_item notification+ center.expect_no_item notification2, notification3, notification4++ # Filter for "Assignee"+ side_menu.click_item 'Assignee'+ center.expect_work_package_item notification2+ center.expect_no_item notification, notification3, notification4++ # Filter for "Responsible"+ side_menu.click_item 'Responsible'+ center.expect_work_package_item notification3+ center.expect_no_item notification, notification2, notification4++ # Filter for "@mentioned"+ side_menu.click_item '@mentioned'+ center.expect_work_package_item notification4+ center.expect_no_item notification, notification2, notification3++ # Filter for project1+ side_menu.click_item project.name+ center.expect_work_package_item notification+ center.expect_no_item notification2, notification3, notification4++ # Filter for project3+ side_menu.click_item project3.name+ center.expect_work_package_item notification3, notification4+ center.expect_no_item notification, notification2++ # Reset by clicking on the Inbox+ side_menu.click_item 'Inbox'+ center.expect_work_package_item notification, notification2, notification3, notification4+ end+ end+enddiff --git a/spec/support/components/common/sidemenu.rb b/spec/support/components/common/sidemenu.rbnew file mode 100644index 00000000000..3b036e6e2ba--- /dev/null+++ b/spec/support/components/common/sidemenu.rb@@ -0,0 +1,78 @@+#-- 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 COPYRIGHT and LICENSE files for more details.+#++++module Components+ module Notifications+ class Sidemenu+ include Capybara::DSL+ include RSpec::Matchers++ def initialize; end++ def expect_open+ expect(page).to have_selector('[data-qa-selector="op-sidemenu"]')+ end++ def expect_item_not_visible(item)+ expect(page).to have_no_selector(item_selector, text: item)+ end++ def expect_item_with_count(item, count)+ within "[data-qa-selector='op-sidemenu--item-action--#{item.delete(' ')}']" do+ expect(page).to have_text item+ expect_count(count)+ end+ end++ def expect_item_with_no_count(item)+ within "[data-qa-selector='op-sidemenu--item-action--#{item.delete(' ')}']" do+ expect(page).to have_text item+ expect_no_count+ end+ end++ def click_item(item)+ page.find(item_selector, text: item).click+ end++ private++ def expect_count(count)+ expect(page).to have_selector('.op-bubble', text: count)+ end++ def expect_no_count+ expect(page).to have_no_selector('.op-bubble')+ end++ def item_selector+ '[data-qa-selector="op-sidemenu--item"]'+ end+ end+ end+enddiff --git a/spec/support/components/notifications/center.rb b/spec/support/components/notifications/center.rbindex 9fa423b589a..ac35691efcb 100644--- a/spec/support/components/notifications/center.rb+++ b/spec/support/components/notifications/center.rb@@ -75,9 +75,11 @@ module Componentsendend- def expect_no_item(notification)- expect(page)- .to have_no_selector("[data-qa-selector='op-ian-notification-item-#{notification.id}']")+ def expect_no_item(*notifications)+ notifications.each do |notification|+ expect(page)+ .to have_no_selector("[data-qa-selector='op-ian-notification-item-#{notification.id}']")+ endenddef expect_read_item(notification)@@ -90,12 +92,14 @@ module Components.not_to have_selector("[data-qa-selector='op-ian-notification-item-#{notification.id}'][data-qa-ian-read]")end- def expect_work_package_item(notification)- work_package = notification.resource- raise(ArgumentError, "Expected work package") unless work_package.is_a?(WorkPackage)+ def expect_work_package_item(*notifications)+ notifications.each do |notification|+ work_package = notification.resource+ raise(ArgumentError, "Expected work package") unless work_package.is_a?(WorkPackage)- expect_item notification,- subject: "#{work_package.type.name.upcase} #{work_package.subject}"+ expect_item notification,+ subject: "#{work_package.type.name.upcase} #{work_package.subject}"+ endenddef expect_closed