Skip to content

Commit

Permalink
MOBILE-4362 timeline: Fix empty searches
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Aug 1, 2023
1 parent c2650cc commit 739cc1c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/addons/block/timeline/components/timeline/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)),
Expand Down
24 changes: 24 additions & 0 deletions src/addons/block/timeline/tests/behat/basic_usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 739cc1c

Please sign in to comment.