Skip to content

Commit

Permalink
Merge pull request #69 from fga-eps-mds/#143-issues-page-test-coverag…
Browse files Browse the repository at this point in the history
…e-increase

test: increase issues page test coverage
  • Loading branch information
IanFPFerreira authored Jul 9, 2023
2 parents 799f84f + 20b73fc commit 1fa427f
Showing 1 changed file with 52 additions and 23 deletions.
75 changes: 52 additions & 23 deletions src/pages/chamados/chamados.spec.tsx
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';
Expand All @@ -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(),
}),
}));
});
Expand All @@ -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}>
Expand All @@ -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', () => {
Expand Down

0 comments on commit 1fa427f

Please sign in to comment.