2023-04-28 11:01:40 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { fireEvent, waitFor } from '@testing-library/react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2023-07-17 12:11:38 +02:00
|
|
|
import mockState from '../../../../test/data/mock-state.json';
|
2023-04-28 11:01:40 +02:00
|
|
|
import ConfirmRemoveJwt from '.';
|
|
|
|
|
|
|
|
const mockedRemoveAccount = jest.fn();
|
|
|
|
const mockedHideModal = jest.fn();
|
|
|
|
|
|
|
|
jest.mock('../../../store/actions', () => ({
|
|
|
|
removeAccount: () => mockedRemoveAccount,
|
|
|
|
hideModal: () => mockedHideModal,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const address = '0xaD6D458402F60fD3Bd25163575031ACDce07538D';
|
|
|
|
|
|
|
|
const props = {
|
|
|
|
hideModal: mockedHideModal,
|
2023-07-17 12:11:38 +02:00
|
|
|
token: address,
|
2023-04-28 11:01:40 +02:00
|
|
|
custodyAccountDetails: [
|
|
|
|
{
|
|
|
|
address,
|
|
|
|
name: 'Test name account',
|
|
|
|
labels: [],
|
|
|
|
authDetails: { token: address },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
accounts: [{ address, balance: '0x0' }],
|
|
|
|
};
|
|
|
|
|
|
|
|
const middleware = [thunk];
|
2023-07-17 12:11:38 +02:00
|
|
|
const store = configureMockStore(middleware)(mockState);
|
2023-04-28 11:01:40 +02:00
|
|
|
|
|
|
|
const render = () => {
|
|
|
|
return renderWithProvider(<ConfirmRemoveJwt {...props} />, store);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Confirm Remove JWT', function () {
|
|
|
|
it('should render correctly', () => {
|
|
|
|
const { container } = render();
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should show full token address when "show more" is clicked', () => {
|
|
|
|
const { getByText } = render();
|
|
|
|
|
|
|
|
const showMoreLink = getByText('Show more');
|
|
|
|
fireEvent.click(showMoreLink);
|
|
|
|
|
|
|
|
const fullTokenAddress = getByText(address);
|
|
|
|
expect(fullTokenAddress).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches removeAccount action when user clicks remove button', async () => {
|
|
|
|
const { getByText } = render();
|
|
|
|
|
|
|
|
const removeButton = getByText('Remove');
|
|
|
|
fireEvent.click(removeButton);
|
|
|
|
|
|
|
|
await waitFor(() => expect(mockedRemoveAccount).toHaveBeenCalled());
|
|
|
|
expect(mockedHideModal).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|