Skip to content

Commit 4f5fb39

Browse files
committed
Add modal initial test
1 parent 585d504 commit 4f5fb39

File tree

4 files changed

+60
-11
lines changed

4 files changed

+60
-11
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"dependencies": {
66
"@testing-library/jest-dom": "^5.16.5",
77
"@testing-library/react": "^13.4.0",
8-
"@testing-library/user-event": "^12.1.10",
8+
"@testing-library/user-event": "^14.4.3",
99
"framer-motion": "4.1.17",
1010
"postcss-cli": "^10.1.0",
1111
"react": "^18.1.0",
@@ -45,6 +45,7 @@
4545
},
4646
"devDependencies": {
4747
"@tailwindcss/forms": "^0.5.2",
48+
"@testing-library/dom": "^8.20.0",
4849
"autoprefixer": "^10.4.7",
4950
"postcss": "^8.4.21",
5051
"tailwindcss": "^3.0.24"

src/__tests__/Banner.test.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,33 @@ function setupUserEvent(jsx) {
1313
};
1414
}
1515

16-
test('it shows the name in banner', () => {
16+
test('it shows the title in the banner', () => {
1717
setup();
18-
const titleElement = screen.getByText(/Hi, Iam Stoman/i);
19-
expect(titleElement).toBeInTheDocument();
18+
// We expect that the title 'Hi, Iam Stoman' is in the banner component
19+
expect(screen.getByText(/Hi, Iam Stoman/i)).toBeInTheDocument();
20+
});
21+
22+
test('can download cv when clicked on download cv button', async () => {
23+
const { user } = setupUserEvent(<AppBanner />);
24+
25+
const downloadCV = screen.getByText(/Download CV/i);
26+
27+
expect(downloadCV).toBeInTheDocument();
28+
29+
const downloadCVButton = downloadCV.parentElement.parentElement;
30+
31+
expect(downloadCVButton).toBeInTheDocument();
32+
33+
await user.click(downloadCVButton);
34+
35+
// const downloadLink = {
36+
// click: await user.click(downloadCVButton),
37+
// };
38+
// jest.spyOn(document, 'createElement').mockImplementation(
39+
// () => downloadLink
40+
// );
41+
42+
// expect(downloadLink.download).toEqual('Stoman-Resume.pdf');
43+
// expect(downloadLink.href).toEqual('/files/Stoman-Resume.pdf');
44+
// expect(downloadLink.click).toHaveBeenCalledTimes(1);
2045
});

src/__tests__/Modal.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { render, screen } from '@testing-library/react';
2+
import userEvent from '@testing-library/user-event';
3+
import HireMeModal from '../components/HireMeModal';
4+
5+
// Get user event
6+
function setupUserEvent(jsx) {
7+
return {
8+
user: userEvent.setup(),
9+
...render(jsx),
10+
};
11+
}
12+
13+
test('modal shows the children and a close button', async () => {
14+
const { user } = setupUserEvent(<HireMeModal />);
15+
16+
expect(
17+
screen.getByText(/What project are you looking for?/i)
18+
).toBeInTheDocument();
19+
20+
const closeModal = screen.getByText(/Close/i);
21+
expect(closeModal).toBeInTheDocument();
22+
23+
const closeModalButton = closeModal.parentElement;
24+
expect(closeModalButton).toBeInTheDocument();
25+
});

yarn.lock

+5-7
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,7 @@
17141714
dependencies:
17151715
mini-svg-data-uri "^1.2.3"
17161716

1717-
"@testing-library/dom@^8.5.0":
1717+
"@testing-library/dom@^8.20.0", "@testing-library/dom@^8.5.0":
17181718
version "8.20.0"
17191719
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.20.0.tgz#914aa862cef0f5e89b98cc48e3445c4c921010f6"
17201720
integrity sha512-d9ULIT+a4EXLX3UU8FBjauG9NnsZHkHztXoIcTsOKoOw030fyjheN9svkTULjJxtYag9DZz5Jz5qkWZDPxTFwA==
@@ -1752,12 +1752,10 @@
17521752
"@testing-library/dom" "^8.5.0"
17531753
"@types/react-dom" "^18.0.0"
17541754

1755-
"@testing-library/user-event@^12.1.10":
1756-
version "12.8.3"
1757-
resolved "https://registry.npmjs.org/@testing-library/user-event/-/user-event-12.8.3.tgz"
1758-
integrity sha512-IR0iWbFkgd56Bu5ZI/ej8yQwrkCv8Qydx6RzwbKz9faXazR/+5tvYKsZQgyXJiwgpcva127YO6JcWy7YlCfofQ==
1759-
dependencies:
1760-
"@babel/runtime" "^7.12.5"
1755+
"@testing-library/user-event@^14.4.3":
1756+
version "14.4.3"
1757+
resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.4.3.tgz#af975e367743fa91989cd666666aec31a8f50591"
1758+
integrity sha512-kCUc5MEwaEMakkO5x7aoD+DLi02ehmEM2QCGWvNqAS1dV/fAvORWEjnjsEIvml59M7Y5kCkWN6fCCyPOe8OL6Q==
17611759

17621760
"@tootallnate/once@1":
17631761
version "1.1.2"

0 commit comments

Comments
 (0)