Skip to content
Merged
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
2 changes: 1 addition & 1 deletion __tests__/components/alerts/InboundEvaluation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppDispatch, configureAppStore, RootState } from '@/store';
import { updateInboundData } from '@/store/notifications/slice';
import { updateInboundData } from '@/store/notifications';
import {
createSubjectCategory,
generateEvaluationImpact,
Expand Down
10 changes: 2 additions & 8 deletions __tests__/components/alerts/InboundLevelOrScoreChange.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ import {
InboundProfile,
NotificationType,
updateInboundData,
} from '@/store/notifications/slice';
} from '@/store/notifications';
import {
createSubjectCategory,
findProfileCategory,
generateEvaluationImpact,
generateRandomBrightIdConnectionBackup,
mockedBrightIdProfileData,
TEST_BRIGHT_ID,
TEST_BRIGHT_PASSWORD,
} from '../../utils/api/profile';
import {
EvaluationCategory,
EvaluationValue,
PreferredView,
} from '@/types/dashboard';
import { EvaluationCategory, PreferredView } from '@/types/dashboard';
import { setupServer } from 'msw/node';
import { BrightIdBackupConnection } from '@/types';
import { http, HttpResponse } from 'msw';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
makeMockInboundInterceptor,
makeMockOutboundInterceptor,
} from '../../utils/api/server';
import { triggerNotificationFetch } from '@/store/notifications/slice';
import { triggerNotificationFetch } from '@/store/notifications';

