Skip to content

Commit 22ebc5d

Browse files
authored
Merge pull request #90 from Meta-Node/fro-317-fix-and-update-alerts-testing-implementations
fix: tests issue
2 parents a4df23e + 38e06b9 commit 22ebc5d

File tree

15 files changed

+564
-1028
lines changed

15 files changed

+564
-1028
lines changed

__tests__/components/alerts/InboundEvaluation.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppDispatch, configureAppStore, RootState } from '@/store';
2-
import { updateInboundData } from '@/store/notifications/slice';
2+
import { updateInboundData } from '@/store/notifications';
33
import {
44
createSubjectCategory,
55
generateEvaluationImpact,

__tests__/components/alerts/InboundLevelOrScoreChange.test.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@ import {
33
InboundProfile,
44
NotificationType,
55
updateInboundData,
6-
} from '@/store/notifications/slice';
6+
} from '@/store/notifications';
77
import {
8-
createSubjectCategory,
98
findProfileCategory,
10-
generateEvaluationImpact,
119
generateRandomBrightIdConnectionBackup,
1210
mockedBrightIdProfileData,
1311
TEST_BRIGHT_ID,
1412
TEST_BRIGHT_PASSWORD,
1513
} from '../../utils/api/profile';
16-
import {
17-
EvaluationCategory,
18-
EvaluationValue,
19-
PreferredView,
20-
} from '@/types/dashboard';
14+
import { EvaluationCategory, PreferredView } from '@/types/dashboard';
2115
import { setupServer } from 'msw/node';
2216
import { BrightIdBackupConnection } from '@/types';
2317
import { http, HttpResponse } from 'msw';

__tests__/components/alerts/InitialNotificationState.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
makeMockInboundInterceptor,
1818
makeMockOutboundInterceptor,
1919
} from '../../utils/api/server';
20-
import { triggerNotificationFetch } from '@/store/notifications/slice';
20+
import { triggerNotificationFetch } from '@/store/notifications';
2121

2222
const createMockStore = (): EnhancedStore => {
2323
return configureAppStore().store;

__tests__/components/alerts/OutboundUserEvaluation.test.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import {
33
OutboundProfile,
44
updateInboundData,
55
updateOutboundData,
6-
} from '@/store/notifications/slice';
6+
} from '@/store/notifications';
77
import {
88
createSubjectCategory,
9-
generateEvaluationImpact,
109
generateRandomBrightId,
1110
generateRandomBrightIdConnectionBackup,
1211
TEST_BRIGHT_ID,
@@ -19,11 +18,7 @@ import {
1918
} from '@/types/dashboard';
2019
import { setupServer } from 'msw/node';
2120
import { BrightIdBackupConnection } from '@/types';
22-
import { http, HttpResponse } from 'msw';
23-
import {
24-
makeMockInboundInterceptor,
25-
makeMockOutboundInterceptor,
26-
} from '../../utils/api/server';
21+
import { makeMockOutboundInterceptor } from '../../utils/api/server';
2722
import { EnhancedStore } from '@reduxjs/toolkit';
2823

2924
const createMockedData = () => {
@@ -59,7 +54,7 @@ const createMockedData = () => {
5954
evaluatorName: '',
6055
impact: -40000,
6156
modified: Date.now(),
62-
score: -10000,
57+
score: -40000,
6358
level: 2,
6459
},
6560
],
@@ -114,7 +109,7 @@ outboundTrackedProfiles.set(`${customUser.id}-${EvaluationCategory.SUBJECT}`, {
114109
evaluators: {},
115110
id: customUser.id,
116111
lastUpdated: Date.now() - 5 * 60000,
117-
level: 1,
112+
level: -1,
118113
score: -40000,
119114
});
120115

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

170165
const { outboundTrackedProfiles, alerts } = getState().alerts;
166+
console.log(alerts);
171167

172168
expect(alerts.length).toBe(1);
173169
});

__tests__/routes/home/Filters.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ connection1.auraEvaluations?.push({
3636
confidence: 4,
3737
evaluation: EvaluationValue.POSITIVE,
3838
modified: new Date().getTime() / 1000,
39+
timestamp: new Date().getTime() / 1000,
3940
});
4041

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

