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 feature specs

Christophe Bliard091dce5cee27
diff --git a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-relations-count.function.ts b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-relations-count.function.ts
index 08735a690a8..17f1ab500ed 100644
--- a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-relations-count.function.ts
+++ b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-relations-count.function.ts
@@ -1,9 +1,10 @@
import { Injector } from '@angular/core';
-import { Observable, combineLatest, from, Subject } from 'rxjs';
-import { switchMap, startWith } from 'rxjs/operators';
+import { Observable, combineLatest, from } from 'rxjs';
+import { switchMap, startWith, filter, throttleTime, tap } from 'rxjs/operators';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { WorkPackageRelationsService } from 'core-app/features/work-packages/components/wp-relations/wp-relations.service';
+import { HalEventsService } from 'core-app/features/hal/services/hal-events.service';
export function workPackageRelationsCount(
workPackage:WorkPackageResource,
@@ -11,16 +12,34 @@ export function workPackageRelationsCount(
):Observable<number> {
const pathHelper = injector.get(PathHelperService);
const wpRelations = injector.get(WorkPackageRelationsService);
+ const halEvents = injector.get(HalEventsService);
const wpId = workPackage.id!.toString();
// It is an intermediate solution, until the API can return all relations
// in the long term, the tabs are going to be the same as in the notifications
const url = pathHelper.workPackageGetRelationsCounterPath(wpId.toString());
- const updateTrigger$ = new Subject<void>();
+
+ const relationEventUpdates$ = halEvents
+ .events$
+ .pipe(
+ filter((event) => event.resourceType === 'WorkPackage' && event.eventType === 'association' && event.id === wpId),
+ tap((event) => {
+ // eslint-disable-next-line no-console
+ console.log('Event received:', { event, wpId });
+ }),
+ );
// Listen for relation state changes
- const relationsState$ = wpRelations.state(wpId).values$().pipe(startWith(null));
+ const relationsState$ = wpRelations.state(wpId).values$();
- return combineLatest([relationsState$, updateTrigger$.pipe(startWith(null))]).pipe(
+ return combineLatest([
+ // combineLatest only emits when all observables emit at least once, so we
+ // add an initial null value to the stream to trigger it the first time.
+ relationsState$.pipe(startWith(null)),
+ relationEventUpdates$.pipe(startWith(null)),
+ ]).pipe(
+ // Fire directly, then ignore events for 500ms and fire again if an event was received during this time (leading: true)
+ // see https://stackoverflow.com/a/57097217/177665
+ throttleTime(500, undefined, { leading: true, trailing: true }),
switchMap(() =>
from(
fetch(url)
diff --git a/spec/features/work_packages/details/relations/hierarchy_spec.rb b/spec/features/work_packages/details/relations/hierarchy_spec.rb
index e329a0eb00d..023a31586f2 100644
--- a/spec/features/work_packages/details/relations/hierarchy_spec.rb
+++ b/spec/features/work_packages/details/relations/hierarchy_spec.rb
@@ -141,7 +141,7 @@ RSpec.shared_examples "work package relations tab", :js, :with_cuprite do
expect(page).to have_test_selector("op-wp-breadcrumb-parent", text: parent.subject)
# And it should count the two relations
- tabs.expect_counter(relations_tab, 2)
+ tabs.expect_counter(relations_tab, 3)
end
end
@@ -155,6 +155,7 @@ RSpec.shared_examples "work package relations tab", :js, :with_cuprite do
relations.add_parent(parent.id, parent)
wp_page.expect_and_dismiss_toaster(message: "Successful update.")
relations.expect_parent(parent)
+ tabs.expect_counter(relations_tab, 3)
##
# Add child
@@ -162,12 +163,13 @@ RSpec.shared_examples "work package relations tab", :js, :with_cuprite do
relations.expect_child(child)
# Expect counter to add up child to the existing relations
- tabs.expect_counter(relations_tab, 3)
+ tabs.expect_counter(relations_tab, 4)
# Remove parent
relations.remove_parent
wp_page.expect_and_dismiss_toaster(message: "Successful update.")
relations.expect_no_parent
+ tabs.expect_counter(relations_tab, 3)
# Remove child
relations.remove_child(child)