Skip to content

Commit

Permalink
test: fireEvent.press(dropdownButton)
Browse files Browse the repository at this point in the history
  • Loading branch information
Natyrodrigues committed Sep 19, 2024
1 parent 6ae3fd0 commit c42c39a
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions src/app/__tests__/FiltroDropdown.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,27 @@ describe('FiltroDropdown Component', () => {
const { rerender } = render(<FiltroDropdown filtro={null} setFiltro={() => {}} />);
const dropdownButton = screen.getByText('Filtro');

// Simulate button measuring
fireEvent.press(dropdownButton); // Open dropdown
rerender(<FiltroDropdown filtro={null} setFiltro={() => {}} />);
// Ensure dimensions are set
// This test is more about ensuring the effect runs, not a direct assertion
});

it('should correctly handle selection toggling', async () => {
const mockSetFiltro = jest.fn();

// Renderiza o componente
render(<FiltroDropdown filtro={null} setFiltro={mockSetFiltro} />);

// Abre o dropdown
const dropdownButton = screen.getByText('Filtro');
fireEvent.press(dropdownButton);

// Seleciona uma opção
const optionButton = screen.getByText('Alimentação');
fireEvent.press(optionButton);

// Verifica se a função setFiltro foi chamada com o valor correto
expect(mockSetFiltro).toHaveBeenCalledWith('Alimentação');

// Verifica se o item selecionado está visível no botão do dropdown
expect(screen.getByText('Alimentação')).toBeTruthy();

// Adicionalmente, pode-se verificar se o item da lista ainda está visível
// (isso é opcional e depende do comportamento desejado)
await waitFor(() => {
expect(screen.queryByText('Alimentação')).toBeTruthy();
});
});
});
});

0 comments on commit c42c39a

Please sign in to comment.