Skip to content

Commit 6374354

Browse files
committed
add Snapshot tests for remaining Utils components
1 parent d6d907d commit 6374354

File tree

4 files changed

+87
-47
lines changed

4 files changed

+87
-47
lines changed

__tests__/Utils/TooltipNew.test.js

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,29 @@
22
* @jest-environment jsdom
33
*/
44
import React from 'react';
5-
import { render, screen } from '../../test-utils';
65
import ToolTipNew from '../../components/Utils/ToolTipNew';
7-
import nextRouter from 'next/router';
6+
import renderer from 'react-test-renderer';
87
// Test cases for full balances, empty balances, and undefined balances.
98
const Child = () => {
109
return <div></div>;
1110
};
1211

13-
describe('AccountModal', () => {
14-
// Test cases for
15-
let push;
16-
beforeEach(() => {
17-
push = jest.fn(() => {
18-
return { catch: jest.fn };
19-
});
20-
process.env.BASE_URL = 'http://localhost:3000';
21-
const observe = jest.fn();
22-
const disconnect = jest.fn();
23-
window.IntersectionObserver = jest.fn(() => ({
24-
observe,
25-
disconnect,
26-
}));
27-
28-
nextRouter.useRouter = jest.fn();
29-
nextRouter.useRouter.mockImplementation(() => ({
30-
query: { type: null },
31-
prefetch: jest.fn(() => {
32-
return { catch: jest.fn };
33-
}),
34-
push,
35-
}));
36-
});
37-
38-
it('should display tooltip', async () => {
39-
// ARRANGE
40-
render(<ToolTipNew toolTipText='sample text' />);
41-
// ASSERT
42-
expect(screen.getByText(/sample text/)).toBeInTheDocument();
43-
});
44-
45-
it('should hide tooltip', async () => {
46-
// ARRANGE
47-
render(
48-
<ToolTipNew hideToolTip={true} toolTipText='sample text'>
12+
describe('ToolTipNew', () => {
13+
it('should match DOM Snapshot & display tooltip with styles', () => {
14+
const tree = renderer.create(
15+
<ToolTipNew toolTipText='sample text' outerStyles={'outerStyles'} innerStyles={'innerStyles'} hideToolTip={false}>
4916
<Child />
5017
</ToolTipNew>
5118
);
52-
// ASSERT
53-
expect(screen.queryByText(/sample text/)).not.toBeInTheDocument();
19+
expect(tree.toJSON()).toMatchSnapshot();
5420
});
55-
it('should show tooltip styles', async () => {
56-
// ARRANGE
57-
render(
58-
<ToolTipNew toolTipText='sample text' outerStyles={'outerStyles'} innerStyles={'innerStyles'} hideToolTip={false}>
21+
22+
it('should match DOM Snapshot & hide tooltip', () => {
23+
const tree = renderer.create(
24+
<ToolTipNew hideToolTip={true} toolTipText='sample text'>
5925
<Child />
6026
</ToolTipNew>
6127
);
62-
// ASSERT
63-
expect(document.querySelector('.innerStyles')).toBeInTheDocument();
64-
expect(document.querySelector('.outerStyles')).toBeInTheDocument();
28+
expect(tree.toJSON()).toMatchSnapshot();
6529
});
6630
});

__tests__/Utils/TweetAbout.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import TweetAbout from '../../components/Utils/TweetAbout';
3+
import renderer from 'react-test-renderer';
4+
import Constants from '../../test-utils/constant';
5+
6+
describe('TweetAbout', () => {
7+
const bounty = Constants.bounty;
8+
const tweetText = 'Please tweet me!';
9+
it('should match DOM Snapshot', () => {
10+
const tree = renderer.create(<TweetAbout tweetText={tweetText} bounty={bounty} />);
11+
expect(tree.toJSON()).toMatchSnapshot();
12+
});
13+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ToolTipNew should match DOM Snapshot & display tooltip with styles 1`] = `
4+
<div
5+
className="group undefined"
6+
>
7+
<div />
8+
<div
9+
className="justify-center w-full relative hidden z-50 group-hover:block outerStyles "
10+
>
11+
<div
12+
className="flex flex-col items-center"
13+
>
14+
<div
15+
className="flex mt-0.5 md:mt-1 tooltip-triangle absolute undefined"
16+
/>
17+
<div
18+
className="flex tooltip absolute undefined"
19+
>
20+
<div
21+
className="innerStyles"
22+
>
23+
sample text
24+
</div>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
`;
30+
31+
exports[`ToolTipNew should match DOM Snapshot & hide tooltip 1`] = `<div />`;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`TweetAbout should match DOM Snapshot 1`] = `
4+
<div
5+
className="flex justify-center items-center btn-primary"
6+
onClick={[Function]}
7+
onMouseEnter={[Function]}
8+
onTouchStart={[Function]}
9+
>
10+
<div
11+
className="flex justify-center items-center gap-2"
12+
>
13+
<div
14+
className=""
15+
data-testid="link"
16+
>
17+
Tweet about it
18+
</div>
19+
<svg
20+
className="w-4 inline"
21+
height="24"
22+
viewBox="0 0 128 128"
23+
width="24"
24+
>
25+
<path
26+
d="M40.254 127.637c48.305 0 74.719-48.957 74.719-91.403 0-1.39 0-2.777-.075-4.156 5.141-4.547 9.579-10.18 13.102-16.633-4.79 2.602-9.871 4.305-15.078 5.063 5.48-4.02 9.582-10.336 11.539-17.774-5.156 3.743-10.797 6.38-16.68 7.801-8.136-10.586-21.07-13.18-31.547-6.32-10.472 6.86-15.882 21.46-13.199 35.617C41.922 38.539 22.246 26.336 8.915 6.27 1.933 20.94 5.487 39.723 17.022 49.16c-4.148-.172-8.207-1.555-11.832-4.031v.41c0 15.273 8.786 28.438 21.02 31.492a21.596 21.596 0 01-11.863.543c3.437 13.094 13.297 22.07 24.535 22.328-9.305 8.918-20.793 13.75-32.617 13.72-2.094 0-4.188-.15-6.266-.446 12.008 9.433 25.98 14.441 40.254 14.422"
27+
fill="#ffffff"
28+
/>
29+
</svg>
30+
</div>
31+
</div>
32+
`;

0 commit comments

Comments
 (0)