diff --git a/src/app/calendar-app/calendar-app.component.spec.ts b/src/app/calendar-app/calendar-app.component.spec.ts index e2b29af55..f8adc7b8a 100644 --- a/src/app/calendar-app/calendar-app.component.spec.ts +++ b/src/app/calendar-app/calendar-app.component.spec.ts @@ -36,6 +36,7 @@ import { of, Observable, ReplaySubject } from 'rxjs'; import { MatLegacySnackBar as MatSnackBar } from '@angular/material/legacy-snack-bar'; import { RunboxCalendar } from './runbox-calendar'; import { RunboxCalendarEvent } from './runbox-calendar-event'; +import { RunboxCalendarView } from './runbox-calendar-view'; import { MatIcon } from '@angular/material/icon'; import { MatIconTestingModule } from '@angular/material/icon/testing'; import moment from 'moment'; @@ -281,6 +282,27 @@ END:VCALENDAR expect(component.shown_events.length).toBe(shownEventsCount, 'same number of events shown after cycling through months'); }); + it('should advance by week when restoring the week calendar view from preferences (GH-1541)', () => { + const preferences = TestBed.inject(PreferencesService) as any; + const startDate = new Date('2024-02-26T12:00:00Z'); + + component.viewDate = new Date(startDate); + preferences.preferences.next(new Map([[ + 'global:calendarSettings', + { lastUsedView: RunboxCalendarView.Week } + ]])); + fixture.detectChanges(); + + expect(component.view).toBe(RunboxCalendarView.Week); + expect(component.mwlView).toBe(component.CalendarView.Week); + + fixture.debugElement.nativeElement.querySelector('button#nextPeriodButton').click(); + fixture.detectChanges(); + + const daysAdvanced = Math.round((component.viewDate.getTime() - startDate.getTime()) / (24 * 60 * 60 * 1000)); + expect(daysAdvanced).toBe(7); + }); + it('should not display yearly events as longer than they are (GH-179)', () => { mockData['events'] = GH_179_recurring_yearly; component.calendarservice.syncCaldav(true); diff --git a/src/app/calendar-app/calendar-app.component.ts b/src/app/calendar-app/calendar-app.component.ts index 0f1195171..188cff8f6 100644 --- a/src/app/calendar-app/calendar-app.component.ts +++ b/src/app/calendar-app/calendar-app.component.ts @@ -118,7 +118,8 @@ export class CalendarAppComponent implements OnDestroy { const storedSettings = prefs.get(`${this.prefGroup}:calendarSettings`); if (storedSettings) { this.settings = new CalendarSettings(storedSettings); - this.setView(this.settings.lastUsedView); + this.view = this.settings.lastUsedView; + this.syncMwlView(); } }); this.calendarservice.errorLog.subscribe(e => this.showError(e)); @@ -328,30 +329,35 @@ export class CalendarAppComponent implements OnDestroy { }); } + private syncMwlView(): void { + switch (this.view) { + case RunboxCalendarView.Overview: { + this.mwlView = null; + break; + } + case RunboxCalendarView.Month: { + this.mwlView = CalendarView.Month; + break; + } + case RunboxCalendarView.Week: { + this.mwlView = CalendarView.Week; + break; + } + case RunboxCalendarView.Day: { + this.mwlView = CalendarView.Day; + break; + } + } + } + setView(view: RunboxCalendarView): void { this.view = view; + if (this.settings.lastUsedView !== view) { this.settings.lastUsedView = this.view; this.preferenceService.set(this.prefGroup, 'calendarSettings', this.settings); - switch (this.view) { - case RunboxCalendarView.Overview: { - this.mwlView = null; - break; - } - case RunboxCalendarView.Month: { - this.mwlView = CalendarView.Month; - break; - } - case RunboxCalendarView.Week: { - this.mwlView = CalendarView.Week; - break; - } - case RunboxCalendarView.Day: { - this.mwlView = CalendarView.Day; - break; - } - } + this.syncMwlView(); } }