|
| 1 | +import { fireEvent, screen, waitFor } from '@testing-library/react'; |
1 | 2 | import React from 'react';
|
2 |
| -import { screen, fireEvent } from '@testing-library/react'; |
3 |
| -import { renderWithProvider } from '../../../../test/jest'; |
4 |
| -import configureStore from '../../../store/store'; |
5 |
| -import mockState from '../../../../test/data/mock-state.json'; |
| 3 | +import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; |
6 | 4 | import { NOTIFICATION_SOLANA_ON_METAMASK } from '../../../../shared/notifications';
|
| 5 | +import { MOCK_ACCOUNT_SOLANA_MAINNET } from '../../../../test/data/mock-accounts'; |
| 6 | +import mockState from '../../../../test/data/mock-state.json'; |
| 7 | +import { renderWithProvider } from '../../../../test/jest'; |
7 | 8 | import { useMultichainWalletSnapClient } from '../../../hooks/accounts/useMultichainWalletSnapClient';
|
8 |
| -import { MultichainNetworks } from '../../../../shared/constants/multichain/networks'; |
| 9 | +import configureStore from '../../../store/store'; |
9 | 10 | import WhatsNewModal from './whats-new-modal';
|
10 | 11 |
|
11 | 12 | jest.mock('../../../hooks/accounts/useMultichainWalletSnapClient', () => ({
|
@@ -34,7 +35,11 @@ describe('WhatsNewModal', () => {
|
34 | 35 | });
|
35 | 36 | });
|
36 | 37 |
|
37 |
| - const renderModalWithNotification = (notificationId: number) => { |
| 38 | + const renderModalWithNotification = ({ |
| 39 | + notificationId, |
| 40 | + }: { |
| 41 | + notificationId: number; |
| 42 | + }) => { |
38 | 43 | const store = configureStore({
|
39 | 44 | metamask: {
|
40 | 45 | ...mockState.metamask,
|
@@ -102,55 +107,153 @@ describe('WhatsNewModal', () => {
|
102 | 107 | };
|
103 | 108 |
|
104 | 109 | describe('Whats new notification modal', () => {
|
105 |
| - beforeEach(() => { |
106 |
| - renderModalWithNotification(NOTIFICATION_SOLANA_ON_METAMASK); |
107 |
| - }); |
| 110 | + describe('Content agnostic functionality', () => { |
| 111 | + beforeEach(() => { |
| 112 | + renderModalWithNotification({ |
| 113 | + notificationId: NOTIFICATION_SOLANA_ON_METAMASK, |
| 114 | + }); |
| 115 | + }); |
108 | 116 |
|
109 |
| - it('calls onClose when the modal is closed', () => { |
110 |
| - const closeButton = screen.getByRole('button', { name: /close/iu }); |
111 |
| - fireEvent.click(closeButton); |
112 |
| - expect(mockOnClose).toHaveBeenCalled(); |
113 |
| - }); |
| 117 | + it('calls onClose when the modal is closed', async () => { |
| 118 | + const closeButton = screen.getByRole('button', { name: /close/iu }); |
| 119 | + fireEvent.click(closeButton); |
114 | 120 |
|
115 |
| - it('renders Solana notification content correctly', () => { |
116 |
| - expect(screen.getByTestId('solana-modal-body')).toBeInTheDocument(); |
117 |
| - expect( |
118 |
| - screen.getByText(/Send, receive, and swap tokens/iu), |
119 |
| - ).toBeInTheDocument(); |
120 |
| - expect(screen.getByText(/Import Solana accounts/iu)).toBeInTheDocument(); |
121 |
| - expect( |
122 |
| - screen.getByText(/More features coming soon/iu), |
123 |
| - ).toBeInTheDocument(); |
| 121 | + await waitFor(() => { |
| 122 | + expect(mockOnClose).toHaveBeenCalled(); |
| 123 | + }); |
| 124 | + }); |
124 | 125 | });
|
125 | 126 |
|
126 |
| - it('opens the create solana account modal and handles account creation', async () => { |
127 |
| - const createButton = screen.getByTestId('create-solana-account-button'); |
128 |
| - fireEvent.click(createButton); |
| 127 | + describe('Solana notification content', () => { |
| 128 | + describe('when the user does not have a Solana account', () => { |
| 129 | + beforeEach(() => { |
| 130 | + renderModalWithNotification({ |
| 131 | + notificationId: NOTIFICATION_SOLANA_ON_METAMASK, |
| 132 | + }); |
| 133 | + }); |
| 134 | + |
| 135 | + it('renders Solana notification when the user does not have a Solana account', () => { |
| 136 | + expect(screen.getByTestId('solana-modal-body')).toBeInTheDocument(); |
| 137 | + expect( |
| 138 | + screen.getByText(/Send, receive, and swap tokens/iu), |
| 139 | + ).toBeInTheDocument(); |
| 140 | + expect( |
| 141 | + screen.getByText(/Import Solana accounts/iu), |
| 142 | + ).toBeInTheDocument(); |
| 143 | + expect( |
| 144 | + screen.getByText(/More features coming soon/iu), |
| 145 | + ).toBeInTheDocument(); |
| 146 | + expect( |
| 147 | + screen.getByTestId('create-solana-account-button'), |
| 148 | + ).toBeInTheDocument(); |
| 149 | + expect(screen.getByTestId('not-now-button')).toBeInTheDocument(); |
| 150 | + }); |
| 151 | + |
| 152 | + it('opens the "Create account" modal when clicking the "Create account" button', async () => { |
| 153 | + const createButton = screen.getByTestId( |
| 154 | + 'create-solana-account-button', |
| 155 | + ); |
| 156 | + fireEvent.click(createButton); |
| 157 | + |
| 158 | + expect( |
| 159 | + screen.queryByTestId('whats-new-modal'), |
| 160 | + ).not.toBeInTheDocument(); |
| 161 | + |
| 162 | + expect( |
| 163 | + screen.getByTestId('create-solana-account-modal'), |
| 164 | + ).toBeInTheDocument(); |
129 | 165 |
|
130 |
| - expect(screen.queryByTestId('whats-new-modal')).not.toBeInTheDocument(); |
| 166 | + // TODO: The next code should be tested in the CreateSolanaAccountModal component |
131 | 167 |
|
132 |
| - expect( |
133 |
| - screen.getByTestId('create-solana-account-modal'), |
134 |
| - ).toBeInTheDocument(); |
| 168 | + const accountNameInput = screen.getByLabelText(/account name/iu); |
| 169 | + fireEvent.change(accountNameInput, { |
| 170 | + target: { value: 'Test Account' }, |
| 171 | + }); |
135 | 172 |
|
136 |
| - const accountNameInput = screen.getByLabelText(/account name/iu); |
137 |
| - fireEvent.change(accountNameInput, { target: { value: 'Test Account' } }); |
| 173 | + const submitButton = screen.getByTestId( |
| 174 | + 'submit-add-account-with-name', |
| 175 | + ); |
| 176 | + fireEvent.click(submitButton); |
138 | 177 |
|
139 |
| - const submitButton = screen.getByTestId('submit-add-account-with-name'); |
140 |
| - fireEvent.click(submitButton); |
| 178 | + await expect(mockCreateAccount).toHaveBeenCalledWith({ |
| 179 | + scope: MultichainNetworks.SOLANA, |
| 180 | + entropySource: KEYRING_ID, |
| 181 | + accountNameSuggestion: 'Test Account', |
| 182 | + }); |
| 183 | + }); |
141 | 184 |
|
142 |
| - await expect(mockCreateAccount).toHaveBeenCalledWith({ |
143 |
| - scope: MultichainNetworks.SOLANA, |
144 |
| - entropySource: KEYRING_ID, |
145 |
| - accountNameSuggestion: 'Test Account', |
| 185 | + it('closes the modal when clicking "Not Now"', async () => { |
| 186 | + const notNowButton = screen.getByTestId('not-now-button'); |
| 187 | + fireEvent.click(notNowButton); |
| 188 | + |
| 189 | + await waitFor(() => { |
| 190 | + expect(mockOnClose).toHaveBeenCalled(); |
| 191 | + }); |
| 192 | + }); |
146 | 193 | });
|
147 |
| - expect(mockOnClose).toHaveBeenCalled(); |
148 |
| - }); |
149 | 194 |
|
150 |
| - it('closes the modal when clicking "Not Now"', () => { |
151 |
| - const notNowButton = screen.getByTestId('not-now-button'); |
152 |
| - fireEvent.click(notNowButton); |
153 |
| - expect(mockOnClose).toHaveBeenCalled(); |
| 195 | + describe('when the user has a Solana account', () => { |
| 196 | + beforeEach(() => { |
| 197 | + const store = configureStore({ |
| 198 | + metamask: { |
| 199 | + ...mockState.metamask, |
| 200 | + announcements: { |
| 201 | + [NOTIFICATION_SOLANA_ON_METAMASK]: { |
| 202 | + date: '2025-03-03', |
| 203 | + id: NOTIFICATION_SOLANA_ON_METAMASK, |
| 204 | + isShown: false, |
| 205 | + }, |
| 206 | + }, |
| 207 | + keyrings: [ |
| 208 | + { |
| 209 | + metadata: { |
| 210 | + id: KEYRING_ID, |
| 211 | + }, |
| 212 | + }, |
| 213 | + ], |
| 214 | + internalAccounts: { |
| 215 | + accounts: { |
| 216 | + [MOCK_ACCOUNT_SOLANA_MAINNET.id]: MOCK_ACCOUNT_SOLANA_MAINNET, |
| 217 | + }, |
| 218 | + }, |
| 219 | + }, |
| 220 | + }); |
| 221 | + renderWithProvider(<WhatsNewModal onClose={mockOnClose} />, store); |
| 222 | + }); |
| 223 | + |
| 224 | + it('renders Solana notification correctly', () => { |
| 225 | + expect(screen.getByTestId('solana-modal-body')).toBeInTheDocument(); |
| 226 | + expect( |
| 227 | + screen.getByText(/Send, receive, and swap tokens/iu), |
| 228 | + ).toBeInTheDocument(); |
| 229 | + expect( |
| 230 | + screen.getByText(/Import Solana accounts/iu), |
| 231 | + ).toBeInTheDocument(); |
| 232 | + expect( |
| 233 | + screen.getByText(/More features coming soon/iu), |
| 234 | + ).toBeInTheDocument(); |
| 235 | + expect(screen.getByTestId('got-it-button')).toBeInTheDocument(); |
| 236 | + expect(screen.getByTestId('not-now-button')).toBeInTheDocument(); |
| 237 | + }); |
| 238 | + |
| 239 | + it('closes the modal when clicking "Got it"', async () => { |
| 240 | + const gotItButton = screen.getByTestId('got-it-button'); |
| 241 | + fireEvent.click(gotItButton); |
| 242 | + |
| 243 | + await waitFor(() => { |
| 244 | + expect(mockOnClose).toHaveBeenCalled(); |
| 245 | + }); |
| 246 | + }); |
| 247 | + |
| 248 | + it('closes the modal when clicking "Not Now"', async () => { |
| 249 | + const notNowButton = screen.getByTestId('not-now-button'); |
| 250 | + fireEvent.click(notNowButton); |
| 251 | + |
| 252 | + await waitFor(() => { |
| 253 | + expect(mockOnClose).toHaveBeenCalled(); |
| 254 | + }); |
| 255 | + }); |
| 256 | + }); |
154 | 257 | });
|
155 | 258 | });
|
156 | 259 | });
|
0 commit comments