Skip to content

Commit 1d5c64c

Browse files
committed
Merge branch 'main' into jl/mmp-3725/caip-multichain-add-postMessage-stream-non-chromium
2 parents 5dc4318 + bf83353 commit 1d5c64c

File tree

3 files changed

+66
-28
lines changed

3 files changed

+66
-28
lines changed

test/e2e/tests/swaps/shared.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,17 @@ export const reviewQuote = async (
7474
'[data-testid="exchange-rate-display-quote-rate"]',
7575
);
7676
const summaryText = await summary.getText();
77-
assert.equal(summaryText.includes(options.swapFrom), true);
78-
assert.equal(summaryText.includes(options.swapTo), true);
77+
78+
await driver.waitForSelector({
79+
testId: 'prepare-swap-page-swap-from',
80+
text: options.swapFrom,
81+
});
82+
83+
await driver.waitForSelector({
84+
testId: 'prepare-swap-page-swap-to',
85+
text: options.swapTo,
86+
});
87+
7988
const quote = summaryText.split(`\n`);
8089

8190
const elementSwapToAmount = await driver.findElement(
@@ -138,22 +147,20 @@ export const checkActivityTransaction = async (
138147
await driver.clickElement('[data-testid="account-overview__activity-tab"]');
139148
await driver.waitForSelector('.activity-list-item');
140149

141-
const transactionList = await driver.findElements(
142-
'[data-testid="activity-list-item-action"]',
143-
);
144-
const transactionText = await transactionList[options.index].getText();
145-
assert.equal(
146-
transactionText,
147-
`Swap ${options.swapFrom} to ${options.swapTo}`,
148-
'Transaction not found',
149-
);
150+
await driver.waitForSelector({
151+
tag: 'p',
152+
text: `Swap ${options.swapFrom} to ${options.swapTo}`,
153+
});
150154

151155
await driver.findElement({
152156
css: '[data-testid="transaction-list-item-primary-currency"]',
153157
text: `-${options.amount} ${options.swapFrom}`,
154158
});
155159

156-
await transactionList[options.index].click();
160+
await driver.clickElement({
161+
tag: 'p',
162+
text: `Swap ${options.swapFrom} to ${options.swapTo}`,
163+
});
157164
await driver.delay(regularDelayMs);
158165

159166
await driver.findElement({
Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,57 @@
11
import React from 'react';
2-
import { render } from '@testing-library/react';
3-
import { Provider } from 'react-redux';
4-
import configureStore from 'redux-mock-store';
5-
import thunk from 'redux-thunk';
2+
import { fireEvent } from '@testing-library/react';
3+
import { createMockNotificationEthSent } from '@metamask/notification-services-controller/notification-services/mocks';
4+
import { processNotification } from '@metamask/notification-services-controller/notification-services';
5+
6+
import * as UseNotificationModule from '../../hooks/metamask-notifications/useNotifications';
7+
import { renderWithProvider } from '../../../test/lib/render-helpers';
8+
import configureStore from '../../store/store';
9+
import mockState from '../../../test/data/mock-state.json';
610
import { NotificationsListReadAllButton } from './notifications-list-read-all-button';
711

8-
const mockStore = configureStore([thunk]);
9-
const store = mockStore({
10-
metamask: {
11-
metamaskNotificationsList: [],
12-
},
13-
});
12+
const mockNotification = (isRead: boolean) => {
13+
const n = processNotification(createMockNotificationEthSent());
14+
n.isRead = isRead;
15+
return n;
16+
};
1417

1518
describe('NotificationsListReadAllButton', () => {
19+
const store = configureStore(mockState);
20+
1621
it('renders correctly and handles click', () => {
17-
const { getByTestId } = render(
18-
<Provider store={store}>
19-
<NotificationsListReadAllButton notifications={[]} />
20-
</Provider>,
22+
const { getByTestId } = renderWithProvider(
23+
<NotificationsListReadAllButton notifications={[]} />,
24+
store,
2125
);
2226

2327
const button = getByTestId('notifications-list-read-all-button');
2428
expect(button).toBeInTheDocument();
2529
});
30+
31+
it('presses and marks all unread notifications as read', async () => {
32+
const mockMarkAsReadCallback = jest.fn();
33+
jest
34+
.spyOn(UseNotificationModule, 'useMarkNotificationAsRead')
35+
.mockReturnValue({ markNotificationAsRead: mockMarkAsReadCallback });
36+
37+
const notificationList = [
38+
mockNotification(true),
39+
mockNotification(false),
40+
mockNotification(false),
41+
mockNotification(false),
42+
mockNotification(true),
43+
];
44+
45+
const { getByTestId } = renderWithProvider(
46+
<NotificationsListReadAllButton notifications={notificationList} />,
47+
store,
48+
);
49+
50+
const button = getByTestId('notifications-list-read-all-button');
51+
fireEvent.click(button);
52+
53+
expect(mockMarkAsReadCallback).toHaveBeenCalled();
54+
const mockCall = mockMarkAsReadCallback.mock.lastCall[0];
55+
expect(mockCall.length).toBe(3); // 3 unread notifications sent
56+
});
2657
});

ui/pages/notifications/notifications-list-read-all-button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export const NotificationsListReadAllButton = ({
3434
if (notifications && notifications.length > 0) {
3535
notificationsRead = notifications
3636
.filter(
37-
(notification): notification is Notification =>
38-
(notification as Notification).id !== undefined,
37+
(notification) =>
38+
notification?.id !== undefined && !notification.isRead,
3939
)
4040
.map((notification: Notification) => ({
4141
id: notification.id,

0 commit comments

Comments
 (0)