diff --git a/src/addons/block/timeline/components/timeline/timeline.ts b/src/addons/block/timeline/components/timeline/timeline.ts index 85e071d7ae7..b9ee654cc99 100644 --- a/src/addons/block/timeline/components/timeline/timeline.ts +++ b/src/addons/block/timeline/components/timeline/timeline.ts @@ -252,29 +252,32 @@ export class AddonBlockTimelineComponent implements OnInit, ICoreBlockComponent const courseIds = courses.map(course => course.id); const gracePeriod = await this.getCoursesGracePeriod(); const courseEvents = await AddonBlockTimeline.getActionEventsByCourses(courseIds, search ?? ''); + const sectionObservables = courses + .filter( + course => + !course.hidden && + !CoreCoursesHelper.isPastCourse(course, gracePeriod.after) && + !CoreCoursesHelper.isFutureCourse(course, gracePeriod.after, gracePeriod.before) && + courseEvents[course.id].events.length > 0, + ) + .map(course => { + const section = new AddonBlockTimelineSection( + search, + overdue, + dateRange, + course, + courseEvents[course.id].events, + courseEvents[course.id].canLoadMore, + ); + + return section.data$.pipe(map(({ events }) => events.length > 0 ? section : null)); + }); + + if (sectionObservables.length === 0) { + return of([]); + } - return combineLatest( - courses - .filter( - course => - !course.hidden && - !CoreCoursesHelper.isPastCourse(course, gracePeriod.after) && - !CoreCoursesHelper.isFutureCourse(course, gracePeriod.after, gracePeriod.before) && - courseEvents[course.id].events.length > 0, - ) - .map(course => { - const section = new AddonBlockTimelineSection( - search, - overdue, - dateRange, - course, - courseEvents[course.id].events, - courseEvents[course.id].canLoadMore, - ); - - return section.data$.pipe(map(({ events }) => events.length > 0 ? section : null)); - }), - ).pipe( + return combineLatest(sectionObservables).pipe( map(sections => sections.filter( (section: AddonBlockTimelineSection | null): section is AddonBlockTimelineSection => !!section, )), diff --git a/src/addons/block/timeline/tests/behat/basic_usage.feature b/src/addons/block/timeline/tests/behat/basic_usage.feature index 9042ad3078f..37ab2f6a733 100644 --- a/src/addons/block/timeline/tests/behat/basic_usage.feature +++ b/src/addons/block/timeline/tests/behat/basic_usage.feature @@ -91,3 +91,27 @@ Feature: Timeline block. | assign | C1 | newassign | New Assignment | ##tomorrow## | And I pull to refresh in the app Then I should find "New Assignment" in the app + + @lms_from4.0 + Scenario: Search + Given I entered the app as "student1" + Then I should find "Assignment 00" within "Timeline" "ion-card" in the app + + When I set the field "Search by activity type or name" to "thisdoesntexist" in the app + And I press "Search" in the app + Then I should find "No activities require action" in the app + But I should not find "Assignment 00" within "Timeline" "ion-card" in the app + + When I press "Clear search" in the app + Then I should find "Assignment 00" within "Timeline" "ion-card" in the app + + When I press "Sort by" in the app + And I press "Sort by courses" in the app + Then I should find "Course 1" in the app + And I should find "Assignment 02" within "Timeline" "ion-card" in the app + + When I set the field "Search by activity type or name" to "thisdoesntexist" in the app + And I press "Search" in the app + Then I should find "No activities require action" in the app + But I should not find "Course 1" in the app + And I should not find "Assignment 02" within "Timeline" "ion-card" in the app