forked from fga-eps-mds/2022-2-schedula-front
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #69 from fga-eps-mds/#143-issues-page-test-coverag…
…e-increase test: increase issues page test coverage
- Loading branch information
Showing
1 changed file
with
52 additions
and
23 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,4 +1,4 @@ | ||
import { render } from '@testing-library/react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { vi } from 'vitest'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
@@ -7,18 +7,24 @@ import { Issue } from '@/features/issues/types'; | |
|
||
import 'intersection-observer'; | ||
|
||
beforeAll(() => { | ||
beforeAll(async () => { | ||
vi.mock('@/features/issues/api/get-all-issues', () => ({ | ||
useGetAllIssues: vi.fn().mockReturnValue({ | ||
id: '1', | ||
requester: 'Mockerson', | ||
phone: '61988554474', | ||
city_id: '123', | ||
workstation_id: '123', | ||
problem_category_id: 'Category Mock', | ||
problem_types_ids: ['Type Mock'], | ||
date: new Date(), | ||
email: '[email protected]', | ||
data: [ | ||
{ | ||
id: '1', | ||
requester: 'Mockerson', | ||
phone: '61988554474', | ||
city_id: '123', | ||
workstation_id: '123', | ||
problem_category_id: 'Category Mock', | ||
problem_types_ids: ['Type Mock'], | ||
date: new Date(), | ||
email: '[email protected]', | ||
}, | ||
], | ||
isLoading: false, | ||
refetch: vi.fn(), | ||
}), | ||
})); | ||
}); | ||
|
@@ -39,35 +45,35 @@ describe('Issues page', () => { | |
expect(heading).toHaveTextContent('Atendimentos'); | ||
}); | ||
|
||
it('should display a list', async () => { | ||
const { findByRole } = render( | ||
it('should display a new issue button', async () => { | ||
const { queryByText } = render( | ||
<BrowserRouter> | ||
<QueryClientProvider client={queryClient}> | ||
<Chamados /> | ||
</QueryClientProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const list = await findByRole('list'); | ||
expect(list).toBeInTheDocument(); | ||
const button = await queryByText('Novo Atendimento'); | ||
if (button) { | ||
expect(button).toBeInTheDocument(); | ||
} | ||
}); | ||
|
||
it('should display a new issue button', async () => { | ||
const { queryByText } = render( | ||
it('should display a refresh button', async () => { | ||
const { findByRole } = render( | ||
<BrowserRouter> | ||
<QueryClientProvider client={queryClient}> | ||
<Chamados /> | ||
</QueryClientProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const button = await queryByText('Novo Atendimento'); | ||
if (button) { | ||
expect(button).toBeInTheDocument(); | ||
} | ||
const button = await findByRole('button', { name: 'Atualizar Dados' }); | ||
expect(button).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display a refresh button', async () => { | ||
it('should display an apply filter button', async () => { | ||
const { findByRole } = render( | ||
<BrowserRouter> | ||
<QueryClientProvider client={queryClient}> | ||
|
@@ -76,9 +82,32 @@ describe('Issues page', () => { | |
</BrowserRouter> | ||
); | ||
|
||
const button = await findByRole('button', { name: 'Atualizar Dados' }); | ||
const button = await findByRole('button', { name: 'Aplicar Filtro' }); | ||
expect(button).toBeInTheDocument(); | ||
}); | ||
|
||
it('applies date filter correctly', () => { | ||
const { getByPlaceholderText, getByText, container } = render( | ||
<BrowserRouter> | ||
<QueryClientProvider client={queryClient}> | ||
<Chamados /> | ||
</QueryClientProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const startDateInput = getByPlaceholderText('Data inicial'); | ||
const endDateInput = getByPlaceholderText('Data final'); | ||
|
||
fireEvent.change(startDateInput, { target: { value: '2021-08-01' } }); | ||
fireEvent.change(endDateInput, { target: { value: '2021-08-31' } }); | ||
|
||
const applyFilterButton = getByText('Aplicar Filtro'); | ||
fireEvent.click(applyFilterButton); | ||
|
||
const issueItems = container.querySelectorAll('.issue-item'); | ||
|
||
expect(issueItems.length).toBe(0); | ||
}); | ||
}); | ||
|
||
describe('sortIssues', () => { | ||
|