Jérémie Pardou-Piquemal 50cefcb459
Add frontend component tests (#144)
* Install react-testing-library

* Add some trivial tests with snapshot

* Add File transfer tests

* Add Home component test

* Add Chat tests

* Add tests for nav

* 100% coverage for About component

* 100% coverage room link

* 100% coverage for RoomLocked

* 100% coverage for T component

* 100% coverage Settings

* More 90% coverage for Chat component

* Ignore some file from coverage

* 100% coverage fo redux actions

* 100% coverage for translations

* Near 100% coverage for reducer

* Better coverage for Home component

* Run tests in circleCI
2020-06-10 21:46:56 +02:00

33 lines
761 B
JavaScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { getTranslations } from 'i18n';
import _ from 'lodash';
const regex = /{(.*?)}/g;
class T extends Component {
render() {
const t = getTranslations(this.props.language);
const englishT = getTranslations('en');
const str =
_.get(t, this.props.path, '') || _.get(englishT, this.props.path, '');
let string = str.split(regex);
if (this.props.data) {
string = string.map((word) => {
if (this.props.data[word]) {
return this.props.data[word];
}
return word;
});
return <span>{string}</span>;
}
return string;
}
}
T.propTypes = {
path: PropTypes.string.isRequired,
};
export default T;