Bug 1593879 - Select a new default calendar if the current one is removed. r+a=pmorris
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 05 Nov 2019 15:32:53 +1300
changeset 36377 2bd2944137e359094aac45f9cd3cdae34fe9e3ac
parent 36376 f28c010aac310532478294838f0c4ae9d988c9c8
child 36378 163dc9241deb5eaaf7d3295a7aa19f18bb2c45d0
push id2521
push usermozilla@jorgk.com
push dateWed, 06 Nov 2019 09:31:04 +0000
treeherdercomm-beta@308f336efa3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1593879
Bug 1593879 - Select a new default calendar if the current one is removed. r+a=pmorris
calendar/base/content/calendar-management.js
calendar/test/browser/browser_calendarList.js
--- a/calendar/base/content/calendar-management.js
+++ b/calendar/base/content/calendar-management.js
@@ -386,16 +386,19 @@ function loadCalendarManager() {
       }
       addCalendarItem(calendar);
       saveSortOrder();
     },
     onCalendarUnregistering(calendar) {
       compositeCalendar.removeCalendar(calendar);
       let item = calendarList.getElementsByAttribute("calendar-id", calendar.id)[0];
       item.remove();
+      if (compositeCalendar.defaultCalendar.id == calendar.id) {
+        compositeCalendar.defaultCalendar = compositeCalendar.getCalendars({})[0];
+      }
       saveSortOrder();
     },
     onCalendarDeleting(calendar) {},
   };
   calendarManager.addObserver(calendarList._calendarManagerObserver);
 }
 
 /**
--- a/calendar/test/browser/browser_calendarList.js
+++ b/calendar/test/browser/browser_calendarList.js
@@ -323,10 +323,12 @@ add_task(async () => {
   await withMockPromptService(0, async () => {
     EventUtils.synthesizeMouseAtCenter(calendarList.itemChildren[1], {});
     await calendarListContextMenu(calendarList.itemChildren[1], "list-calendars-context-delete");
   });
   is(manager.getCalendars({}).length, 1);
   is(calendarList.itemCount, 1);
   checkSortOrder(0);
 
+  is(composite.defaultCalendar.id, calendars[0].id);
+  is(calendarList.selectedItem, calendarList.itemChildren[0]);
   await closeCalendarTab();
 });