const createMockStore = (): EnhancedStore => {
return configureAppStore().store;
Expand Down
14 changes: 5 additions & 9 deletions __tests__/components/alerts/OutboundUserEvaluation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import {
OutboundProfile,
updateInboundData,
updateOutboundData,
} from '@/store/notifications/slice';
} from '@/store/notifications';
import {
createSubjectCategory,
generateEvaluationImpact,
generateRandomBrightId,
generateRandomBrightIdConnectionBackup,
TEST_BRIGHT_ID,
Expand All @@ -19,11 +18,7 @@ import {
} from '@/types/dashboard';
import { setupServer } from 'msw/node';
import { BrightIdBackupConnection } from '@/types';
import { http, HttpResponse } from 'msw';
import {
makeMockInboundInterceptor,
makeMockOutboundInterceptor,
} from '../../utils/api/server';
import { makeMockOutboundInterceptor } from '../../utils/api/server';
import { EnhancedStore } from '@reduxjs/toolkit';

const createMockedData = () => {
Expand Down Expand Up @@ -59,7 +54,7 @@ const createMockedData = () => {
evaluatorName: '',
impact: -40000,
modified: Date.now(),
score: -10000,
score: -40000,
level: 2,
},
],
Expand Down Expand Up @@ -114,7 +109,7 @@ outboundTrackedProfiles.set(`${customUser.id}-${EvaluationCategory.SUBJECT}`, {
evaluators: {},
id: customUser.id,
lastUpdated: Date.now() - 5 * 60000,
level: 1,
level: -1,
score: -40000,
});

Expand Down Expand Up @@ -168,6 +163,7 @@ describe('outbound notification generations', () => {
await updateOutboundData(getState, dispatch, TEST_BRIGHT_ID);

const { outboundTrackedProfiles, alerts } = getState().alerts;
console.log(alerts);

expect(alerts.length).toBe(1);
});
Expand Down
2 changes: 2 additions & 0 deletions __tests__/routes/home/Filters.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ connection1.auraEvaluations?.push({
confidence: 4,
evaluation: EvaluationValue.POSITIVE,
modified: new Date().getTime() / 1000,
timestamp: new Date().getTime() / 1000,
});

const domains = connection1.verifications![0].domains!;
Expand Down Expand Up @@ -123,6 +124,7 @@ connection5.auraEvaluations?.push({
confidence: 4,
evaluation: EvaluationValue.NEGATIVE,
modified: new Date().getTime() / 1000,
timestamp: new Date().getTime() / 1000 - -2000,
});

addPlayerRuleWithCategoryToConnection(
Expand Down
13 changes: 12 additions & 1 deletion __tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import '@testing-library/jest-dom';
import 'vitest-canvas-mock';
import { setGlobalOrigin } from 'undici';
import { setGlobalOrigin, fetch, Headers, Request, Response } from 'undici';

beforeEach(() => {
setGlobalOrigin(window.location.href);
});

// @ts-ignore
globalThis.fetch = fetch;
// @ts-ignore
globalThis.Headers = Headers;

// @ts-ignore
globalThis.Request = Request;

// @ts-ignore
globalThis.Response = Response;

beforeAll(() => {
window.PointerEvent = class PointerEvent extends Event {} as any;
window.HTMLElement.prototype.scrollIntoView = vi.fn();
Expand Down
41 changes: 2 additions & 39 deletions src/app/routes/_app.notifications/route.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import {
LucideBell,
LucideTrendingUp,
LucideTrendingDown,
LucideArrowUp,
LucideArrowDown,
LucideUserCheck,
RefreshCcwIcon,
} from 'lucide-react';
import { Card } from '@/components/ui/card';
import { Notification } from '@/store/notifications';
import { NotificationObject } from '@/store/notifications';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import DefaultHeader from '@/components/Header/DefaultHeader';
Expand All @@ -24,22 +22,18 @@ import BrightIdProfilePicture from '@/components/BrightIdProfilePicture';
import { Link } from 'react-router';
import { Fragment } from 'react/jsx-runtime';
import {
alertLoadingSelector,
alertsSelector,
markAllAsRead,
markAsRead,
NotificationObject,
NotificationType,
} from '@/store/notifications/slice';
} from '@/store/notifications';
import { useStore } from 'react-redux';
import { compactFormat } from '@/utils/number';
import {
getBgClassNameOfAuraRatingObject,
getTextClassNameOfAuraRatingObject,
} from '@/constants';
import { useMemo } from 'react';
import Tooltip from '@/components/Shared/Tooltip';
import { ratingToText } from '@/constants/chart';

// Define icons for evaluation categories
export const subjectViewAsIconColored: {
Expand All @@ -63,37 +57,6 @@ const iconMap = {
evaluation: <LucideUserCheck className="text-blue-500" />,
};

function getIcon(notification: Notification) {
if (
notification.changeType === 'level' ||
notification.changeType === 'score'
) {
if (
typeof (notification as any).newValue === 'number' &&
typeof (notification as any).oldValue === 'number'
) {
if (notification.changeType === 'level') {
return (notification as any).newValue > (notification as any).oldValue
? iconMap.level.up
: iconMap.level.down;
}
if (notification.changeType === 'score') {
return (notification as any).newValue > (notification as any).oldValue
? iconMap.score.up
: iconMap.score.down;
}
} else {
return notification.changeType === 'level'
? iconMap.level.up
: iconMap.score.up;
}
}
if (notification.changeType === 'evaluation') {
return iconMap.evaluation;
}
return <LucideBell />;
}

export function parseTitleAndDescription(
description: string,
type: NotificationType,
Expand Down
3 changes: 1 addition & 2 deletions src/components/Header/DefaultHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import { FC, PropsWithChildren, ReactNode } from 'react';
import { useSelector } from 'react-redux';
import { Link } from 'react-router';
import { FaHome } from 'react-icons/fa';
import { notificationsSelector } from '@/store/notifications';
import { Badge } from '@/components/ui/badge';
import { alertsSelector } from '@/store/notifications/slice';
import { alertsSelector } from '@/store/notifications';

export const HeaderBody: FC<
PropsWithChildren & { title?: string; beforeTitle?: ReactNode }
Expand Down
17 changes: 14 additions & 3 deletions src/components/Shared/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,20 @@ export default function Dropdown<T extends DropdownItem>({
<SelectItem
data-testid={`dropdown-option-${item.value}`}
key={item.value}
onMouseDown={() => {
onItemClick(item);
setIsDropdownOpen(false);
{...{
onMouseDown: process.env.VITEST
? undefined
: () => {
onItemClick(item);
setIsDropdownOpen(false);
},

onClick: process.env.VITEST
? () => {
onItemClick(item);
setIsDropdownOpen(false);
}
: undefined,
}}
value={item.value.toString()}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/notifications/notifications-checker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
alertsLastFetchSelector,
resetOnMountStates,
triggerNotificationFetch,
} from '@/store/notifications/slice';
} from '@/store/notifications';
import { selectAuthData } from '@/store/profile/selectors';
import { useEffect } from 'react';
import { useDispatch, useSelector, useStore } from 'react-redux';
Expand Down
8 changes: 3 additions & 5 deletions src/prompt-sw.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cleanupOutdatedCaches } from 'workbox-precaching';
import { setupPwa } from '@vite-pwa/remix/sw';
import { setupRoutes } from './shared-sw';
import { triggerNotificationFetch } from './store/notifications/slice';
import { triggerNotificationFetch } from './store/notifications';
import { configureAppStore } from './store';

declare const self: ServiceWorkerGlobalScope;
Expand Down Expand Up @@ -35,15 +35,13 @@ self.addEventListener('periodicsync', (event: any) => {
subjectId,
);

const { notifications } = store.getState();
const { alerts } = store.getState();

if (Notification.permission !== 'granted') {
return;
}

const newNotifications = notifications.items.filter(
(item) => !item.viewed,
);
const newNotifications = alerts.alerts.filter((item) => !item.viewed);

if (!newNotifications.length) return;

Expand Down
4 changes: 1 addition & 3 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { operationsSlice } from '@/BrightID/actions';
import { cacheSlice } from './cache';
import localforage from 'localforage';
import { notificationsSlice } from './notifications';
import { alertsSlice } from './notifications/slice';
import { contactsSlice } from './contacts';

const migrationManifest = createMigrate(migrations, { debug: __DEV__ });
Expand Down Expand Up @@ -100,9 +99,8 @@ const rootReducer = withReduxStateSync(
combineReducers({
...reducers,
profile: profileSlice.reducer,
[notificationsSlice.reducerPath]: notificationsSlice.reducer,
[contactsSlice.reducerPath]: contactsSlice.reducer,
[alertsSlice.reducerPath]: alertsSlice.reducer,
[notificationsSlice.reducerPath]: notificationsSlice.reducer,
[cacheSlice.reducerPath]: cacheSlice.reducer,
}),
);
Expand Down
Loading
Loading