-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathNotificationsCategory.test.tsx
More file actions
131 lines (107 loc) · 4.21 KB
/
Copy pathNotificationsCategory.test.tsx
File metadata and controls
131 lines (107 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React from 'react';
import { fireEvent, render } from '@testing-library/react-native';
import NotificationsCategory from './NotificationsCategory';
import { NotificationsCategorySelectorsIDs } from './NotificationsCategory.testIds';
let mockIsMetamaskNotificationsEnabled = true;
let mockIsSocialLeaderboardEnabled = false;
let mockIsPriceAlertsEnabled = false;
let mockCategories: Array<{ categoryId: string; ausKeys: string[] }> = [
{ categoryId: 'walletActivity', ausKeys: ['walletActivity'] },
{ categoryId: 'perps', ausKeys: ['perps'] },
{ categoryId: 'socialAI', ausKeys: ['socialAI'] },
{ categoryId: 'marketing', ausKeys: ['marketing'] },
];
let mockIsLoading = false;
jest.mock('react-redux', () => ({
useSelector: (selector: (state: unknown) => unknown) => selector({}),
}));
jest.mock('../../../../selectors/notifications', () => ({
selectIsMetamaskNotificationsEnabled: () =>
mockIsMetamaskNotificationsEnabled,
}));
jest.mock(
'../../../../selectors/featureFlagController/socialLeaderboard',
() => ({
selectSocialLeaderboardEnabled: () => mockIsSocialLeaderboardEnabled,
}),
);
jest.mock('../../../../selectors/featureFlagController/priceAlerts', () => ({
selectPriceAlertsEnabled: () => mockIsPriceAlertsEnabled,
}));
jest.mock('../../../../util/notifications/categories', () => ({
...jest.requireActual('../../../../util/notifications/categories'),
useNotificationCategories: () => ({
categories: mockCategories,
isLoading: mockIsLoading,
}),
}));
describe('NotificationsCategory', () => {
beforeEach(() => {
mockIsMetamaskNotificationsEnabled = true;
mockIsSocialLeaderboardEnabled = false;
mockIsPriceAlertsEnabled = false;
mockIsLoading = false;
mockCategories = [
{ categoryId: 'walletActivity', ausKeys: ['walletActivity'] },
{ categoryId: 'perps', ausKeys: ['perps'] },
{ categoryId: 'socialAI', ausKeys: ['socialAI'] },
{ categoryId: 'marketing', ausKeys: ['marketing'] },
];
});
it('renders the All tab plus one tab per catalog category', () => {
const { getByTestId, queryByTestId } = render(
<NotificationsCategory onSelect={jest.fn()} />,
);
expect(getByTestId(NotificationsCategorySelectorsIDs.ALL)).toBeTruthy();
expect(getByTestId('notifications-category-walletActivity')).toBeTruthy();
expect(getByTestId('notifications-category-perps')).toBeTruthy();
expect(getByTestId('notifications-category-marketing')).toBeTruthy();
expect(queryByTestId('notifications-category-socialAI')).toBeNull();
});
it('shows the socialAI tab when the social leaderboard flag is enabled', () => {
mockIsSocialLeaderboardEnabled = true;
const { getByTestId } = render(
<NotificationsCategory onSelect={jest.fn()} />,
);
expect(getByTestId('notifications-category-socialAI')).toBeTruthy();
});
it('calls onSelect with the categoryId when a tab is pressed', () => {
const onSelect = jest.fn();
const { getByTestId } = render(
<NotificationsCategory onSelect={onSelect} />,
);
fireEvent(getByTestId('notifications-category-perps'), 'onPress');
expect(onSelect).toHaveBeenCalledWith('perps');
});
it('renders a loading skeleton while categories are loading', () => {
mockIsLoading = true;
const { queryByTestId } = render(
<NotificationsCategory onSelect={jest.fn()} />,
);
expect(
queryByTestId(NotificationsCategorySelectorsIDs.CONTAINER),
).toBeNull();
expect(
queryByTestId(NotificationsCategorySelectorsIDs.SKELETON),
).toBeTruthy();
});
it('renders neither tabs nor a skeleton while loading if notifications are disabled', () => {
mockIsLoading = true;
mockIsMetamaskNotificationsEnabled = false;
const { queryByTestId } = render(
<NotificationsCategory onSelect={jest.fn()} />,
);
expect(
queryByTestId(NotificationsCategorySelectorsIDs.SKELETON),
).toBeNull();
});
it('renders nothing when MetaMask notifications are disabled', () => {
mockIsMetamaskNotificationsEnabled = false;
const { queryByTestId } = render(
<NotificationsCategory onSelect={jest.fn()} />,
);
expect(
queryByTestId(NotificationsCategorySelectorsIDs.CONTAINER),
).toBeNull();
});
});