Skip to content

Commit

Permalink
Merge pull request #25 from severidade/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
severidade authored Nov 29, 2024
2 parents 8dbc05e + 1a4b8c6 commit f91dcd2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/Footer/Footer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import Footer from './index';

describe('Component Footer', () => {
describe('👢 - Component Footer', () => {
it('o texto "Tecnologias" deve ser exibido na tela', () => {
render(<Footer />);
const text = screen.getByText(/Tecnologias/i);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Loading/Loading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react';
import { describe, it, expect } from 'vitest';
import Loading from './index';

describe('Component Loading', () => {
describe('⏳ - Component Loading', () => {
it('o texto "Carregando" deve ser exibido na tela', () => {
render(<Loading />);
const loadingText = screen.getByText(/Carregando/i);
Expand Down
68 changes: 68 additions & 0 deletions src/components/Navbar/NavBar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { render, screen } from '@testing-library/react';
import { MemoryRouter, Route, Routes } from 'react-router-dom'; // Importa o MemoryRouter
import Navbar from './Navbar';
import styles from './navbar.module.css';

describe('🍔 - Menu testes', () => {

it('Renderiza container com lista de itens de menu', () => {
// Envolve o componente Navbar com o MemoryRouter
render(
<MemoryRouter>
<Navbar />
</MemoryRouter>
);

const containerNav = screen.getByRole('navigation');

expect(containerNav).toBeInTheDocument();
expect(containerNav).toHaveClass(styles.container_nav_link);
});

it('Renderiza no mínimo um item de menu', () => {
render(
<MemoryRouter>
<Navbar />
</MemoryRouter>
);

const navLinkElements = screen.getAllByRole('link');
const navLinkElement = navLinkElements[0];

expect(navLinkElements.length).toBeGreaterThan(0);

expect(navLinkElement).toBeInTheDocument();
expect(navLinkElement).toHaveClass(styles.nav_link);
});

it('Inicia com a classe "ativo" na rota principal', () => {
render(
<MemoryRouter initialEntries={['/']}>
<Routes>
<Route path="/" element={<Navbar />} />
</Routes>
</MemoryRouter>
);

const homeLink = screen.getByTestId('link-home');
expect(homeLink).toHaveClass(styles.active);
});

it('Verifica se o link "home" esta inativo quando outra rota é acessada', () => {

render(
<MemoryRouter initialEntries={['/demo02']}>
<Routes>
<Route path="/demo02" element={<Navbar />} />
</Routes>
</MemoryRouter>
);


const navLinkElements = screen.getAllByRole('link');
const homeLink = navLinkElements[0];

expect(homeLink).not.toHaveClass(styles.active);
expect(navLinkElements[1]).toHaveClass(styles.active)
});
});
17 changes: 14 additions & 3 deletions src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ import styles from './navbar.module.css';
import { NavLink } from 'react-router-dom';
function Navbar() {
return (
<nav className={styles.container_nav_link}>
<NavLink to="/" className={({ isActive }) => `${styles.nav_link} ${isActive && styles.active} link`} >
<nav
className={styles.container_nav_link}
role="navigation"
>
<NavLink
to="/"
className={({ isActive }) => `${styles.nav_link} ${isActive && styles.active} link`}
data-testid="link-home"
>
Demo 01
</NavLink>
<NavLink to="/demo02" className={({ isActive }) => `${styles.nav_link} ${isActive && styles.active} link`}>
<NavLink
to="/demo02"
className={({ isActive }) => `${styles.nav_link} ${isActive && styles.active} link`}
data-testid="link-demo-02"
>
Demo 02
</NavLink>
</nav>
Expand Down

0 comments on commit f91dcd2

Please sign in to comment.