Merge pull request #3764 from NoelDeMartin/MOBILE-4362

MOBILE-4362 timeline: Fix empty searches
main
Dani Palou 2023-08-01 10:46:48 +02:00 committed by GitHub
commit ad3245136e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 21 deletions

View File

@ -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 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));
});
return section.data$.pipe(map(({ events }) => events.length > 0 ? section : null));
}),
).pipe(
if (sectionObservables.length === 0) {
return of([]);
}
return combineLatest(sectionObservables).pipe(
map(sections => sections.filter(
(section: AddonBlockTimelineSection | null): section is AddonBlockTimelineSection => !!section,
)),

View File

@ -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