mattermost-mobile/app/components/error_text/error_text.js
Joseph Baylon 5f6fd6df7a
MM-30286 Detox/E2E: Add e2e test for MM-T3236 and added basic unit tests (#4969)
* MM-30286 Detox/E2E: Add e2e test for MM-T3236

* Fix more testID hierarchies

* Fix typo

* Fix failing test

* Remove extra lines

* Updated to use string interpolation

* Update channels list element query

* Updated channel item unit test to be more consistent

* Fix error text testID hierarchies; fix edit channel info testIDs

* Fix snap file

* Fix line return
2020-11-24 16:58:09 +08:00

59 lines
1.7 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Text} from 'react-native';
import CustomPropTypes from 'app/constants/custom_prop_types';
import FormattedText from 'app/components/formatted_text';
import {GlobalStyles} from 'app/styles';
import {makeStyleSheetFromTheme} from 'app/utils/theme';
export default class ErrorText extends PureComponent {
static propTypes = {
testID: PropTypes.string,
error: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
textStyle: CustomPropTypes.Style,
theme: PropTypes.object.isRequired,
};
render() {
const {testID, error, textStyle, theme} = this.props;
if (!error) {
return null;
}
const style = getStyleSheet(theme);
const {intl} = error;
if (intl) {
return (
<FormattedText
testID={testID}
id={intl.id}
defaultMessage={intl.defaultMessage}
values={intl.values}
style={[GlobalStyles.errorLabel, style.errorLabel, textStyle]}
/>
);
}
return (
<Text
testID={testID}
style={[GlobalStyles.errorLabel, style.errorLabel, textStyle]}
>
{error.message || error}
</Text>
);
}
}
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
return {
errorLabel: {
color: (theme.errorTextColor || '#DA4A4A'),
},
};
});