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 { 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
|
|
|
|
2022-10-14 15:42:53 +00:00
|
|
|
const mockUpdateDialogOpen = jest.fn();
|
|
|
|
jest.mock('@vegaprotocol/wallet', () => ({
|
|
|
|
...jest.requireActual('@vegaprotocol/wallet'),
|
|
|
|
useVegaWalletDialogStore: () => ({
|
|
|
|
openVegaWalletDialog: mockUpdateDialogOpen,
|
|
|
|
}),
|
|
|
|
}));
|
2022-03-31 17:16:30 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-10-14 15:42:53 +00:00
|
|
|
jest.clearAllMocks();
|
2022-03-31 17:16:30 +00:00
|
|
|
});
|
|
|
|
|
2022-10-14 15:42:53 +00:00
|
|
|
const generateJsx = (context: VegaWalletContextShape) => {
|
2022-03-31 17:16:30 +00:00
|
|
|
return (
|
|
|
|
<VegaWalletContext.Provider value={context}>
|
2022-10-14 15:42:53 +00:00
|
|
|
<VegaWalletConnectButton />
|
2022-03-31 17:16:30 +00:00
|
|
|
</VegaWalletContext.Provider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-12 12:32:14 +00:00
|
|
|
it('Not connected', () => {
|
2022-10-14 15:42:53 +00:00
|
|
|
render(generateJsx({ pubKey: null } as VegaWalletContextShape));
|
2022-03-31 17:16:30 +00:00
|
|
|
|
|
|
|
const button = screen.getByRole('button');
|
|
|
|
expect(button).toHaveTextContent('Connect Vega wallet');
|
|
|
|
fireEvent.click(button);
|
2022-10-14 15:42:53 +00:00
|
|
|
expect(mockUpdateDialogOpen).toHaveBeenCalled();
|
2022-03-31 17:16:30 +00:00
|
|
|
});
|
|
|
|
|
2022-05-12 12:32:14 +00:00
|
|
|
it('Connected', () => {
|
2022-10-03 18:12:34 +00:00
|
|
|
const pubKey = { publicKey: '123456__123456', name: 'test' };
|
2022-03-31 17:16:30 +00:00
|
|
|
render(
|
2022-10-14 15:42:53 +00:00
|
|
|
generateJsx({
|
|
|
|
pubKey: pubKey.publicKey,
|
|
|
|
pubKeys: [pubKey],
|
|
|
|
} as VegaWalletContextShape)
|
2022-03-31 17:16:30 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
const button = screen.getByRole('button');
|
2022-10-03 18:12:34 +00:00
|
|
|
expect(button).toHaveTextContent(truncateByChars(pubKey.publicKey));
|
2022-03-31 17:16:30 +00:00
|
|
|
fireEvent.click(button);
|
2022-10-14 15:42:53 +00:00
|
|
|
expect(mockUpdateDialogOpen).not.toHaveBeenCalled();
|
2022-03-31 17:16:30 +00:00
|
|
|
});
|