2022-03-31 17:16:30 +00:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
|
|
|
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
|
|
|
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
|
|
|
import type { VegaWalletConnectButtonProps } from './vega-wallet-connect-button';
|
|
|
|
import { VegaWalletConnectButton } from './vega-wallet-connect-button';
|
2022-08-31 04:35:46 +00:00
|
|
|
import { truncateByChars } from '@vegaprotocol/react-helpers';
|
2022-03-31 17:16:30 +00:00
|
|
|
|
|
|
|
let props: VegaWalletConnectButtonProps;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
props = {
|
|
|
|
setConnectDialog: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const generateJsx = (
|
|
|
|
context: VegaWalletContextShape,
|
|
|
|
props: VegaWalletConnectButtonProps
|
|
|
|
) => {
|
|
|
|
return (
|
|
|
|
<VegaWalletContext.Provider value={context}>
|
|
|
|
<VegaWalletConnectButton {...props} />
|
|
|
|
</VegaWalletContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-12 12:32:14 +00:00
|
|
|
it('Not connected', () => {
|
2022-03-31 17:16:30 +00:00
|
|
|
render(generateJsx({ keypair: null } as VegaWalletContextShape, props));
|
|
|
|
|
|
|
|
const button = screen.getByRole('button');
|
|
|
|
expect(button).toHaveTextContent('Connect Vega wallet');
|
|
|
|
fireEvent.click(button);
|
|
|
|
expect(props.setConnectDialog).toHaveBeenCalledWith(true);
|
|
|
|
});
|
|
|
|
|
2022-05-12 12:32:14 +00:00
|
|
|
it('Connected', () => {
|
2022-08-31 04:35:46 +00:00
|
|
|
const keypair = { pub: '123456__123456', name: 'test' };
|
2022-03-31 17:16:30 +00:00
|
|
|
render(
|
|
|
|
generateJsx(
|
2022-08-31 04:35:46 +00:00
|
|
|
{ keypair, keypairs: [keypair] } as VegaWalletContextShape,
|
2022-03-31 17:16:30 +00:00
|
|
|
props
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
const button = screen.getByRole('button');
|
2022-08-31 04:35:46 +00:00
|
|
|
expect(button).toHaveTextContent(
|
|
|
|
`${keypair.name}: ${truncateByChars(keypair.pub)}`
|
|
|
|
);
|
2022-03-31 17:16:30 +00:00
|
|
|
fireEvent.click(button);
|
|
|
|
expect(props.setConnectDialog).not.toHaveBeenCalled();
|
|
|
|
});
|