ApplETS / Notre-Dame

The 4th generation of ÉTSMobile, the main gateway between the École de technologie supérieure and its students on mobile devices
Apache License 2.0
36 stars 12 forks source link

Check for empty sessions list when getting course activities #978

Closed DylanApardian closed 3 weeks ago

DylanApardian commented 2 months ago

⁉️ Related Issue

957

📖 Description

The courseRepository.getCourseActivities() method has if(_sessions == null){ await getSessions(); }. Except it never enters this if statement because _sessions is not null, but has 0 elements when the sessions aren't cached. This results in looping through 0 elements (sessions) so obviously there won't be a schedule.

The following methods end up calling courseRepository.getSessions() one way or another:

Because of the asynchronous operations, _sessions actually gets populated with the correct values right after getCourseActivities() loops through an empty _sessions array.

I decided to change the condition to also check if the array is empty. It's not my favourite implementation but I noticed that we're already doing a similar thing in futureToRunGrades().

if (_sessions == null || _sessions!.isEmpty) {
  await getSessions();
}

🧪 How Has This Been Tested?

I tested manually by reinstall the application/clearing the cache.

☑️ Checklist before requesting a review

🖼️ Screenshots (if useful):

image

github-actions[bot] commented 3 weeks ago

Coverage after merging 957-fixed-schedule-widget-not-loading-on-first-install into master will be

73.64%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
lib
   locator.dart3.85%100%100%3.85%30, 32–44, 47–53, 56–59
lib/core/constants
   preferences_flags.dart0%100%100%0%61, 66, 68, 70–72, 75, 77–80, 82, 84
   widget_helper.dart100%100%100%100%
   quick_links.dart100%100%100%100%
   emergency_procedures.dart100%100%100%100%
   markers.dart100%100%100%100%
   report_news.dart0%100%100%0%11, 13–15, 17–18, 20, 22–24, 6–9
lib/core/extensions
   webview_controller_extension.dart88.89%100%100%88.89%21
lib/core/managers
   author_repository.dart0%100%100%0%17, 19
   cache_manager.dart0%100%100%0%30–31, 34–37, 40, 44, 46–50, 56, 58–61, 66, 68–71
   course_repository.dart84.68%100%100%84.68%193, 198, 204, 206, 210, 212–213, 216–222, 227, 229, 232, 234–236, 239–244, 248, 252–254, 256, 260, 330, 338, 340, 525–526, 76
   news_repository.dart0%100%100%0%20, 25
   quick_link_repository.dart85.71%100%100%85.71%39–40
   settings_manager.dart89.15%100%100%89.15%221, 227, 230, 234, 236, 256, 258–259, 272, 274–276, 39, 88
   user_repository.dart93.52%100%100%93.52%131–132, 182, 304, 306, 94–95
lib/core/models
   quick_link.dart100%100%100%100%
   quick_link_data.dart100%100%100%100%
   widget_models.dart100%100%100%100%
   feedback_issue.dart100%100%100%100%
   discovery.dart100%100%100%100%
   group_discovery.dart100%100%100%100%
   emergency_procedure.dart100%100%100%100%
   report_news.dart100%100%100%100%
   social_link.dart100%100%100%100%
   faq_actions.dart100%100%100%100%
   faq_questions.dart100%100%100%100%
lib/core/services
   preferences_service.dart69.09%100%100%69.09%119–120, 122, 36, 38, 40, 43–45, 69–70, 80–82, 85, 87–88
   analytics_service.dart0%100%100%0%13–14, 17, 20–22, 25, 30, 32–34, 38, 40–41, 43
   app_widget_service.dart77.42%100%100%77.42%71, 73–78
   github_api.dart0%100%100%0%100–101, 104, 106, 110, 112–116, 118–119, 122, 124, 131–134, 138–139, 141, 39, 42–43, 47, 51–55, 57–58, 60, 62, 64–65, 68, 70, 77, 82–88, 92, 94, 96–98
   in_app_review_service.dart0%100%100%0%16, 20, 23, 27
   internal_info_service.dart0%100%100%0%18–21, 24–29, 32, 34–38, 42–43
   launch_url_service.dart0%100%100%0%16–18, 21–23, 26–31, 37, 55–56, 59
   navigation_service.dart0%100%100%0%27, 30–31, 33–34, 41–42, 45–46, 49–51, 53, 58, 61, 63–64, 67–69, 71–72
   networking_service.dart0%100%100%0%10–11, 13–15, 18–20
   remote_config_service.dart0%100%100%0%100, 103–105, 108–110, 113–115, 118–120, 123–125, 128–130, 133–135, 138–140, 143–144, 146–150, 154–156, 58–60, 63–65, 68–70, 73–75, 78–80, 83–85, 88–90, 93–95, 98–99
   rive_animation_service.dart0%100%100%0%12–13, 16, 19–20, 28, 32–33, 35
   siren_flutter_service.dart0%100%100%0%13–14, 18–19, 23–25, 29–31, 35, 41
lib/core/utils
   cache_exception.dart100%100%100%100%
   animation_exception.dart20%100%100%20%15, 17–19
   utils.dart63.33%100%100%63.33%12–15, 17–18, 44–45, 48–49, 64
   login_mask.dart5%100%100%5%12, 15–16, 18–20, 23–30, 33–34, 37–39
   calendar_utils.dart0%100%100%0%100, 104, 106–109, 11, 110, 112–113, 115, 118–121, 127–128, 13, 131, 134, 138, 14, 145, 150, 153, 155, 160, 164–165, 169, 17, 170–171, 173–175, 179, 183, 19, 21, 35–36, 38, 40–41, 45–48, 56, 59–60, 63, 68, 7, 71, 77, 79–80, 83, 87–88, 9, 92–94
lib/core/viewmodels
   news_viewmodel.dart71.43%100%100%71.43%42, 46–48
   quick_links_viewmodel.dart100%100%100%100%
   web_link_card_viewmodel.dart62.50%100%100%62.50%35, 40–41
   login_viewmodel.dart100%100%100%100%
   security_viewmodel.dart50%100%100%50%37–38, 42–44, 46, 51–52
   grades_details_viewmodel.dart96.67%100%100%96.67%53
   schedule_settings_viewmodel.dart77.38%100%100%77.38%118–122, 138, 140, 142, 145, 148–149, 151, 65, 67–72
   schedule_viewmodel.dart79.47%100%100%79.47%100, 102–106, 108, 123, 147, 164, 166–167, 169, 171–176, 215, 227, 283–284, 320, 370–374, 382–383, 406–409, 412–413, 446–447
   choose_language_viewmodel.dart100%100%100%100%
   grades_viewmodel.dart100%100%100%100%
   profile_viewmodel.dart96%100%100%96%126–127
   feedback_viewmodel.dart97.14%100%100%97.14%63
   not_found_viewmodel.dart100%100%100%100%
   schedule_default_viewmodel.dart92.50%100%100%92.50%59, 98–99
   settings_viewmodel.dart100%100%100%100%
   calendar_selection_viewmodel.dart0%100%100%0%20, 25–26, 29–35, 38, 41–43, 46, 48–49, 51, 55–56, 58, 60, 65–68, 70, 72, 77–78
   news_details_viewmodel.dart100%100%100%100%
   report_news_viewmodel.dart0%100%100%0%10–12
   author_viewmodel.dart68%100%100%68%56, 60, 62–65, 68–69
   more_viewmodel.dart64.71%100%100%64.71%110, 112–114, 116–117, 119, 124–125, 144–145, 147–148, 150–151, 154–155, 64
   faq_viewmodel.dart41.67%100%100%41.67%30, 32–33, 35, 38, 41,