|
| 1 | +import { screen } from '@testing-library/react'; |
| 2 | +import userEvent from '@testing-library/user-event'; |
| 3 | +import { renderWithIntl } from '@src/testUtils'; |
| 4 | +import GradingActionRow from '@src/grading/components/GradingActionRow'; |
| 5 | +import messages from '../messages'; |
| 6 | +import { useCourseInfo } from '@src/data/apiHook'; |
| 7 | +import { useGradingConfiguration } from '../data/apiHook'; |
| 8 | + |
| 9 | +jest.mock('react-router-dom', () => ({ |
| 10 | + ...jest.requireActual('react-router-dom'), |
| 11 | + useParams: () => ({ |
| 12 | + courseId: 'course-v1:edX+DemoX+Demo_Course', |
| 13 | + }), |
| 14 | +})); |
| 15 | + |
| 16 | +jest.mock('@src/data/apiHook', () => ({ |
| 17 | + useCourseInfo: jest.fn(), |
| 18 | +})); |
| 19 | + |
| 20 | +jest.mock('@src/grading/data/apiHook', () => ({ |
| 21 | + useGradingConfiguration: jest.fn(), |
| 22 | +})); |
| 23 | + |
| 24 | +describe('GradingActionRow', () => { |
| 25 | + beforeEach(() => { |
| 26 | + jest.clearAllMocks(); |
| 27 | + (useCourseInfo as jest.Mock).mockReturnValue({ data: { gradebookUrl: 'https://example.com/gradebook', studioGradingUrl: 'https://example.com/studio' } }); |
| 28 | + // TODO: Update this mock to use similar structure when API is ready, currently just returning random text to ensure component renders without error |
| 29 | + (useGradingConfiguration as jest.Mock).mockReturnValue({ data: 'Some random text' }); |
| 30 | + }); |
| 31 | + |
| 32 | + it('renders ActionRow with gradebook and configuration buttons', () => { |
| 33 | + renderWithIntl(<GradingActionRow />); |
| 34 | + expect(screen.getByRole('link', { name: messages.viewGradebook.defaultMessage })).toBeInTheDocument(); |
| 35 | + expect(screen.getByRole('button', { name: messages.configurationAlt.defaultMessage })).toBeInTheDocument(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('opens configuration menu when configuration button is clicked', async () => { |
| 39 | + renderWithIntl(<GradingActionRow />); |
| 40 | + const user = userEvent.setup(); |
| 41 | + await user.click(screen.getByRole('button', { name: messages.configurationAlt.defaultMessage })); |
| 42 | + expect(screen.getByText('View Grading Configuration')).toBeInTheDocument(); |
| 43 | + expect(screen.getByText('View Course Grading Settings')).toBeInTheDocument(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('opens and closes GradingConfigurationModal when menu item is clicked', async () => { |
| 47 | + renderWithIntl(<GradingActionRow />); |
| 48 | + const user = userEvent.setup(); |
| 49 | + await user.click(screen.getByRole('button', { name: messages.configurationAlt.defaultMessage })); |
| 50 | + const gradingConfigButton = screen.getByText('View Grading Configuration'); |
| 51 | + await user.click(gradingConfigButton); |
| 52 | + expect(screen.getByRole('dialog', { name: messages.gradingConfiguration.defaultMessage })).toBeInTheDocument(); |
| 53 | + |
| 54 | + // Close modal |
| 55 | + await user.click(screen.getAllByRole('button', { name: messages.close.defaultMessage })[0]); |
| 56 | + expect(screen.queryByRole('dialog', { name: messages.gradingConfiguration.defaultMessage })).not.toBeInTheDocument(); |
| 57 | + }); |
| 58 | +}); |
0 commit comments