Skip to content

Commit

Permalink
(#5) adicionando testes modal
Browse files Browse the repository at this point in the history
Co-authored-by: Sergio Cipriano <sergiosacj@protonmail.com>
  • Loading branch information
emysdias and sergiosacj committed Sep 17, 2021
1 parent 687d4f1 commit 3da09c9
Show file tree
Hide file tree
Showing 5 changed files with 228 additions and 169 deletions.
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "ta-na-mesa",
"version": "0.1.0",
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.1.0",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import '@testing-library/jest-dom';
import LoginModal from '../../../../components/Modal/LoginModal/index';

describe('LoginModal', () => {
it('renders nothing when not visible', () => {
const props = {
title: 'Some content',
visible: false,
onClose: () => {
return;
},
};
render(<LoginModal {...props} />);

expect(screen.queryByText('Some content')).not.toBeVisible();
});

it('renders content when visible', () => {
const props = {
title: 'Some content',
visible: true,
onClose: () => {
return;
},
};
render(<LoginModal {...props} />);

expect(screen.getByText('Some content')).toBeVisible();
});

it('fires onClosed when clicking the button', () => {
const onCloseHandler = jest.fn();
const props = {
title: 'Some content',
visible: true,
onClose: onCloseHandler,
};
render(<LoginModal {...props} />);

const button = screen.getByRole('button');
fireEvent.click(button);

expect(onCloseHandler).toHaveBeenCalled();
});

it('fires onClosed when pressing esc', () => {
const onCloseHandler = jest.fn();
const props = {
title: 'Some content',
visible: true,
onClose: onCloseHandler,
};
render(<LoginModal {...props} />);

fireEvent.keyDown(document.body, {
key: 'Escape',
keyCode: 27,
which: 27,
});

expect(onCloseHandler).toHaveBeenCalled();
});
});
6 changes: 3 additions & 3 deletions frontend/src/components/Modal/LoginModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React, { useEffect, useRef } from 'react';
import { Container } from 'components/Modal/LoginModal/styles';

type Props = {
title?: string;
title: string;
visible: boolean;
onClose: (event: any) => void;
};

const Modal: React.FC<Props> = ({ title, visible, onClose }) => {
const LoginModal: React.FC<Props> = ({ title, visible, onClose }) => {
const modalRef = useRef(null);

useEffect(() => {
Expand Down Expand Up @@ -41,4 +41,4 @@ const Modal: React.FC<Props> = ({ title, visible, onClose }) => {
);
};

export default Modal;
export default LoginModal;
Loading

0 comments on commit 3da09c9

Please sign in to comment.