generated from gabrielduete/frontend-template-nextjs
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #54 from gabrielduete/feat/resolve-todo-tests
feat; resolve todo tests
- Loading branch information
Showing
15 changed files
with
211 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import fetchMock from 'jest-fetch-mock' | ||
|
||
fetchMock.enableMocks() |
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,28 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react' | ||
|
||
import Home from './index.page' | ||
|
||
describe('<Home />', () => { | ||
beforeAll(() => { | ||
window.Element.prototype.animate = jest.fn() | ||
}) | ||
|
||
it('should render the title and explore link', () => { | ||
render(<Home />) | ||
|
||
expect(screen.getAllByText('sandevistan')[0]).toBeInTheDocument() | ||
expect(screen.getByText('explore')).toBeInTheDocument() | ||
}) | ||
|
||
it('should navigate to the about page when explore link is clicked', () => { | ||
render(<Home />) | ||
window.open = jest.fn() | ||
|
||
const exploreLink = screen.getByText('explore') | ||
|
||
fireEvent.click(exploreLink) | ||
|
||
expect(window.open).toHaveBeenCalledTimes(1) | ||
expect(window.open).toHaveBeenCalledWith('/about', '_self', 'noreferrer') | ||
}) | ||
}) |
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
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 |
---|---|---|
@@ -1,5 +1,15 @@ | ||
describe('<MobileNavBar />', () => { | ||
it.todo('render texts correctly') | ||
import { render, screen } from '@testing-library/react' | ||
import { pagesMock } from '~/src/mocks/pagesMock' | ||
|
||
it.todo('toggles the NavBar when BackIcon is clicked') | ||
import DesktopNavBar from '.' | ||
|
||
describe('<DesktopNavBar />', () => { | ||
beforeEach(() => { | ||
render(<DesktopNavBar pages={pagesMock} />) | ||
}) | ||
|
||
it('render texts correctly', () => { | ||
expect(screen.getByText('Git e Versionamento')).toBeInTheDocument() | ||
expect(screen.getByText('My list git commands')).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
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,5 +1,15 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { pagesMock } from '~/src/mocks/pagesMock' | ||
|
||
import MobileNavBar from '.' | ||
|
||
describe('<MobileNavBar />', () => { | ||
it.todo('render texts correctly') | ||
beforeEach(() => { | ||
render(<MobileNavBar pages={pagesMock} />) | ||
}) | ||
|
||
it.todo('toggles the NavBar when BackIcon is clicked') | ||
it('render texts correctly', () => { | ||
expect(screen.getByText('Git e Versionamento')).toBeInTheDocument() | ||
expect(screen.getByText('My list git commands')).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
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,53 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { render, screen, waitFor } from '@testing-library/react' | ||
import fetchMock from 'jest-fetch-mock' | ||
|
||
import Layout from '.' | ||
import { PagesStoregedProvider } from '../contexts/ContextPages' | ||
|
||
describe('<Layout />', () => { | ||
it('should render children Layout correctly', () => { | ||
const id = 'layout' | ||
|
||
it('should render children and components correctly', () => { | ||
render(<Layout>Layout</Layout>) | ||
|
||
const children = screen.getByText('Layout') | ||
|
||
expect(children).toBeInTheDocument() | ||
expect(screen.getByTestId(`${id}__header`)).toBeInTheDocument() | ||
expect(screen.queryByTestId(`${id}__navbar`)).not.toBeInTheDocument() | ||
expect(screen.getByTestId(`${id}__footer`)).toBeInTheDocument() | ||
}) | ||
|
||
it('should render loading case correctly', async () => { | ||
fetchMock.mockResponse( | ||
() => | ||
new Promise(() => { | ||
// @NOTE: this is a promise that never resolves, to mock loading case | ||
}) | ||
) | ||
|
||
render( | ||
<PagesStoregedProvider> | ||
<Layout>Layout</Layout> | ||
</PagesStoregedProvider> | ||
) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId(`${id}__loader`)).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
it.todo('should render Header, Footer and NavBar components correctly') | ||
it('should render error case correctly', async () => { | ||
fetchMock.mockReject(new Error('error bip bop')) | ||
|
||
render( | ||
<PagesStoregedProvider> | ||
<Layout>Layout</Layout> | ||
</PagesStoregedProvider> | ||
) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByTestId('error-case__id')).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,52 @@ | ||
export const pagesMock = [ | ||
{ | ||
object: 'block', | ||
id: '1', | ||
parent: { | ||
type: 'page_id', | ||
page_id: '1', | ||
}, | ||
created_time: '2023-11-14T13:54:00.000Z', | ||
last_edited_time: '2024-07-17T01:18:00.000Z', | ||
created_by: { | ||
object: 'user', | ||
id: '1234', | ||
}, | ||
last_edited_by: { | ||
object: 'user', | ||
id: '1234', | ||
}, | ||
has_children: true, | ||
archived: false, | ||
in_trash: false, | ||
type: 'child_page', | ||
child_page: { | ||
title: 'Git e Versionamento', | ||
}, | ||
}, | ||
{ | ||
object: 'block', | ||
id: '2', | ||
parent: { | ||
type: 'page_id', | ||
page_id: '2', | ||
}, | ||
created_time: '2023-11-15T04:37:00.000Z', | ||
last_edited_time: '2024-07-17T01:18:00.000Z', | ||
created_by: { | ||
object: 'user', | ||
id: '1234', | ||
}, | ||
last_edited_by: { | ||
object: 'user', | ||
id: '1234', | ||
}, | ||
has_children: true, | ||
archived: false, | ||
in_trash: false, | ||
type: 'child_page', | ||
child_page: { | ||
title: 'My list git commands', | ||
}, | ||
}, | ||
] |
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