-
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 #64 from fga-eps-mds/163-aumentar-cobertura-de-testes
163 - Aumentando cobertura de testes
- Loading branch information
Showing
11 changed files
with
507 additions
and
72 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
src/components/action-buttons/delete-extensive-button/delete-button.spec.tsx
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/components/action-buttons/delete-extensive-button/delete-extensive-button.spec.tsx
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 { screen, render, fireEvent, act } from '@testing-library/react'; | ||
import { vi } from 'vitest'; | ||
import { DeleteExtensiveButton } from '.'; | ||
|
||
describe('DeleteExtensiveButton', () => { | ||
it('has the correct aria-label', () => { | ||
render(<DeleteExtensiveButton label="usuário" onClick={() => {}} />); | ||
expect(screen.getByText('Excluir usuário')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should be able to call DeleteExtensiveButton onClick function', async () => { | ||
const onClickMock = vi.fn(); | ||
render(<DeleteExtensiveButton label="usuário" onClick={onClickMock} />); | ||
|
||
const button = screen.getAllByText('Excluir').pop() as HTMLElement; | ||
await act(() => fireEvent.click(button)); | ||
|
||
expect(onClickMock).toHaveBeenCalled(); | ||
}); | ||
}); |
102 changes: 102 additions & 0 deletions
102
src/components/equipment-edit-form/equipment-edit-form.spec.tsx
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,102 @@ | ||
import { screen, render } from '@testing-library/react'; | ||
import { vi } from 'vitest'; | ||
import EquipmentEditForm from '.'; | ||
|
||
const EQUIPMENT_MOCK = { | ||
tippingNumber: 'tippingNumber', | ||
serialNumber: 'serialNumber', | ||
type: 'type', | ||
situacao: 'situacao', | ||
model: 'model', | ||
description: 'description', | ||
acquisitionDate: new Date(2000, 1, 1), | ||
screenSize: 'screenSize', | ||
power: 'power', | ||
screenType: 'screenType', | ||
processor: 'processor', | ||
storageType: 'storageType', | ||
storageAmount: 'storageAmount', | ||
brandName: 'brandName', | ||
acquisition: { name: 'name' }, | ||
unitId: 'unitId', | ||
ram_size: 'ram_size', | ||
estado: 'estado', | ||
}; | ||
|
||
describe('EquipmentEditForm', () => { | ||
it('should render correctly', () => { | ||
render( | ||
<EquipmentEditForm | ||
onClose={vi.fn()} | ||
equip={EQUIPMENT_MOCK} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
expect(screen.getByText('Cancelar')).toBeInTheDocument(); | ||
expect(screen.getByText('Editar')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render cpu fields', () => { | ||
const equipmentMock = { ...EQUIPMENT_MOCK, type: 'CPU' }; | ||
render( | ||
<EquipmentEditForm | ||
onClose={vi.fn()} | ||
equip={equipmentMock} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
expect(screen.getByLabelText('Qtd. Memória RAM (GB)')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Tipo de armazenamento')).toBeInTheDocument(); | ||
expect( | ||
screen.getByLabelText('Qtd. Armazenamento (GB)') | ||
).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Processador')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render monitor fields', () => { | ||
const equipmentMock = { ...EQUIPMENT_MOCK, type: 'Monitor' }; | ||
render( | ||
<EquipmentEditForm | ||
onClose={vi.fn()} | ||
equip={equipmentMock} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
expect(screen.getByLabelText('Tipo de monitor')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Tamanho do Monitor')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render estabilizador fields', () => { | ||
const equipmentMock = { ...EQUIPMENT_MOCK, type: 'Estabilizador' }; | ||
render( | ||
<EquipmentEditForm | ||
onClose={vi.fn()} | ||
equip={equipmentMock} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
expect(screen.getByLabelText('Potência (VA)')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render Nobreak fields', () => { | ||
const equipmentMock = { ...EQUIPMENT_MOCK, type: 'Nobreak' }; | ||
render( | ||
<EquipmentEditForm | ||
onClose={vi.fn()} | ||
equip={equipmentMock} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
expect(screen.getByLabelText('Potência (VA)')).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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { screen, render, act, fireEvent } from '@testing-library/react'; | ||
import { vi } from 'vitest'; | ||
import EquipmentForm from '.'; | ||
|
||
describe('EquipmentForm', () => { | ||
it('should render correctly', () => { | ||
render( | ||
<EquipmentForm | ||
onClose={vi.fn()} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
expect(screen.getByText('Cancelar')).toBeInTheDocument(); | ||
expect(screen.getByText('Confirmar')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render cpu fields', async () => { | ||
render( | ||
<EquipmentForm | ||
onClose={vi.fn()} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
const select = screen.getByLabelText('Tipo de equipamento'); | ||
await act(() => fireEvent.change(select, { target: { value: 'CPU' } })); | ||
|
||
expect(screen.getByLabelText('Qtd. Memória RAM (GB)')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Tipo de armazenamento')).toBeInTheDocument(); | ||
expect( | ||
screen.getByLabelText('Qtd. Armazenamento (GB)') | ||
).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Processador')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render monitor fields', async () => { | ||
render( | ||
<EquipmentForm | ||
onClose={vi.fn()} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
const select = screen.getByLabelText('Tipo de equipamento'); | ||
await act(() => fireEvent.change(select, { target: { value: 'Monitor' } })); | ||
|
||
expect(screen.getByLabelText('Tipo de monitor')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Tamanho do Monitor')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render estabilizador fields', async () => { | ||
render( | ||
<EquipmentForm | ||
onClose={vi.fn()} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
const select = screen.getByLabelText('Tipo de equipamento'); | ||
await act(() => | ||
fireEvent.change(select, { target: { value: 'Estabilizador' } }) | ||
); | ||
|
||
expect(screen.getByLabelText('Potência (VA)')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render Nobreak fields', async () => { | ||
render( | ||
<EquipmentForm | ||
onClose={vi.fn()} | ||
refreshRequest={false} | ||
setRefreshRequest={vi.fn()} | ||
/> | ||
); | ||
|
||
const select = screen.getByLabelText('Tipo de equipamento'); | ||
await act(() => fireEvent.change(select, { target: { value: 'Nobreak' } })); | ||
|
||
expect(screen.getByLabelText('Potência (VA)')).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
Oops, something went wrong.