refactor: use application error alert in katex-frame

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-08-06 13:05:35 +02:00
parent 6f0adfd717
commit 2c4d688abd
4 changed files with 104 additions and 23 deletions

View file

@ -89,12 +89,13 @@ exports[`katex frame renders an error for an invalid latex expression as explici
<p
data-testid="katex-block"
>
<div
class="fade alert alert-danger show"
role="alert"
>
mocked parseerror
</div>
This is a mock for ApplicationErrorAlert.
<br />
Props:
{"className":""}
<br />
Children:
mocked parseerror
</p>
</div>
`;
@ -104,12 +105,13 @@ exports[`katex frame renders an error for an invalid latex expression as explici
<span
data-testid="katex-inline"
>
<div
class="fade d-inline-block alert alert-danger show"
role="alert"
>
mocked parseerror
</div>
This is a mock for ApplicationErrorAlert.
<br />
Props:
{"className":"d-inline-block"}
<br />
Children:
mocked parseerror
</span>
</div>
`;
@ -119,12 +121,13 @@ exports[`katex frame renders an error for an invalid latex expression as implici
<span
data-testid="katex-inline"
>
<div
class="fade d-inline-block alert alert-danger show"
role="alert"
>
mocked parseerror
</div>
This is a mock for ApplicationErrorAlert.
<br />
Props:
{"className":"d-inline-block"}
<br />
Children:
mocked parseerror
</span>
</div>
`;

View file

@ -101,10 +101,74 @@ exports[`KaTeX markdown extensions renders an error message for an invalid LaTeX
data-testid="katex-inline"
>
<div
class="fade d-inline-block alert alert-danger show"
class="fade alert d-inline-block alert alert-primary show"
role="alert"
>
mocked parseerror
<p
class="d-flex align-items-center"
>
<svg
class="logo"
clip-rule="evenodd"
fill-rule="evenodd"
height="32px"
stroke-linejoin="round"
stroke-miterlimit="2"
viewBox="0 0 430.07892 430.07892"
width="32"
xmlns="http://www.w3.org/2000/svg"
>
<g
fill-rule="nonzero"
transform="translate(10.242436 10.242452)"
>
<path
d="m0-124.766-6.399 6.398-7.662-4.814-4.812 7.662-8.541-2.989-2.988 8.54-8.993-1.013-1.011 8.991-8.992 1.013 1.012 8.991-8.541 2.989 2.988 8.54-7.661 4.815 4.815 7.662-6.399 6.399 6.398 6.398-4.814 7.661 7.661 4.814-2.988 8.541 8.541 2.988-1.012 8.985 8.992 1.011 1.011 8.985 8.993-1.015 2.988 8.54 8.541-2.988 4.812 7.662 7.662-4.813h12.796l7.661 4.813 4.814-7.66 8.541 2.988 2.988-8.54 8.992 1.014 1.014-8.985 8.99-1.012-1.012-8.985 8.54-2.988-2.988-8.541 7.662-4.815-4.815-7.66 6.398-6.398-6.398-6.399 4.815-7.66-7.662-4.814 2.988-8.542-8.54-2.988 1.014-8.991-8.992-1.015-1.013-8.991-8.991 1.013-2.989-8.54-8.54 2.989-4.814-7.663-7.663 4.815z"
fill="none"
stroke="#fff"
stroke-linejoin="miter"
stroke-miterlimit="2"
stroke-width="4.4095"
transform="matrix(3.2849556 0 0 3.2849556 207.55664 409.85076)"
/>
<path
d="m0-30.513c0-12.366-10.025-22.393-22.392-22.393-6.143 0-11.707 2.476-15.752 6.481l-.003-.002-5.705 5.706-4.665-4.665c-4.104-4.683-10.125-7.642-16.839-7.642-12.367 0-22.392 10.025-22.392 22.391 0 6.463 2.74 12.281 7.118 16.368l36.799 36.784 35.987-36.014c4.496-4.232 7.844-10.203 7.844-17.014"
fill="#fefefe"
transform="matrix(3.2849556 0 0 3.2849556 351.53527 341.0132)"
/>
<path
d="m-4.558-8.253c1.645 1.64 2.662 3.904 2.662 6.406 0 2.5-1.017 4.766-2.662 6.405-3.514-.026-6.357-2.883-6.357-6.405s2.843-6.38 6.357-6.406"
transform="matrix(0 -3.2849556 -3.2849556 0 201.44397 379.04995)"
/>
<path
d="m-4.896-4.894c-2.704 0-4.895 2.191-4.895 4.894 0 2.704 2.191 4.896 4.895 4.896s4.896-2.192 4.896-4.896c0-2.703-2.192-4.894-4.896-4.894"
transform="matrix(0 -3.2849556 -3.2849556 0 166.86087 250.80164)"
/>
<path
d="m-1.356-1.355c-.751 0-1.356.607-1.356 1.356 0 .748.605 1.355 1.356 1.355.749 0 1.357-.607 1.357-1.355 0-.749-.608-1.356-1.357-1.356"
fill="#fff"
transform="matrix(0 -3.2849556 -3.2849556 0 172.96926 261.80315)"
/>
<path
d="m-4.896-4.894c-2.704 0-4.895 2.191-4.895 4.896 0 2.703 2.191 4.894 4.895 4.894s4.896-2.191 4.896-4.894c0-2.705-2.192-4.896-4.896-4.896"
transform="matrix(0 -3.2849556 -3.2849556 0 248.40602 250.80164)"
/>
<path
d="m-1.357-1.356c-.751 0-1.356.608-1.356 1.358 0 .748.605 1.355 1.356 1.355.749 0 1.357-.607 1.357-1.355 0-.75-.608-1.358-1.357-1.358"
fill="#fff"
transform="matrix(0 -3.2849556 -3.2849556 0 254.51398 261.79888)"
/>
</g>
</svg>
<span
class="exclamation"
>
!
</span>
<span>
mocked parseerror
</span>
</p>
</div>
</span>
</p>

View file

@ -7,9 +7,23 @@ import KatexFrame from './katex-frame'
import { render } from '@testing-library/react'
import type { KatexOptions } from 'katex'
import { default as KatexDefault } from 'katex'
import type { PropsWithChildren } from 'react'
import React, { Fragment } from 'react'
jest.mock('katex')
jest.mock('../../../components/common/application-error-alert/application-error-alert', () => ({
ApplicationErrorAlert: ({ children, ...props }: PropsWithChildren) => (
<Fragment>
This is a mock for ApplicationErrorAlert.
<br />
Props: {JSON.stringify(props)}
<br />
Children: {children}
</Fragment>
)
}))
describe('katex frame', () => {
afterAll(() => {
jest.resetAllMocks()

View file

@ -8,7 +8,7 @@ import { testId } from '../../../utils/test-id'
import KaTeX from 'katex'
import 'katex/dist/katex.min.css'
import React, { useMemo } from 'react'
import { Alert } from 'react-bootstrap'
import { ApplicationErrorAlert } from '../../../components/common/application-error-alert/application-error-alert'
interface KatexFrameProps {
expression: string
@ -33,9 +33,9 @@ export const KatexFrame: React.FC<KatexFrameProps> = ({ expression, block = fals
)
} catch (error) {
return (
<Alert className={block ? '' : 'd-inline-block'} variant={'danger'}>
<ApplicationErrorAlert className={block ? '' : 'd-inline-block'}>
{(error as Error).message}
</Alert>
</ApplicationErrorAlert>
)
}
}, [block, expression])