128130
addPlayerRuleWithCategoryToConnection(

__tests__/setup.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import '@testing-library/jest-dom';
22
import 'vitest-canvas-mock';
3-
import { setGlobalOrigin } from 'undici';
3+
import { setGlobalOrigin, fetch, Headers, Request, Response } from 'undici';
44

55
beforeEach(() => {
66
setGlobalOrigin(window.location.href);
77
});
88

9+
// @ts-ignore
10+
globalThis.fetch = fetch;
11+
// @ts-ignore
12+
globalThis.Headers = Headers;
13+
14+
// @ts-ignore
15+
globalThis.Request = Request;
16+
17+
// @ts-ignore
18+
globalThis.Response = Response;
19+
920
beforeAll(() => {
1021
window.PointerEvent = class PointerEvent extends Event {} as any;
1122
window.HTMLElement.prototype.scrollIntoView = vi.fn();

src/app/routes/_app.notifications/route.tsx

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import {
2-
LucideBell,
32
LucideTrendingUp,
43
LucideTrendingDown,
54
LucideArrowUp,
65
LucideArrowDown,
76
LucideUserCheck,
8-
RefreshCcwIcon,
97
} from 'lucide-react';
108
import { Card } from '@/components/ui/card';
11-
import { Notification } from '@/store/notifications';
9+
import { NotificationObject } from '@/store/notifications';
1210
import { Button } from '@/components/ui/button';
1311
import { cn } from '@/lib/utils';
1412
import DefaultHeader from '@/components/Header/DefaultHeader';
@@ -24,22 +22,18 @@ import BrightIdProfilePicture from '@/components/BrightIdProfilePicture';
2422
import { Link } from 'react-router';
2523
import { Fragment } from 'react/jsx-runtime';
2624
import {
27-
alertLoadingSelector,
2825
alertsSelector,
2926
markAllAsRead,
3027
markAsRead,
31-
NotificationObject,
3228
NotificationType,
33-
} from '@/store/notifications/slice';
29+
} from '@/store/notifications';
3430
import { useStore } from 'react-redux';
3531
import { compactFormat } from '@/utils/number';
3632
import {
3733
getBgClassNameOfAuraRatingObject,
3834
getTextClassNameOfAuraRatingObject,
3935
} from '@/constants';
4036
import { useMemo } from 'react';
41-
import Tooltip from '@/components/Shared/Tooltip';
42-
import { ratingToText } from '@/constants/chart';
4337

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

66-
function getIcon(notification: Notification) {
67-
if (
68-
notification.changeType === 'level' ||
69-
notification.changeType === 'score'
70-
) {
71-
if (
72-
typeof (notification as any).newValue === 'number' &&
73-
typeof (notification as any).oldValue === 'number'
74-
) {
75-
if (notification.changeType === 'level') {
76-
return (notification as any).newValue > (notification as any).oldValue
77-
? iconMap.level.up
78-
: iconMap.level.down;
79-
}
80-
if (notification.changeType === 'score') {
81-
return (notification as any).newValue > (notification as any).oldValue
82-
? iconMap.score.up
83-
: iconMap.score.down;
84-
}
85-
} else {
86-
return notification.changeType === 'level'
87-
? iconMap.level.up
88-
: iconMap.score.up;
89-
}
90-
}
91-
if (notification.changeType === 'evaluation') {
92-
return iconMap.evaluation;
93-
}
94-
return <LucideBell />;
95-
}
96-
9760
export function parseTitleAndDescription(
9861
description: string,
9962
type: NotificationType,

src/components/Header/DefaultHeader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { FC, PropsWithChildren, ReactNode } from 'react';
77
import { useSelector } from 'react-redux';
88
import { Link } from 'react-router';
99
import { FaHome } from 'react-icons/fa';
10-
import { notificationsSelector } from '@/store/notifications';
1110
import { Badge } from '@/components/ui/badge';
12-
import { alertsSelector } from '@/store/notifications/slice';
11+
import { alertsSelector } from '@/store/notifications';
1312

1413
export const HeaderBody: FC<
1514
PropsWithChildren & { title?: string; beforeTitle?: ReactNode }

src/components/Shared/Dropdown/index.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,20 @@ export default function Dropdown<T extends DropdownItem>({
4949
<SelectItem
5050
data-testid={`dropdown-option-${item.value}`}
5151
key={item.value}
52-
onMouseDown={() => {
53-
onItemClick(item);
54-
setIsDropdownOpen(false);
52+
{...{
53+
onMouseDown: process.env.VITEST
54+
? undefined
55+
: () => {
56+
onItemClick(item);
57+
setIsDropdownOpen(false);
58+
},
59+
60+
onClick: process.env.VITEST
61+
? () => {
62+
onItemClick(item);
63+
setIsDropdownOpen(false);
64+
}
65+
: undefined,
5566
}}
5667
value={item.value.toString()}
5768
>

src/components/notifications/notifications-checker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
alertsLastFetchSelector,
33
resetOnMountStates,
44
triggerNotificationFetch,
5-
} from '@/store/notifications/slice';
5+
} from '@/store/notifications';
66
import { selectAuthData } from '@/store/profile/selectors';
77
import { useEffect } from 'react';
88
import { useDispatch, useSelector, useStore } from 'react-redux';

0 commit comments

Comments
 (0)