import { PORTFOLIO_METRICS, SUB_COMPONENTS_METRICS, convertMeasures } from '../utils';
import { SubComponent } from '../types';
import '../styles.css';
+import { translate } from '../../../helpers/l10n';
interface Props {
component: { key: string; name: string };
);
}
+ isEmpty = () => this.state.measures == undefined || this.state.measures['ncloc'] == undefined;
+
+ isNotComputed = () =>
+ this.state.measures && this.state.measures['reliability_rating'] == undefined;
+
renderSpinner() {
return (
<div className="page page-limited">
);
}
+ renderEmpty() {
+ return (
+ <div className="empty-search">
+ <h3>{translate('portfolio.empty')}</h3>
+ <p>{translate('portfolio.empty.hint')}</p>
+ </div>
+ );
+ }
+
+ renderWhenNotComputed() {
+ return (
+ <div className="empty-search">
+ <h3>{translate('portfolio.not_computed')}</h3>
+ </div>
+ );
+ }
+
+ renderMain() {
+ const { component } = this.props;
+ const { measures, subComponents, totalSubComponents } = this.state;
+
+ if (this.isEmpty()) {
+ return this.renderEmpty();
+ }
+
+ if (this.isNotComputed()) {
+ return this.renderWhenNotComputed();
+ }
+
+ return (
+ <div>
+ <div className="portfolio-boxes">
+ <ReleasabilityBox component={component.key} measures={measures!} />
+ <ReliabilityBox component={component.key} measures={measures!} />
+ <SecurityBox component={component.key} measures={measures!} />
+ <MaintainabilityBox component={component.key} measures={measures!} />
+ </div>
+
+ {subComponents != undefined &&
+ totalSubComponents != undefined && (
+ <WorstProjects
+ component={component.key}
+ subComponents={subComponents}
+ total={totalSubComponents}
+ />
+ )}
+ </div>
+ );
+ }
+
render() {
const { component } = this.props;
- const { loading, measures, subComponents, totalSubComponents } = this.state;
+ const { loading, measures } = this.state;
if (loading) {
return this.renderSpinner();
return (
<div className="page page-limited">
<div className="page-with-sidebar">
- <div className="page-main">
- {measures != undefined && (
- <div className="portfolio-boxes">
- <ReleasabilityBox component={component.key} measures={measures} />
- <ReliabilityBox component={component.key} measures={measures} />
- <SecurityBox component={component.key} measures={measures} />
- <MaintainabilityBox component={component.key} measures={measures} />
- </div>
- )}
-
- {subComponents != undefined &&
- totalSubComponents != undefined && (
- <WorstProjects
- component={component.key}
- subComponents={subComponents}
- total={totalSubComponents}
- />
- )}
- </div>
+ <div className="page-main">{this.renderMain()}</div>
<aside className="page-sidebar-fixed">
- {measures != undefined && <Summary component={component} measures={measures} />}
+ {!this.isEmpty() &&
+ !this.isNotComputed() && <Summary component={component} measures={measures!} />}
<Activity component={component.key} />
<Report component={component} />
</aside>
it('renders', () => {
const wrapper = shallow(<App component={component} />);
- wrapper.setState({ loading: false, measures: {}, subComponents: [], totalSubComponents: 0 });
+ wrapper.setState({
+ loading: false,
+ measures: { ncloc: '173', reliability_rating: '1' },
+ subComponents: [],
+ totalSubComponents: 0
+ });
+ expect(wrapper).toMatchSnapshot();
+});
+
+it('renders when portfolio is empty', () => {
+ const wrapper = shallow(<App component={component} />);
+ wrapper.setState({ loading: false, measures: { reliability_rating: '1' } });
+ expect(wrapper).toMatchSnapshot();
+});
+
+it('renders when portfolio is not computed', () => {
+ const wrapper = shallow(<App component={component} />);
+ wrapper.setState({ loading: false, measures: { ncloc: '173' } });
expect(wrapper).toMatchSnapshot();
});
<div
className="page-main"
>
- <div
- className="portfolio-boxes"
- >
- <ReleasabilityBox
- component="foo"
- measures={Object {}}
- />
- <ReliabilityBox
- component="foo"
- measures={Object {}}
- />
- <SecurityBox
- component="foo"
- measures={Object {}}
- />
- <MaintainabilityBox
+ <div>
+ <div
+ className="portfolio-boxes"
+ >
+ <ReleasabilityBox
+ component="foo"
+ measures={
+ Object {
+ "ncloc": "173",
+ "reliability_rating": "1",
+ }
+ }
+ />
+ <ReliabilityBox
+ component="foo"
+ measures={
+ Object {
+ "ncloc": "173",
+ "reliability_rating": "1",
+ }
+ }
+ />
+ <SecurityBox
+ component="foo"
+ measures={
+ Object {
+ "ncloc": "173",
+ "reliability_rating": "1",
+ }
+ }
+ />
+ <MaintainabilityBox
+ component="foo"
+ measures={
+ Object {
+ "ncloc": "173",
+ "reliability_rating": "1",
+ }
+ }
+ />
+ </div>
+ <WorstProjects
component="foo"
- measures={Object {}}
+ subComponents={Array []}
+ total={0}
/>
</div>
- <WorstProjects
+ </div>
+ <aside
+ className="page-sidebar-fixed"
+ >
+ <Summary
+ component={
+ Object {
+ "key": "foo",
+ "name": "Foo",
+ }
+ }
+ measures={
+ Object {
+ "ncloc": "173",
+ "reliability_rating": "1",
+ }
+ }
+ />
+ <Activity
component="foo"
- subComponents={Array []}
- total={0}
/>
+ <Report
+ component={
+ Object {
+ "key": "foo",
+ "name": "Foo",
+ }
+ }
+ />
+ </aside>
+ </div>
+</div>
+`;
+
+exports[`renders when portfolio is empty 1`] = `
+<div
+ className="page page-limited"
+>
+ <div
+ className="page-with-sidebar"
+ >
+ <div
+ className="page-main"
+ >
+ <div
+ className="empty-search"
+ >
+ <h3>
+ portfolio.empty
+ </h3>
+ <p>
+ portfolio.empty.hint
+ </p>
+ </div>
</div>
<aside
className="page-sidebar-fixed"
>
- <Summary
+ <Activity
+ component="foo"
+ />
+ <Report
component={
Object {
"key": "foo",
"name": "Foo",
}
}
- measures={Object {}}
/>
+ </aside>
+ </div>
+</div>
+`;
+
+exports[`renders when portfolio is not computed 1`] = `
+<div
+ className="page page-limited"
+>
+ <div
+ className="page-with-sidebar"
+ >
+ <div
+ className="page-main"
+ >
+ <div
+ className="empty-search"
+ >
+ <h3>
+ portfolio.not_computed
+ </h3>
+ </div>
+ </div>
+ <aside
+ className="page-sidebar-fixed"
+ >
<Activity
component="foo"
/>