import React from 'react'; import { fireEvent } from '@testing-library/dom'; import { initialState, render, screen, testUnits, } from '../../../../setupTest'; import UnitNavigation from './UnitNavigation'; describe('Unit Navigation', () => { const mockData = { sequenceId: '1', unitId: '2', onClickPrevious: () => {}, onClickNext: () => {}, }; it('renders correctly without units', () => { const { asFragment } = render( {}} onClickNext={() => {}} />); expect(asFragment()).toMatchSnapshot(); }); it('handles the clicks', () => { const onClickPrevious = jest.fn(); const onClickNext = jest.fn(); render(); fireEvent.click(screen.getByRole('button', { name: /previous/i })); expect(onClickPrevious).toHaveBeenCalledTimes(1); fireEvent.click(screen.getByRole('button', { name: /next/i })); expect(onClickNext).toHaveBeenCalledTimes(1); }); it('should have the navigation buttons enabled for the non-corner unit in the sequence', () => { render(, { initialState }); screen.getAllByRole('button').forEach(button => { expect(button).toBeEnabled(); }); }); it('should have the "Previous" button disabled for the first unit in the sequence', () => { render(, { initialState }); expect(screen.getByRole('button', { name: /previous/i })).toBeDisabled(); expect(screen.getByRole('button', { name: /next/i })).toBeEnabled(); }); it('should display "learn.end.of.course" message instead of the "Next" button for the last unit in the sequence', () => { render( , { initialState }, ); expect(screen.getByRole('button', { name: /previous/i })).toBeEnabled(); expect(screen.queryByRole('button', { name: /next/i })).not.toBeInTheDocument(); expect(screen.getByText("You've reached the end of this course!")).toBeInTheDocument(); }); });