Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
jonybur committed Dec 16, 2024
1 parent 831db7d commit 97642ec
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,59 +1,80 @@
import React from 'react';
import { fireEvent } from '@testing-library/react';
import { renderWithProvider } from '../../../../../../test/jest';
import { Provider } from 'react-redux';
import { render, fireEvent } from '@testing-library/react';
import configureStore from '../../../../../store/store';
import mockState from '../../../../../../test/data/mock-state.json';
import { SiteCell } from './site-cell';

describe('SiteCell', () => {
const store = configureStore({
metamask: {
...mockState.metamask,
useBlockie: false,
},
});

const defaultProps = {
nonTestNetworks: [],
testNetworks: [],
accounts: [],
onSelectAccountAddresses: jest.fn(),
onSelectChainIds: jest.fn(),
selectedAccountAddresses: [],
selectedChainIds: [],
};

describe('toast handling', () => {
it('should call hideAllToasts when edit accounts is clicked', () => {
const hideAllToasts = jest.fn();
const { getByTestId } = renderWithProvider(
<SiteCell {...defaultProps} hideAllToasts={hideAllToasts} />,
store,
const { getAllByTestId } = render(
<Provider store={store}>
<SiteCell
nonTestNetworks={[]}
testNetworks={[]}
accounts={[]}
onSelectAccountAddresses={() => undefined}
onSelectChainIds={() => undefined}
selectedAccountAddresses={[]}
selectedChainIds={[]}
hideAllToasts={hideAllToasts}
/>
</Provider>,
);

fireEvent.click(getByTestId('edit-accounts'));
const editButtons = getAllByTestId('edit');
fireEvent.click(editButtons[0]);
expect(hideAllToasts).toHaveBeenCalled();
});

it('should call hideAllToasts when edit networks is clicked', () => {
const hideAllToasts = jest.fn();
const { getByTestId } = renderWithProvider(
<SiteCell {...defaultProps} hideAllToasts={hideAllToasts} />,
store,
const { getAllByTestId } = render(
<Provider store={store}>
<SiteCell
nonTestNetworks={[]}
testNetworks={[]}
accounts={[]}
onSelectAccountAddresses={() => undefined}
onSelectChainIds={() => undefined}
selectedAccountAddresses={[]}
selectedChainIds={[]}
hideAllToasts={hideAllToasts}
/>
</Provider>,
);

fireEvent.click(getByTestId('edit-networks'));
const editButtons = getAllByTestId('edit');
fireEvent.click(editButtons[1]);
expect(hideAllToasts).toHaveBeenCalled();
});

it('should not throw if hideAllToasts is not provided', () => {
const { getByTestId } = renderWithProvider(
<SiteCell {...defaultProps} />,
store,
const { getAllByTestId } = render(
<Provider store={store}>
<SiteCell
nonTestNetworks={[]}
testNetworks={[]}
accounts={[]}
onSelectAccountAddresses={() => undefined}
onSelectChainIds={() => undefined}
selectedAccountAddresses={[]}
selectedChainIds={[]}
/>
</Provider>,
);

expect(() => {
fireEvent.click(getByTestId('edit-accounts'));
fireEvent.click(getByTestId('edit-networks'));
const editButtons = getAllByTestId('edit');
fireEvent.click(editButtons[0]);
fireEvent.click(editButtons[1]);
}).not.toThrow();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type SiteCellProps = {
selectedAccountAddresses: string[];
selectedChainIds: string[];
isConnectFlow?: boolean;
hideAllToasts: () => void;
hideAllToasts?: () => void;
};

export const SiteCell: React.FC<SiteCellProps> = ({
Expand Down

0 comments on commit 97642ec

Please sign in to comment.