|
| 1 | +import { MathJaxContext } from 'better-react-mathjax'; |
1 | 2 | import { render, screen } from '@testing-library/react'; |
2 | 3 | import { fileUploadResponseOptions } from 'data/services/lms/constants'; |
3 | 4 | import { selectors } from 'data/redux'; |
4 | 5 | import { ResponseDisplay, mapStateToProps } from '.'; |
5 | 6 |
|
| 7 | +jest.mock('better-react-mathjax', () => ({ |
| 8 | + MathJax: ({ children }) => <div data-testid="mathjax">{children}</div>, |
| 9 | + MathJaxContext: ({ children }) => <div>{children}</div>, |
| 10 | +})); |
| 11 | + |
6 | 12 | jest.mock('data/redux', () => ({ |
7 | 13 | selectors: { |
8 | 14 | grading: { |
@@ -68,41 +74,65 @@ describe('ResponseDisplay', () => { |
68 | 74 |
|
69 | 75 | describe('behavior', () => { |
70 | 76 | it('renders response display container', () => { |
71 | | - const { container } = render(<ResponseDisplay {...defaultProps} />); |
| 77 | + const { container } = render( |
| 78 | + <MathJaxContext> |
| 79 | + <ResponseDisplay {...defaultProps} /> |
| 80 | + </MathJaxContext>, |
| 81 | + ); |
72 | 82 | const responseDisplay = container.querySelector('.response-display'); |
73 | 83 | expect(responseDisplay).toBeInTheDocument(); |
74 | 84 | }); |
75 | 85 |
|
76 | 86 | it('displays text content in cards', () => { |
77 | | - const { container } = render(<ResponseDisplay {...defaultProps} />); |
| 87 | + const { container } = render( |
| 88 | + <MathJaxContext> |
| 89 | + <ResponseDisplay {...defaultProps} /> |
| 90 | + </MathJaxContext>, |
| 91 | + ); |
78 | 92 | const textContents = container.querySelectorAll('.response-display-text-content'); |
79 | 93 | expect(textContents).toHaveLength(defaultProps.response.text.length); |
80 | 94 | expect(textContents[0]).toHaveTextContent('some text response here'); |
81 | 95 | expect(textContents[1]).toHaveTextContent('another text response'); |
82 | 96 | }); |
83 | 97 |
|
84 | 98 | it('displays submission files when file upload is allowed', () => { |
85 | | - render(<ResponseDisplay {...defaultProps} />); |
| 99 | + render( |
| 100 | + <MathJaxContext> |
| 101 | + <ResponseDisplay {...defaultProps} /> |
| 102 | + </MathJaxContext>, |
| 103 | + ); |
86 | 104 | const submissionFiles = screen.getByTestId('submission-files'); |
87 | 105 | expect(submissionFiles).toBeInTheDocument(); |
88 | 106 | expect(submissionFiles).toHaveTextContent('Files: 2'); |
89 | 107 | }); |
90 | 108 |
|
91 | 109 | it('displays preview display when file upload is allowed', () => { |
92 | | - render(<ResponseDisplay {...defaultProps} />); |
| 110 | + render( |
| 111 | + <MathJaxContext> |
| 112 | + <ResponseDisplay {...defaultProps} /> |
| 113 | + </MathJaxContext>, |
| 114 | + ); |
93 | 115 | const previewDisplay = screen.getByTestId('preview-display'); |
94 | 116 | expect(previewDisplay).toBeInTheDocument(); |
95 | 117 | expect(previewDisplay).toHaveTextContent('Preview: 2'); |
96 | 118 | }); |
97 | 119 |
|
98 | 120 | it('does not display file components when file upload is disabled', () => { |
99 | | - render(<ResponseDisplay {...defaultProps} fileUploadResponseConfig={fileUploadResponseOptions.none} />); |
| 121 | + render( |
| 122 | + <MathJaxContext> |
| 123 | + <ResponseDisplay {...defaultProps} fileUploadResponseConfig={fileUploadResponseOptions.none} /> |
| 124 | + </MathJaxContext>, |
| 125 | + ); |
100 | 126 | expect(screen.queryByTestId('submission-files')).not.toBeInTheDocument(); |
101 | 127 | expect(screen.queryByTestId('preview-display')).not.toBeInTheDocument(); |
102 | 128 | }); |
103 | 129 |
|
104 | 130 | it('renders empty content when no text response provided', () => { |
105 | | - const { container } = render(<ResponseDisplay {...defaultProps} response={{ text: [], files: [] }} />); |
| 131 | + const { container } = render( |
| 132 | + <MathJaxContext> |
| 133 | + <ResponseDisplay {...defaultProps} response={{ text: [], files: [] }} /> |
| 134 | + </MathJaxContext>, |
| 135 | + ); |
106 | 136 | const textContents = container.querySelectorAll('.response-display-text-content'); |
107 | 137 | expect(textContents).toHaveLength(0); |
108 | 138 | }); |
|
0 commit comments