vega-frontend-monorepo/apps/trading/components/vega-wallet-connect-button/vega-wallet-connect-button.spec.tsx
Matthew Russell 15551b65e5
Feat/83 switching vega key (#156)
* add manage dialog to wallet lib, add it to trading app

* add test for wallet button

* add tests for manage dialog

* move tooltip to ui-toolkit, add copy with tooltip component for manage dialog

* add better labelling

* add tooltip story

* add story for copy-with-tooltip

* add tests for tooltip and copy-with-tooltip

* move useFakeTimers call to beforeAll

* adjust design of manage dialog

* fix linting issues
2022-03-31 10:16:30 -07:00

52 lines
1.5 KiB
TypeScript

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';
let props: VegaWalletConnectButtonProps;
beforeEach(() => {
props = {
setConnectDialog: jest.fn(),
setManageDialog: jest.fn(),
};
});
const generateJsx = (
context: VegaWalletContextShape,
props: VegaWalletConnectButtonProps
) => {
return (
<VegaWalletContext.Provider value={context}>
<VegaWalletConnectButton {...props} />
</VegaWalletContext.Provider>
);
};
test('Not connected', () => {
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);
expect(props.setManageDialog).not.toHaveBeenCalled();
});
test('Connected', () => {
render(
generateJsx(
{ keypair: { pub: '123456__123456' } } as VegaWalletContextShape,
props
)
);
expect(screen.getByText('Vega key:')).toBeInTheDocument();
const button = screen.getByRole('button');
expect(button).toHaveTextContent('123456\u2026123456');
fireEvent.click(button);
expect(props.setManageDialog).toHaveBeenCalledWith(true);
expect(props.setConnectDialog).not.toHaveBeenCalled();
});