-
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.
Merge pull request #16 from fonteeboa/fix-test
sonar: adicionando exportacao para sonar
- Loading branch information
Showing
16 changed files
with
337 additions
and
1 deletion.
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,5 @@ | ||
sonar.projectKey=fonteeboa_FBLibrary | ||
sonar.organization=fonteeboa | ||
sonar.sources=src | ||
sonar.tests=src | ||
sonar.javascript.lcov.reportPaths=coverage/lcov.info |
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,10 @@ | ||
export const onClickMock = jest.fn(); | ||
|
||
export const buttonProps = { | ||
label: 'Click me', | ||
type: 'primary', | ||
size: 'large', | ||
styles: 'custom-style', | ||
onClick: onClickMock, | ||
className: 'custom-class', | ||
}; |
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,33 @@ | ||
// Mock das colunas e dados de exemplo | ||
export const columns = [ | ||
{ | ||
title: 'Nome', | ||
dataIndex: 'name', | ||
key: 'name', | ||
}, | ||
{ | ||
title: 'Idade', | ||
dataIndex: 'age', | ||
key: 'age', | ||
}, | ||
]; | ||
|
||
export const dataSource = [ | ||
{ | ||
key: '1', | ||
name: 'Alice', | ||
age: 30, | ||
}, | ||
{ | ||
key: '2', | ||
name: 'Bob', | ||
age: 25, | ||
}, | ||
]; | ||
|
||
export const bulkAction = [ | ||
{ | ||
label: 'Excluir Selecionados', | ||
action: jest.fn(), // Mock da ação em lote | ||
}, | ||
]; |
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,10 @@ | ||
export const inputFieldProps = { | ||
name: 'email', | ||
type: 'email', | ||
icon: true, | ||
label: 'Email', | ||
onChange: jest.fn(), | ||
styles: { borderColor: 'red' }, | ||
required: true, | ||
className: 'custom-class', | ||
}; |
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,24 @@ | ||
|
||
import matchMedia from 'match-media-mock'; | ||
|
||
// Mock the window.matchMedia function | ||
const originalMatchMedia = window.matchMedia; | ||
const mockMatchMedia = matchMedia.create(); | ||
|
||
beforeAll(() => { | ||
window.matchMedia = mockMatchMedia; | ||
}); | ||
|
||
afterAll(() => { | ||
window.matchMedia = originalMatchMedia; | ||
}); | ||
|
||
export const setMatchMediaMock = () => { | ||
beforeAll(() => { | ||
window.matchMedia = mockMatchMedia; | ||
}); | ||
|
||
afterAll(() => { | ||
window.matchMedia = originalMatchMedia; | ||
}); | ||
}; |
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,9 @@ | ||
import React from 'react'; | ||
|
||
export const renderOptionsApiName = () => { | ||
return ( | ||
<option key={0} value={1}> | ||
{'name'} | ||
</option> | ||
) | ||
} |
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,12 @@ | ||
export const selectComponentProps = { | ||
name: 'mySelect', | ||
value: 'option2', | ||
label: 'Select an option', | ||
onChange: jest.fn(), | ||
options: [ | ||
{ label: 'Option 1', value: 'option1' }, | ||
{ label: 'Option 2', value: 'option2' }, | ||
{ label: 'Option 3', value: 'option3' }, | ||
], | ||
className: 'custom-class', | ||
}; |
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,18 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { BulkActionsDropdown } from '../../components'; | ||
import '@testing-library/jest-dom'; | ||
|
||
const makeRender = (actions = []) => { | ||
render( | ||
<BulkActionsDropdown actions={actions} /> | ||
); | ||
} | ||
|
||
describe('BulkActionsDropdown', () => { | ||
// Teste para verificar se o componente renderiza corretamente | ||
it('renders correctly', () => { | ||
makeRender() | ||
expect(screen.getByRole('button')).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,14 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import {Button} from '../../components'; | ||
import { buttonProps, onClickMock } from '../mock/button'; | ||
|
||
test('Renderiza o componente Button corretamente', () => { | ||
const { getByText } = render(<Button {...buttonProps} />); | ||
// Verifique se o componente Button foi renderizado com os valores corretos | ||
expect(getByText('Click me')).toBeInTheDocument(); | ||
|
||
// Simule um clique no botão e verifique se o manipulador de clique é chamado | ||
fireEvent.click(getByText('Click me')); | ||
expect(onClickMock).toHaveBeenCalledTimes(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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { Grid } from '../../components'; | ||
import '../../i18n'; | ||
import { dataSource, columns, bulkAction } from '../mock/customTable'; | ||
import { setMatchMediaMock } from '../mock/matchMedia'; | ||
|
||
setMatchMediaMock(); | ||
|
||
test('Renderiza o componente CustomTable corretamente', () => { | ||
|
||
render( | ||
<Grid | ||
pageTitle="Tabela de Usuários" | ||
dataSource={dataSource} | ||
columns={columns} | ||
bulkAction={bulkAction} | ||
/> | ||
); | ||
|
||
// Verifique a renderização do título da tabela | ||
expect(screen.getByText('Tabela de Usuários')).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,13 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import {InputField} from '../../components'; | ||
import { inputFieldProps } from '../mock/inputField'; | ||
|
||
test('Renderiza o componente InputField corretamente', () => { | ||
const { getByTestId, getByText } = render(<InputField {...inputFieldProps} />); | ||
|
||
// Verifique se o componente InputField foi renderizado corretamente | ||
expect(getByText('Email')).toBeInTheDocument(); | ||
expect(getByTestId('dataTestId-' + inputFieldProps.name)).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,79 @@ | ||
import React from 'react'; | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import { renderfields } from '../../utils/renderField'; // Atualize com o caminho correto | ||
import { setMatchMediaMock } from '../mock/matchMedia'; | ||
|
||
import { renderOptionsApiName } from '../mock/renderField'; | ||
|
||
setMatchMediaMock(); | ||
|
||
// Mocks para as funções e propriedades necessárias | ||
const mockSetFieldValues = jest.fn(); | ||
const formInstance = { getFieldValue: jest.fn() }; | ||
|
||
|
||
// Exemplo de teste para o campo select | ||
describe('renderfields function', () => { | ||
it('renders input fields correctly', async () => { | ||
const field1 = { label: 'common.name', name: 'Name', rules: [{ required: true, message:"common.required.field" }] } | ||
const field2 = { label: 'common.test', name: 'Test', rules: [{ required: true, message:"common.required.field" }] } | ||
const fields = [field1, field2] | ||
const { getByTestId } = render( <div> {fields.map((field) => renderfields(field, 0, formInstance, mockSetFieldValues))} </div> ); | ||
const inputField1 = getByTestId(`dataTestId${field1.name}`); | ||
expect(inputField1).toBeInTheDocument(); | ||
const inputField2 = getByTestId(`dataTestId${field2.name}`); | ||
expect(inputField2).toBeInTheDocument(); | ||
fireEvent.change(inputField1, { target: { value: "1" } }); | ||
expect(inputField1.value).toBe("1"); | ||
fireEvent.change(inputField2, { target: { value: "2" } }); | ||
expect(inputField2.value).toBe("2"); | ||
}); | ||
|
||
it('renders inputs doublelines fields correctly', async () => { | ||
const fields = [ | ||
{ label: 'ID', name: 'ID', type: 'hidden' }, | ||
{ name: "doublelines", | ||
doublelines: [ | ||
{ label: 'common.name', name: 'ApiID', type: 'select', optionsFunction: renderOptionsApiName }, | ||
{ label: 'common.key', name: 'ApiKey' }, | ||
] | ||
}, | ||
]; | ||
const { getByTestId } = render( <div> {fields.map((field) => renderfields(field, 0, formInstance, mockSetFieldValues))} </div> ); | ||
const inputField1 = getByTestId(`dataTestIdApiID`); | ||
expect(inputField1).toBeInTheDocument(); | ||
const inputField2 = getByTestId(`dataTestIdApiKey`); | ||
expect(inputField2).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders select fields correctly', async () => { | ||
const field = { label: 'common.select', type: 'select', name: 'select', rules: [{ required: true, message:"common.required.field" }] } | ||
const { getByTestId } = render( <div> {renderfields(field, 0, formInstance, mockSetFieldValues)} </div> ); | ||
const selectField = getByTestId(`dataTestId${field.name}`); | ||
expect(selectField).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders datePicker fields correctly', async () => { | ||
const field = { label: 'common.datePicker', type: 'datePicker', name: 'datePicker', rules: [{ required: true, message:"common.required.field" }] } | ||
const { getByTestId } = render( <div> {renderfields(field, 0, formInstance, mockSetFieldValues)} </div> ); | ||
const selectField = getByTestId(`dataTestId-${field.name}`); | ||
expect(selectField).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders slider fields correctly', async () => { | ||
const field = { label: 'common.slider', type: 'slider', name: 'slider', rules: [{ required: true, message:"common.required.field" }] } | ||
const { getByTestId } = render( <div> {renderfields(field, 0, formInstance, mockSetFieldValues)} </div> ); | ||
const sliderField = getByTestId(`dataTestId${field.name}`); | ||
expect(sliderField).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders number fields correctly', async () => { | ||
const field = { label: 'common.number', type: 'number', name: 'number', required: true } | ||
const { getByTestId } = render( <div> {renderfields(field, 0, formInstance, mockSetFieldValues)} </div> ); | ||
const selectField = getByTestId(`dataTestId${field.name}`); | ||
expect(selectField).toBeInTheDocument(); | ||
fireEvent.change(selectField, { target: { value: "11" } }); | ||
expect(selectField.value).toBe("11"); | ||
}); | ||
|
||
}); |
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,11 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import {Select} from '../../components'; | ||
import { selectComponentProps } from '../mock/selectComponent'; | ||
|
||
test('Renderiza o componente SelectComponent corretamente', () => { | ||
render(<Select {...selectComponentProps} />); | ||
|
||
// Verifique se o componente SelectComponent foi renderizado corretamente | ||
expect(screen.getByText('Select an option')).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,55 @@ | ||
import { validFields } from './../../helpers/validFields'; // Atualize o caminho conforme necessário | ||
import moment from 'moment'; | ||
|
||
describe('validFields', () => { | ||
// Teste para 'date' | ||
it('validates date correctly', () => { | ||
const validDate = '2021-01-01'; | ||
expect(validFields(validDate, 'date')).toEqual(moment(validDate)); | ||
|
||
const invalidDate = 'invalid-date'; | ||
expect(validFields(invalidDate, 'date')).toBe(false); | ||
}); | ||
|
||
// Teste para 'string' | ||
it('validates string correctly', () => { | ||
expect(validFields('test string', 'string')).toBe('test string'); | ||
expect(validFields(123, 'string')).toBe(false); | ||
}); | ||
|
||
// Teste para 'number' | ||
it('validates number correctly', () => { | ||
expect(validFields(123, 'number')).toBe(123); | ||
expect(validFields('not a number', 'number')).toBe(false); | ||
}); | ||
|
||
// Teste para 'boolean' | ||
it('validates boolean correctly', () => { | ||
expect(validFields(true, 'boolean')).toBe(true); | ||
expect(validFields('not a boolean', 'boolean')).toBe(false); | ||
}); | ||
|
||
// Teste para 'array' | ||
it('validates array correctly', () => { | ||
expect(validFields([1, 2, 3], 'array')).toEqual([1, 2, 3]); | ||
expect(validFields('not an array', 'array')).toBe(false); | ||
}); | ||
|
||
// Teste para 'object' | ||
it('validates object correctly', () => { | ||
expect(validFields({ key: 'value' }, 'object')).toEqual({ key: 'value' }); | ||
expect(validFields('not an object', 'object')).toBe(false); | ||
}); | ||
|
||
// Teste para 'email' | ||
it('validates email correctly', () => { | ||
expect(validFields('test@example.com', 'email')).toBe('test@example.com'); | ||
expect(validFields('invalidemail', 'email')).toBe(false); | ||
}); | ||
|
||
// Teste para o caso padrão | ||
it('returns the value for unknown types', () => { | ||
const unknownTypeValue = 'unknown type value'; | ||
expect(validFields(unknownTypeValue, 'unknown')).toBe(unknownTypeValue); | ||
}); | ||
}); |
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 React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { WarningPageScreenSize } from '../../components'; | ||
|
||
// Mock the useTranslation hook | ||
jest.mock('react-i18next', () => ({ | ||
useTranslation: () => ({ | ||
t: jest.fn().mockImplementation((key) => key), | ||
}), | ||
})); | ||
|
||
describe('WarningPageScreenSize', () => { | ||
it('renders correctly', () => { | ||
const { getByText } = render(<WarningPageScreenSize />); | ||
|
||
// Check if the component renders the title and subtitle | ||
expect(getByText('warningPage.title')).toBeInTheDocument(); | ||
expect(getByText('warningPage.subTitle')).toBeInTheDocument(); | ||
}); | ||
}); |