diff --git a/src/components/baseComponents/inputField/index.tsx b/src/components/baseComponents/inputField/index.tsx index 918744b..c96e6f6 100644 --- a/src/components/baseComponents/inputField/index.tsx +++ b/src/components/baseComponents/inputField/index.tsx @@ -26,18 +26,18 @@ export const InputField: React.FC = ({ name, type, icon, label, onC * * @param {any} type - The type of icon to retrieve. * @return {any} The corresponding icon component. - */ + */ const getIcon = (type: any) => { let icons: any; switch (type) { case 'email': - icons = + icons = break; case 'password': - icons = + icons = break; case 'text': - icons = + icons = break; default: icons = ""; diff --git a/src/components/index.ts b/src/components/index.ts index 92ce976..e41b6af 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,4 +1,3 @@ - // Exportando componentes base e seus tipos, se houver export { BulkActionsDropdown, diff --git a/src/components/layout/sidebar/index.tsx b/src/components/layout/sidebar/index.tsx index db3039a..b443d47 100644 --- a/src/components/layout/sidebar/index.tsx +++ b/src/components/layout/sidebar/index.tsx @@ -20,19 +20,19 @@ function renderSubMenu(subMenu: SubMenuItem[]) { if (subSubMenu && subSubMenu.length > 0) { return ( - + {renderSubMenu(subSubMenu)} ); } else if (route) { return ( - + {external ? { label } : linkComponent} ); } else { return ( - + {label} ); @@ -46,6 +46,7 @@ function renderMenuItem(item: MenuItem, index: number) { return ( : null}> + : null} data-testid={index + '-' + item.label}> {item.label} ); diff --git a/src/test/mock/bulkActions.js b/src/test/mock/bulkActions.js new file mode 100644 index 0000000..510cc05 --- /dev/null +++ b/src/test/mock/bulkActions.js @@ -0,0 +1,4 @@ +export const mockActions = [ + { name: 'Action 1', handler: jest.fn(), activeAction: true }, + { name: 'Dangerous Action', handler: jest.fn(), type: 'danger', confirmMessage: 'Are you sure?', activeAction: true } + ]; \ No newline at end of file diff --git a/src/test/mock/customTable.js b/src/test/mock/grid.js similarity index 85% rename from src/test/mock/customTable.js rename to src/test/mock/grid.js index d4dee56..3112aee 100644 --- a/src/test/mock/customTable.js +++ b/src/test/mock/grid.js @@ -1,3 +1,6 @@ +export const mockDeleteAction = jest.fn(); +export const mockOpenModalAction = jest.fn(); + // Mock das colunas e dados de exemplo export const columns = [ { diff --git a/src/test/mock/inputField.js b/src/test/mock/inputField.js deleted file mode 100644 index ad7203e..0000000 --- a/src/test/mock/inputField.js +++ /dev/null @@ -1,10 +0,0 @@ -export const inputFieldProps = { - name: 'email', - type: 'email', - icon: true, - label: 'Email', - onChange: jest.fn(), - styles: { borderColor: 'red' }, - required: true, - className: 'custom-class', - }; \ No newline at end of file diff --git a/src/test/mock/modal.js b/src/test/mock/modal.js new file mode 100644 index 0000000..b1d6c1d --- /dev/null +++ b/src/test/mock/modal.js @@ -0,0 +1,31 @@ +export const mockFieldsDoubleLines = [ + { label: 'ID', name: 'ID', type: 'hidden' }, + { name: "doublelines", + doublelines: [ + { label: 'common.name', name: 'name' }, + { label: 'common.key', name: 'key' }, + ] + }, +]; + +export const mockFields = [ + { label: 'common.name2', name: 'Name2' }, +]; + +export const mockCloseModal = jest.fn(); + +export const mockOnSave = jest.fn(); + +export const tableContentsData = [ + { + fields: mockFieldsDoubleLines, + contentLabel: 'Tab 1 Content', + name: 'Tab 1', + }, + { + fields: mockFields, + contentLabel: 'Tab 2 Content', + name: 'Tab 2', + }, + // Pode adicionar mais elementos de acordo com a estrutura definida +]; diff --git a/src/test/src/Modal.test.js b/src/test/src/Modal.test.js new file mode 100644 index 0000000..3258732 --- /dev/null +++ b/src/test/src/Modal.test.js @@ -0,0 +1,51 @@ +import React from 'react'; +import { render, fireEvent, screen, waitFor} from '@testing-library/react'; +import '@testing-library/jest-dom'; +import Modal from 'react-modal'; +import { ModalFormHandler } from '../../components/baseLayouts/modals/modalFormHandler'; +import { mockCloseModal, mockOnSave, mockFields, mockFieldsDoubleLines } from '../mock/modal'; +import { setMatchMediaMock } from '../mock/matchMedia'; + +setMatchMediaMock(); +Modal.setAppElement('*'); + +const makeRender = (fields) => { + render( + + ); +} + +describe('Modal render', () => { + + it('deve renderizar o modal mockFields', () => { + makeRender(mockFields); + expect(screen.getByText('common.name2')).toBeInTheDocument(); + expect(screen.getByText('common.cancel')).toBeInTheDocument(); + expect(screen.getByText('common.save')).toBeInTheDocument(); + }); + + it('deve renderizar o modal mockFieldsDoubleLines', () => { + makeRender(mockFieldsDoubleLines); + expect(screen.getByText('common.name')).toBeInTheDocument(); + expect(screen.getByText('common.key')).toBeInTheDocument(); + expect(screen.getByText('common.cancel')).toBeInTheDocument(); + expect(screen.getByText('common.save')).toBeInTheDocument(); + }); + +}); + +describe('Modal functions', () => { + + it('deve chamar closeModal ao clicar no botão cancelar', () => { + makeRender(mockFields); + fireEvent.click(screen.getByText('common.cancel')); + expect(mockCloseModal).toHaveBeenCalled(); + }); + +}) \ No newline at end of file diff --git a/src/test/src/bulkActionsDropdown.test.js b/src/test/src/bulkActionsDropdown.test.js index f26ad3e..afac10c 100644 --- a/src/test/src/bulkActionsDropdown.test.js +++ b/src/test/src/bulkActionsDropdown.test.js @@ -1,18 +1,53 @@ import React from 'react'; -import { render, screen } from '@testing-library/react'; -import { BulkActionsDropdown } from '../../components'; +import { render, fireEvent, screen } from '@testing-library/react'; import '@testing-library/jest-dom'; +import { BulkActionsDropdown } from '../../components'; +import { Menu, Popconfirm } from 'antd'; +import { mockActions } from '../mock/bulkActions'; -const makeRender = (actions = []) => { - render( - - ); +const makeRender = (actions = []) => { + render(); } describe('BulkActionsDropdown', () => { - // Teste para verificar se o componente renderiza corretamente - it('renders correctly', () => { + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('deve renderizar o botao', () => { makeRender() expect(screen.getByRole('button')).toBeInTheDocument(); }); + + it('deve renderizar e abrir o menu dropdown', () => { + render(); + + const button = screen.getByRole('button'); + fireEvent.click(button); + + expect(screen.getByText('Action 1')).toBeInTheDocument(); + expect(screen.getByText('Dangerous Action')).toBeInTheDocument(); + }); + + it('deve chamar a ação do handler ao clicar em um item do menu', () => { + render(); + + fireEvent.click(screen.getByRole('button')); + fireEvent.click(screen.getByText('Action 1')); + + expect(mockActions[0].handler).toHaveBeenCalled(); + }); + + it('deve exibir o popconfirm e chamar o handler para ação perigosa', () => { + render(); + + fireEvent.click(screen.getByRole('button')); + fireEvent.click(screen.getByText('Dangerous Action')); + + const popconfirmYesButton = screen.getByText('common.ok'); + fireEvent.click(popconfirmYesButton); + + expect(mockActions[1].handler).toHaveBeenCalled(); + }); }); diff --git a/src/test/src/button.test.js b/src/test/src/button.test.js index ec37823..bf8a054 100644 --- a/src/test/src/button.test.js +++ b/src/test/src/button.test.js @@ -3,12 +3,14 @@ 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(