fix: list every signed-in account's calendars in Settings, not only the one on screen

This commit is contained in:
Linus Rath
2026-11-04 13:50:57 +01:00
parent 109866dd4c
commit cf7dda5fd1
2 changed files with 38 additions and 3 deletions
@@ -187,3 +187,35 @@ describe('CalendarManagementSettings with two accounts', () => {
useAccountStore.setState({ accounts: [], activeAccountId: null });
});
});
// pim-p2-3: opened straight away (no visit to Calendar first), Settings
// loaded only the account on screen.
describe('CalendarManagementSettings opened with two accounts signed in', () => {
it("loads and lists both accounts' calendars", async () => {
const { useAccountStore } = await import('@/stores/account-store');
const fake = (name: string) => ({
supportsCalendars: () => true,
getAccountId: () => 'acct',
getAllCalendarsWithFailures: vi.fn(async () => ({ calendars: [{ ...appleColored, id: 'cal', name }], failedAccountIds: [] })),
});
const clients: Record<string, unknown> = { 'login-a': fake('Home'), 'login-b': fake('Office') };
useAccountStore.setState({
accounts: [
{ id: 'login-a', email: 'a@example.org', username: 'a@example.org', displayName: 'Sam', label: 'Sam', isConnected: true },
{ id: 'login-b', email: 'b@example.org', username: 'b@example.org', displayName: 'Sam', label: 'Sam', isConnected: true },
] as never,
activeAccountId: 'login-a',
});
useAuthStore.setState({
client: clients['login-a'], serverUrl: null, username: null, activeAccountId: 'login-a',
getClientForAccount: ((id: string) => clients[id]) as never,
} as never);
useCalendarStore.setState({ calendars: [], icalSubscriptions: [], updateCalendar: vi.fn() } as never);
render(<CalendarManagementSettings />);
await waitFor(() => expect(screen.getAllByTestId('calendar-settings-account').map((el) => el.textContent)).toEqual(['a@example.org', 'b@example.org']));
useAccountStore.setState({ accounts: [], activeAccountId: null });
useCalendarStore.getState().setAccountClients(null, null);
});
});
@@ -25,6 +25,7 @@ import { useSettingsStore } from '@/stores/settings-store';
import { useManagedAccountStore } from '@/stores/managed-account-store';
import { useAccountStore } from '@/stores/account-store';
import { groupCalendarsByAccount } from '@/lib/calendar-targets';
import { useProMultiAccountCalendars } from '@/hooks/use-pro-multi-account-calendars';
import { apiFetch } from '@/lib/browser-navigation';
import { CALENDAR_COLORS, sharedCalendarColorKey } from '@/lib/shared-calendar-colors';
import { IS_LITE } from '@/lib/lite';
@@ -342,12 +343,14 @@ export function CalendarManagementSettings() {
calendars.some(cal => !cal.isShared && Object.keys(cal.shareWith ?? {}).length > 0 && resolvesShares(cal)),
);
// Load calendars if not yet loaded
// With several accounts signed in, every account's calendars, as in
// Calendar (pim-p2-3); else load them if not yet loaded.
const { enabled: allAccounts } = useProMultiAccountCalendars(null, null);
useEffect(() => {
if (client && calendars.length === 0) {
if (client && calendars.length === 0 && !allAccounts) {
fetchCalendars(client);
}
}, [client, calendars.length, fetchCalendars]);
}, [client, calendars.length, fetchCalendars, allAccounts]);
useEffect(() => {
// CalDAV discovery runs through /api/caldav/discover, absent in the static build.