Skip to content

Commit eef6a84

Browse files
committed
add Snapshot tests for walletconnect
1 parent 6374354 commit eef6a84

File tree

2 files changed

+93
-87
lines changed

2 files changed

+93
-87
lines changed

__tests__/WalletConnect/ConnectModal.test.js

Lines changed: 8 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -3,93 +3,14 @@
33
* @jest-environment jsdom
44
*/
55
import React from 'react';
6-
import { render, screen } from '../../test-utils';
7-
import nextRouter from 'next/router';
86
import ConnectModal from '../../components/WalletConnect/ConnectModal';
9-
// Test cases for full balances, empty balances, and undefined balances.
10-
const subgraphBounty = {
11-
__typename: 'Bounty',
12-
bountyAddress: '0x13f7816057de7256daf5028eaf8e79775d3a27a3',
13-
bountyId: 'I_kwDOGWnnz85I9Ahl',
14-
bountyMintTime: '1654041044',
15-
bountyClosedTime: null,
16-
status: 'OPEN',
17-
claimedTransactionHash: null,
18-
deposits: [
19-
{
20-
__typename: 'Deposit',
21-
id: '0xd024e550ba670d71f23f336c63ed0aacda946c6836f416028ffa0888b1a4b691',
22-
refunded: false,
23-
refundTime: null,
24-
expiration: '2592000',
25-
tokenAddress: '0x5fbdb2315678afecb367f032d93f642f64180aa3',
26-
volume: '12000000000000000000',
27-
sender: {
28-
__typename: 'User',
29-
id: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
30-
},
31-
receiveTime: '1642021044',
32-
},
33-
],
34-
issuer: {
35-
__typename: 'User',
36-
id: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
37-
},
38-
bountyTokenBalances: [
39-
{
40-
__typename: 'BountyFundedTokenBalance',
41-
volume: '12000000000000000000',
42-
tokenAddress: '0x5fbdb2315678afecb367f032d93f642f64180aa3',
43-
},
44-
],
45-
};
46-
47-
describe('WatchButton', () => {
48-
// Test cases for
49-
50-
const push = jest.fn(() => {
51-
return { catch: jest.fn };
52-
});
53-
const closeModal = jest.fn();
54-
55-
beforeEach(() => {
56-
const observe = jest.fn();
57-
const disconnect = jest.fn();
58-
window.IntersectionObserver = jest.fn(() => ({
59-
observe,
60-
disconnect,
61-
}));
62-
63-
nextRouter.useRouter = jest.fn();
64-
nextRouter.useRouter.mockImplementation(() => ({
65-
query: { type: null },
66-
prefetch: jest.fn(() => {
67-
return { catch: jest.fn };
68-
}),
69-
push,
70-
}));
71-
});
72-
73-
it('should render watch button', async () => {
74-
// ARRANGE
75-
render(<ConnectModal bounty={subgraphBounty} closeModal={closeModal} watchingState={false} />);
76-
77-
// ASSERT
78-
const nullish = [...screen.queryAllByRole(/null/), ...screen.queryAllByRole(/undefined/)];
79-
expect(nullish).toHaveLength(0);
80-
});
81-
82-
it('should open modal and display link to profile.', async () => {
83-
// ARRANGE
84-
render(<ConnectModal closeModal={closeModal} />);
85-
86-
const heading = screen.getByText(/Connect Wallet/i);
87-
const metamaskButton = screen.getByRole('button', { name: /Metamask/i });
88-
const walletConnect = screen.getByRole('button', { name: /WalletConnect/i });
89-
90-
// ASSERT
91-
expect(heading).toBeInTheDocument();
92-
expect(metamaskButton).toBeInTheDocument();
93-
expect(walletConnect).toBeInTheDocument();
7+
import ShallowRenderer from 'react-test-renderer/shallow';
8+
9+
describe('ConnectModal', () => {
10+
it('should render match DOM Snapshot', () => {
11+
const shallow = new ShallowRenderer();
12+
shallow.render(<ConnectModal />);
13+
const tree = shallow.getRenderOutput();
14+
expect(tree).toMatchSnapshot();
9415
});
9516
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ConnectModal should render match DOM Snapshot 1`] = `
4+
<ModalLarge
5+
footerRight={
6+
<button
7+
className="btn-default w-full"
8+
>
9+
Close
10+
</button>
11+
}
12+
isWalletConnect={true}
13+
title="Connect Wallet"
14+
>
15+
<div
16+
className="p-4"
17+
>
18+
<p
19+
className="text-xl pt-2"
20+
>
21+
Connect your wallet to continue with OpenQ. By connecting your wallet you agree with OpenQ
22+
'
23+
s
24+
25+
<a
26+
className="hover:underline text-blue-400"
27+
href="https://www.openq.dev/terms-of-service"
28+
rel="noopener noreferrer"
29+
target="_blank"
30+
>
31+
terms of service
32+
</a>
33+
.
34+
</p>
35+
<button
36+
className="flex py-4 pl-4 my-8 w-full gap-8 btn-default"
37+
onClick={[Function]}
38+
>
39+
<Image
40+
alt="metamask logo"
41+
height={40}
42+
src="/wallet-logos/metamask.png"
43+
width={40}
44+
/>
45+
<div
46+
className="text-lg leading-loose"
47+
>
48+
Metamask
49+
</div>
50+
</button>
51+
<button
52+
className="flex py-4 pl-4 mb-8 w-full gap-8 btn-default"
53+
onClick={[Function]}
54+
>
55+
<Image
56+
alt="wallet connect logo"
57+
className="rounded-full"
58+
height={40}
59+
src="/wallet-logos/wallet-connect.jpg"
60+
width={40}
61+
/>
62+
<div
63+
className="leading-loose text-lg"
64+
>
65+
WalletConnect
66+
</div>
67+
</button>
68+
<p
69+
className="text-sm text-muted pb-4"
70+
>
71+
Are you using Gnosis Safe? For the best experience use OpenQ as a Safe App. For more information on safe apps, check out
72+
73+
<a
74+
className="underline"
75+
href="https://help.gnosis-safe.io/en/articles/4022030-add-a-custom-safe-app"
76+
rel="noopener noreferrer"
77+
target="_blank"
78+
>
79+
Add a Custom Safe App
80+
</a>
81+
.
82+
</p>
83+
</div>
84+
</ModalLarge>
85+
`;

0 commit comments

Comments
 (0)