|
| 1 | +import { render, fireEvent } from '@testing-library/react'; |
| 2 | +import { Feedback } from './index'; |
| 3 | + |
| 4 | +describe('Feedback', () => { |
| 5 | + it('renders correctly', () => { |
| 6 | + const handleDiscardClick = jest.fn(); |
| 7 | + const handleEndorseClick = jest.fn(); |
| 8 | + const { getByTestId } = render( |
| 9 | + <Feedback handleDiscardClick={handleDiscardClick} handleEndorseClick={handleEndorseClick} />, |
| 10 | + ); |
| 11 | + const discardButton = getByTestId('discard-button'); |
| 12 | + const endorseButton = getByTestId('endorse-button'); |
| 13 | + expect(discardButton).toBeInTheDocument(); |
| 14 | + expect(endorseButton).toBeInTheDocument(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('calls handleDiscardClick on Discard button click', () => { |
| 18 | + const handleDiscardClick = jest.fn(); |
| 19 | + const handleEndorseClick = jest.fn(); |
| 20 | + const { getByTestId } = render( |
| 21 | + <Feedback handleDiscardClick={handleDiscardClick} handleEndorseClick={handleEndorseClick} />, |
| 22 | + ); |
| 23 | + const discardButton = getByTestId('discard-button'); |
| 24 | + fireEvent.click(discardButton); |
| 25 | + expect(handleDiscardClick).toHaveBeenCalledTimes(1); |
| 26 | + expect(handleEndorseClick).not.toHaveBeenCalled(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('calls handleEndorseClick on Endorse button click', () => { |
| 30 | + const handleDiscardClick = jest.fn(); |
| 31 | + const handleEndorseClick = jest.fn(); |
| 32 | + const { getByTestId } = render( |
| 33 | + <Feedback handleDiscardClick={handleDiscardClick} handleEndorseClick={handleEndorseClick} />, |
| 34 | + ); |
| 35 | + const endorseButton = getByTestId('endorse-button'); |
| 36 | + fireEvent.click(endorseButton); |
| 37 | + expect(handleEndorseClick).toHaveBeenCalledTimes(1); |
| 38 | + expect(handleDiscardClick).not.toHaveBeenCalled(); |
| 39 | + }); |
| 40 | +}); |
0 commit comments