-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from rayane-barbosa/rayane-barbosa/testes-unit…
…arios Rayane barbosa/testes unitarios
- Loading branch information
Showing
17 changed files
with
347 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { socials } from './socials' | ||
|
||
describe('socials', () => { | ||
it('should have at least one social link', () => { | ||
expect(socials.length).toBeGreaterThan(0) | ||
}) | ||
|
||
it('should have valid href values', () => { | ||
socials.forEach((social) => { | ||
expect(social.href).toMatch(/^https?:\/\/[^\s/$.?#].[^\s]*$/) | ||
}) | ||
}) | ||
|
||
it('should have valid icon components', () => { | ||
socials.forEach((social) => { | ||
expect(social.icon).toBeDefined() | ||
expect(typeof social.icon).toBe('object') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { AppHeader } from '@/components/header' | ||
import '@testing-library/jest-dom' | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
import { BrowserRouter as Router } from 'react-router-dom' | ||
|
||
jest.mock('@/hooks/useIsMobile', () => ({ | ||
useIsMobile: () => true, | ||
})) | ||
|
||
jest.mock('@uidotdev/usehooks', () => ({ | ||
useWindowScroll: () => [{ y: 0 }], | ||
})) | ||
|
||
describe('AppHeader', () => { | ||
it('renders without crashing', () => { | ||
render( | ||
<Router> | ||
<AppHeader /> | ||
</Router>, | ||
) | ||
}) | ||
it('displays the hamburger menu icon on mobile', () => { | ||
render( | ||
<Router> | ||
<AppHeader /> | ||
</Router>, | ||
) | ||
const hamburgerMenuIcon = screen.getByRole('button') | ||
expect(hamburgerMenuIcon).toBeInTheDocument() | ||
}) | ||
|
||
it('displays the navigation menu when the hamburger menu icon is clicked', () => { | ||
render( | ||
<Router> | ||
<AppHeader /> | ||
</Router>, | ||
) | ||
const hamburgerMenuIcon = screen.getByRole('button') | ||
fireEvent.click(hamburgerMenuIcon) | ||
const navMenu = screen.getByRole('navigation') | ||
expect(navMenu).toBeInTheDocument() | ||
}) | ||
|
||
it('displays the "Voltar à home" link when not on the home page', () => { | ||
window.history.pushState({}, '', '/not-home') | ||
render( | ||
<Router> | ||
<AppHeader /> | ||
</Router>, | ||
) | ||
const link = screen.getByText('Voltar à home') | ||
expect(link).toBeInTheDocument() | ||
}) | ||
|
||
it('displays the "Cadastrar um pet" link when not on the subscription page', () => { | ||
window.history.pushState({}, '', '/not-subscription') | ||
render( | ||
<Router> | ||
<AppHeader /> | ||
</Router>, | ||
) | ||
const link = screen.getByText('Cadastrar um pet') | ||
expect(link).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import { JoinUs } from './index' | ||
|
||
describe('JoinUs component', () => { | ||
beforeEach(() => { | ||
render(<JoinUs />) | ||
}) | ||
|
||
it('renders without crashing', () => { | ||
const joinUsElement = screen.getByText(/Faça parte da nossa equipe/i) | ||
expect(joinUsElement).toBeInTheDocument() | ||
}) | ||
|
||
it('contains a Paw component', () => { | ||
const pawElement = screen.getByTestId('join-us-paw') | ||
expect(pawElement).toBeInTheDocument() | ||
}) | ||
|
||
it('contains a Button component', () => { | ||
const buttonElement = screen.getByTestId('join-us-button') | ||
expect(buttonElement).toBeInTheDocument() | ||
}) | ||
|
||
it('contains a link to the Discord server', () => { | ||
const linkElement = screen.getByRole('link') | ||
expect(linkElement).toHaveAttribute( | ||
'href', | ||
'https://discord.com/invite/Pr2BZmUG', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import { OthersPlatforms } from '.' | ||
|
||
describe('OthersPlatforms', () => { | ||
test('renders without crashing', () => { | ||
render(<OthersPlatforms />) | ||
expect(screen).not.toBeNull() | ||
}) | ||
|
||
test('contains the heading', () => { | ||
render(<OthersPlatforms />) | ||
const heading = screen.getByText(/Explore Mais Opções/i) | ||
expect(heading).toBeInTheDocument() | ||
}) | ||
|
||
test('contains the paragraph text', () => { | ||
render(<OthersPlatforms />) | ||
const paragraph = screen.getByText(/Se você ainda não encontrou seu pet/i) | ||
expect(paragraph).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import { PetCard } from '.' | ||
|
||
describe('PetCard', () => { | ||
const mockProps = { | ||
id: 1, | ||
imageSrc: 'testImageSrc', | ||
title: 'testTitle', | ||
description: 'testDescription', | ||
specie: 'testSpecie', | ||
size: 'testSize', | ||
color: 'testColor', | ||
} | ||
it('displays the correct title', () => { | ||
render(<PetCard {...mockProps} />) | ||
expect(screen.getByText(mockProps.title)).toBeInTheDocument() | ||
}) | ||
|
||
it('displays the correct description', () => { | ||
render(<PetCard {...mockProps} />) | ||
expect(screen.getByText(mockProps.description)).toBeInTheDocument() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import { Button } from './button' | ||
|
||
describe('Button', () => { | ||
it('renders correctly with default props', () => { | ||
render(<Button />) | ||
const button = screen.getByRole('button') | ||
expect(button).toBeInTheDocument() | ||
expect(button).toHaveClass( | ||
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50', | ||
) | ||
}) | ||
|
||
it('renders correctly with variant prop', () => { | ||
render(<Button variant="destructive" />) | ||
const button = screen.getByRole('button') | ||
expect(button).toHaveClass( | ||
'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90', | ||
) | ||
}) | ||
|
||
it('renders correctly with size prop', () => { | ||
render(<Button size="lg" />) | ||
const button = screen.getByRole('button') | ||
expect(button).toHaveClass('h-10 rounded-md px-8') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import { | ||
Dialog, | ||
DialogClose, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from './dialog' | ||
|
||
describe('Dialog Component', () => { | ||
it('renders without crashing', () => { | ||
render( | ||
<Dialog> | ||
<DialogTrigger>Open Dialog</DialogTrigger> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>Dialog Title</DialogTitle> | ||
<DialogClose>Close</DialogClose> | ||
</DialogHeader> | ||
<DialogDescription>Dialog Description</DialogDescription> | ||
<DialogFooter> | ||
<button>Cancel</button> | ||
<button>Save</button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog>, | ||
) | ||
|
||
expect(screen.findByRole('dialog')).toBeDefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { render } from '@testing-library/react' | ||
import { ImageWithLoader } from './image-with-loader' | ||
import '@testing-library/jest-dom' | ||
|
||
describe('ImageWithLoader', () => { | ||
it('renders without errors', () => { | ||
render(<ImageWithLoader src="test.jpg" alt="Test Image" />) | ||
}) | ||
|
||
it('renders with the correct alt text', () => { | ||
const altText = 'Test Image' | ||
const { getByAltText } = render( | ||
<ImageWithLoader src="test.jpg" alt={altText} />, | ||
) | ||
expect(getByAltText(altText)).toBeInTheDocument() | ||
}) | ||
|
||
it('applies the provided className', () => { | ||
const className = 'custom-class' | ||
const { container } = render( | ||
<ImageWithLoader src="test.jpg" alt="Test Image" className={className} />, | ||
) | ||
expect(container.firstChild).toHaveClass(className) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import React from 'react' | ||
import { MaskedInput } from './input-masked' | ||
|
||
describe('MaskedInput', () => { | ||
it('renders without errors', () => { | ||
render(<MaskedInput />) | ||
expect(screen.getByRole('textbox')).toBeInTheDocument() | ||
}) | ||
it('renders with custom class name', () => { | ||
render(<MaskedInput className="custom-input" />) | ||
expect(screen.getByRole('textbox')).toHaveClass('custom-input') | ||
}) | ||
it('forwards ref to the input element', () => { | ||
const ref = React.createRef<HTMLInputElement>() | ||
render(<MaskedInput ref={ref} />) | ||
expect(ref.current).toBeInstanceOf(HTMLInputElement) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import '@testing-library/jest-dom' | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
import React from 'react' | ||
import { Input } from './input' | ||
|
||
describe('Input', () => { | ||
test('renders without errors', () => { | ||
render(<Input />) | ||
expect(screen.getByRole('textbox')).toBeInTheDocument() | ||
}) | ||
|
||
test('renders with custom class name', () => { | ||
render(<Input className="custom-input" />) | ||
expect(screen.getByRole('textbox')).toHaveClass('custom-input') | ||
}) | ||
|
||
test('forwards ref to the input element', () => { | ||
const ref = React.createRef<HTMLInputElement>() | ||
render(<Input ref={ref} />) | ||
expect(ref.current).toBeInstanceOf(HTMLInputElement) | ||
}) | ||
|
||
test('triggers onChange event', () => { | ||
const handleChange = jest.fn() | ||
render(<Input onChange={handleChange} />) | ||
fireEvent.change(screen.getByRole('textbox'), { target: { value: 'test' } }) | ||
expect(handleChange).toHaveBeenCalledTimes(1) | ||
expect(handleChange).toHaveBeenCalledWith(expect.any(Object)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import '@testing-library/jest-dom' | ||
import { render, screen } from '@testing-library/react' | ||
import { Textarea } from './textarea' | ||
|
||
describe('Textarea', () => { | ||
test('renders without errors', () => { | ||
render(<Textarea />) | ||
const textareaElement = screen.getByRole('textbox') | ||
expect(textareaElement).toBeInTheDocument() | ||
}) | ||
|
||
test('renders with initial value', () => { | ||
const initialValue = 'Hello World' | ||
render(<Textarea value={initialValue} />) | ||
const textareaElement = screen.getByRole('textbox') as HTMLTextAreaElement | ||
expect(textareaElement.value).toBe(initialValue) | ||
}) | ||
test('renders with placeholder', () => { | ||
const placeholder = 'Enter your text' | ||
render(<Textarea placeholder={placeholder} />) | ||
const textareaElement = screen.getByRole('textbox') as HTMLTextAreaElement | ||
expect(textareaElement.placeholder).toBe(placeholder) | ||
}) | ||
|
||
test('renders with custom class', () => { | ||
const customClass = 'custom-textarea' | ||
render(<Textarea className={customClass} />) | ||
const textareaElement = screen.getByRole('textbox') | ||
expect(textareaElement).toHaveClass(customClass) | ||
}) | ||
}) |
Oops, something went wrong.