forked from devhatt/octopost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: usage of hook on testinho and update of tests
refactor devhatt#30
- Loading branch information
1 parent
ad5bdc6
commit 97ed079
Showing
5 changed files
with
49 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,37 @@ | ||
import { render } from '@testing-library/react'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
import Testinho from './Testinho'; | ||
|
||
test('renders Testinho with default name', () => { | ||
const { getByText } = render(<Testinho />); | ||
const linkElement = getByText(/Hello, World!/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
}); | ||
describe('testinhoComponent', () => { | ||
describe('when no props is passed', () => { | ||
it('render with de default value', () => { | ||
const { getByRole } = render(<Testinho />); | ||
const linkElement = getByRole('heading', { level: 1 }); | ||
expect(linkElement.textContent).toBe('Hello, World!'); | ||
}); | ||
}); | ||
|
||
describe('when props is passed', () => { | ||
it('renders with the provided prop', () => { | ||
const { getByRole } = render(<Testinho name="React" />); | ||
const linkElement = getByRole('heading', { level: 1 }); | ||
expect(linkElement.textContent).toBe('Hello, React!'); | ||
}); | ||
}); | ||
|
||
describe('when interact with the posts button', () => { | ||
it('sucessfully change value of posts', () => { | ||
const LABEL = 'Number of posts:'; | ||
const { getByRole } = render(<Testinho />); | ||
|
||
const postsLabel = screen.getByText(`${LABEL} 0`); | ||
expect(postsLabel.textContent).toBe(`${LABEL} 0`); | ||
|
||
const increaseButton = getByRole('button'); | ||
|
||
fireEvent.click(increaseButton); | ||
|
||
test('renders Testinho with provided name', () => { | ||
const { getByText } = render(<Testinho name="React" />); | ||
const linkElement = getByText(/Hello, React!/i); | ||
expect(linkElement).toBeInTheDocument(); | ||
expect(postsLabel.textContent).toBe(`${LABEL} 1`); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import React from 'react'; | ||
|
||
import { usePostsStore } from 'stores/usePostsStore'; | ||
|
||
const Testinho = ({ name = 'World' }) => { | ||
return <h1>Hello, {name}!</h1>; | ||
const posts = usePostsStore((state) => state.postsQuantity); | ||
|
||
const increaseValue = usePostsStore((state) => state.increase); | ||
|
||
return ( | ||
<> | ||
<button onClick={() => increaseValue(1)}>Change value of posts</button> | ||
<p>Number of posts: {posts}</p> | ||
<h1>Hello, {name}!</h1> | ||
</> | ||
); | ||
}; | ||
|
||
export default Testinho; |
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
File renamed without changes.
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