Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/app/calendar-app/calendar-app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
44 changes: 25 additions & 19 deletions src/app/calendar-app/calendar-app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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();
}
}

Expand Down
Loading