Skip to content

Gabarito #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { screen } from '@testing-library/react';
import React from 'react-dom';
import userEvent from '@testing-library/user-event';
import renderWithRouter from './renderWithRouter';
import App from '../App';

describe('Test of APP component.', () => {
it('Should render a link with Home text.', () => {
renderWithRouter(<App />);
const homeEl = screen.getByRole('link', { name: /home/i });
expect(homeEl).toBeDefined();
});

it('Should render a link with About text.', () => {
renderWithRouter(<App />);
const AboutEl = screen.getByRole('link', { name: /About/i });
expect(AboutEl).toBeDefined();
});

it('Should render a link with Favorite Pokémons text.', () => {
renderWithRouter(<App />);
const FavoriteEl = screen.getByRole('link', { name: /favorite pokémons/i });
expect(FavoriteEl).toBeDefined();
});

it('Should go to path / when Home is clicked.', () => {
const { history } = renderWithRouter(<App />);

const homeEl = screen.getByRole('link', { name: /home/i });
expect(homeEl).toBeDefined();

userEvent.click(homeEl);
const { pathname } = history.location;
expect(pathname).toBe('/');
});

it('Should go to path /about when About is clicked.', () => {
const { history } = renderWithRouter(<App />);

const AboutEl = screen.getByRole('link', { name: /About/i });
expect(AboutEl).toBeDefined();

userEvent.click(AboutEl);
const { pathname } = history.location;
expect(pathname).toBe('/about');
});

it('Should go to path /favorites when Favorites is clicked.', () => {
const { history } = renderWithRouter(<App />);

const FavoriteEl = screen.getByRole('link', { name: /favorite pokémons/i });
expect(FavoriteEl).toBeDefined();

userEvent.click(FavoriteEl);
const { pathname } = history.location;
expect(pathname).toBe('/favorites');
});

it('Should render a 404 if a non-existant page is selected', () => {
const { history } = renderWithRouter(<App />);

history.push('/xablau');

const notFound = screen.getByRole('heading', { name: /page requested not found/i });
expect(notFound).toBeDefined();
});
});

// describe('', () => {
// it('', () => { });
// it('', () => { });
// it('', () => { });
// it('', () => { });
// });
Loading