forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [AXIMST-52] display unit and xblock render errors
- Loading branch information
1 parent
68d7533
commit 29e7e13
Showing
24 changed files
with
320 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { CheckCircle as CheckCircleIcon } from '@edx/paragon/icons'; | ||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
|
||
import RenderErrorAlert from '.'; | ||
import messages from './messages'; | ||
|
||
const defaultTitle = messages.alertRenderErrorTitle.defaultMessage; | ||
const defaultDescription = messages.alertRenderErrorDescription.defaultMessage; | ||
const defaultErrorFullMessage = messages.alertRenderErrorMessage.defaultMessage; | ||
const defaultErrorMessage = 'default error message'; | ||
const customClassName = 'some-class'; | ||
const customErrorMessage = 'custom error message'; | ||
|
||
const RootWrapper = (props) => ( | ||
<IntlProvider locale="en"> | ||
<RenderErrorAlert | ||
errorMessage={defaultErrorMessage} | ||
{...props} | ||
/> | ||
</IntlProvider> | ||
); | ||
|
||
describe('<RenderErrorAlert />', () => { | ||
it('renders default values when no props are provided', () => { | ||
const { getByText } = render(<RootWrapper />); | ||
const titleElement = getByText(defaultTitle); | ||
const descriptionElement = getByText(defaultDescription); | ||
expect(titleElement).toBeInTheDocument(); | ||
expect(descriptionElement).toBeInTheDocument(); | ||
expect(getByText(defaultErrorFullMessage.replace('{message}', defaultErrorMessage))).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders provided props correctly', () => { | ||
const customProps = { | ||
variant: 'success', | ||
icon: CheckCircleIcon, | ||
title: 'Custom Title', | ||
description: 'Custom Description', | ||
errorMessage: customErrorMessage, | ||
}; | ||
const { getByText } = render(<RootWrapper {...customProps} />); | ||
|
||
expect(getByText(customProps.title)).toBeInTheDocument(); | ||
expect(getByText(customProps.description)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the alert with additional props', () => { | ||
const { getByRole } = render(<RootWrapper className={customClassName} />); | ||
const alertElement = getByRole('alert'); | ||
const classNameExists = alertElement.classList.contains(customClassName); | ||
expect(alertElement).toBeInTheDocument(); | ||
expect(classNameExists).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import PropTypes from 'prop-types'; | ||
import { Info as InfoIcon } from '@edx/paragon/icons'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
|
||
import AlertMessage from '../alert-message'; | ||
import messages from './messages'; | ||
|
||
const RenderErrorAlert = ({ | ||
variant, icon, title, description, errorMessage, ...props | ||
}) => { | ||
const intl = useIntl(); | ||
|
||
return ( | ||
<AlertMessage | ||
variant={variant} | ||
icon={icon} | ||
title={title || intl.formatMessage(messages.alertRenderErrorTitle)} | ||
description={description || ( | ||
<> | ||
<p className="mt-4 mb-1">{intl.formatMessage(messages.alertRenderErrorDescription)}</p> | ||
<p className="mb-0">{intl.formatMessage(messages.alertRenderErrorMessage, { message: errorMessage })}</p> | ||
</> | ||
)} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
RenderErrorAlert.defaultProps = { | ||
icon: InfoIcon, | ||
variant: 'danger', | ||
title: '', | ||
description: '', | ||
}; | ||
|
||
RenderErrorAlert.propTypes = { | ||
variant: 'danger', | ||
icon: PropTypes.node, | ||
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), | ||
description: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), | ||
errorMessage: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default RenderErrorAlert; |
Oops, something went wrong.