Skip to content
Draft
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
9 changes: 9 additions & 0 deletions src/renderer/components/GlobalEffects.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ describe('renderer/components/GlobalEffects.tsx', () => {
expect(setTrayIconColorAndTitleSpy).toHaveBeenCalledWith(-1, true);
});

it('does not report an error to the tray while the query is offline', async () => {
await act(async () => {
renderWithProviders(<GlobalEffects />, { status: 'offline', notificationCount: 3 });
});

expect(setTrayIconColorAndTitleSpy).toHaveBeenCalledWith(3, true);
expect(setTrayIconColorAndTitleSpy).not.toHaveBeenCalledWith(-1, true);
});

it('resets all stores when the app is reset', async () => {
await act(async () => {
renderWithProviders(<GlobalEffects />, {
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/routes/Notifications.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ describe('renderer/routes/Notifications.tsx', () => {
expect(screen.queryByText('Loading')).not.toBeInTheDocument();
});

it('prefers the offline status over loading while the device is online', () => {
renderWithProviders(<NotificationsRoute />, {
status: 'offline',
isOnline: true,
});

expect(screen.getByText('Oops')).toBeInTheDocument();
expect(screen.queryByText('Loading')).not.toBeInTheDocument();
expect(screen.queryByText('AllRead')).not.toBeInTheDocument();
});

it('prefers the error state over loading', () => {
renderWithProviders(<NotificationsRoute />, {
globalError: getErrorDetails('UNKNOWN'),
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/routes/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function NotificationsRoute() {
[visibleNotifications],
);

if (!isOnline) {
if (!isOnline || status === 'offline') {
return <Oops error={getErrorDetails('OFFLINE')} />;
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function toLinkOrNull(value: string | null | undefined): Link | null {

export type SearchToken = Branded<string, 'SearchToken'>;

export type Status = 'loading' | 'success' | 'error';
export type Status = 'loading' | 'offline' | 'success' | 'error';

export type Percentage = Branded<number, 'Percentage'>;

Expand Down
23 changes: 21 additions & 2 deletions src/renderer/utils/notifications/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,27 @@ describe('renderer/utils/notifications/status.ts', () => {
expect(deriveStatus({ ...baseInput, isLoading: true, notifications: [] })).toBe('loading');
});

it('reports error when the query is paused (offline)', () => {
expect(deriveStatus({ ...baseInput, isPaused: true, notifications: [clean] })).toBe('error');
it('reports offline when the query is paused', () => {
expect(deriveStatus({ ...baseInput, isPaused: true, notifications: [clean] })).toBe(
'offline',
);
});

it('reports offline rather than error when paused with account errors', () => {
expect(
deriveStatus({ ...baseInput, isPaused: true, notifications: [networkError, networkError] }),
).toBe('offline');
});

it('reports offline before the initial fetch settles when paused', () => {
expect(
deriveStatus({
...baseInput,
isLoading: true,
isPaused: true,
notifications: [],
}),
).toBe('offline');
});

it('reports error when the query failed', () => {
Expand Down
11 changes: 9 additions & 2 deletions src/renderer/utils/notifications/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,26 @@ export interface NotificationStatusInput {
*
* Only the initial fetch (no settled success or error yet) reports `loading` -
* background refetches of already-settled data keep their settled status.
*
* A paused query means there is no connectivity, not that a fetch failed, so it
* reports `offline` rather than `error`. This keeps the tray and notifications
* view from showing a failure while the app is offline or reconnecting.
*/
export function deriveStatus({
isLoading,
isPaused,
isError,
notifications,
}: NotificationStatusInput): Status {
if (isPaused) {
return 'offline';
}

if (isLoading) {
return 'loading';
}

// Paused (offline) and outright query errors both surface as error status.
if (isPaused || isError) {
if (isError) {
return 'error';
}

Expand Down
Loading