'ncloc',
'sqale_index',
'violations',
- // TODO handle other types of coverage
- 'coverage',
'duplicated_lines_density'
];
+const METRICS_WITH_COVERAGE = [
+ ...METRICS,
+ 'coverage',
+ 'it_coverage',
+ 'overall_coverage'
+];
export const INIT = 'INIT';
}
-function fetchChildren (dispatch, baseComponent) {
+function fetchChildren (dispatch, getState, baseComponent) {
dispatch(requestComponents(baseComponent));
- return getChildren(baseComponent.key, METRICS)
+
+ const { coverageMetric } = getState();
+ const metrics = [...METRICS, coverageMetric];
+
+ return getChildren(baseComponent.key, metrics)
.then(components => _.sortBy(components, 'name'))
.then(components => dispatch(receiveComponents(baseComponent, components)));
}
export function initComponent (baseComponent) {
- return dispatch => {
- return getComponent(baseComponent.key, METRICS)
- .then(component => fetchChildren(dispatch, component));
+ return (dispatch, getState) => {
+ return getComponent(baseComponent.key, METRICS_WITH_COVERAGE)
+ .then(component => fetchChildren(dispatch, getState, component));
};
}
return (dispatch, getState) => {
const { fetching } = getState();
if (!fetching) {
- return fetchChildren(dispatch, baseComponent);
+ return fetchChildren(dispatch, getState, baseComponent);
}
};
}
}
render () {
- const { fetching, baseComponent, components, breadcrumbs, sourceViewer } = this.props;
+ const { fetching, baseComponent, components, breadcrumbs, sourceViewer, coverageMetric } = this.props;
const shouldShowBreadcrumbs = Array.isArray(breadcrumbs) && breadcrumbs.length > 1;
const shouldShowComponents = !sourceViewer && components;
const shouldShowSourceViewer = sourceViewer;
<Components
baseComponent={baseComponent}
components={components}
+ coverageMetric={coverageMetric}
onBrowse={this.handleBrowse.bind(this)}/>
</div>
)}
import ComponentDetach from './ComponentDetach';
-const Component = ({ component, onBrowse }) => (
+const Component = ({ component, coverageMetric, onBrowse }) => (
<tr>
<td className="thin nowrap">
<span className="spacer-right">
<div className="code-components-cell">
<ComponentMeasure
component={component}
- metricKey="coverage"
+ metricKey={coverageMetric}
metricType="PERCENT"/>
</div>
</td>
import ComponentsEmpty from './ComponentsEmpty';
-const Components = ({ baseComponent, components, onBrowse }) => (
+const Components = ({ baseComponent, components, coverageMetric, onBrowse }) => (
<table className="data zebra">
<thead>
<tr>
</tr>
</thead>
<tbody>
- <Component component={baseComponent}/>
+ <Component
+ component={baseComponent}
+ coverageMetric={coverageMetric}/>
<tr className="blank">
<td colSpan="7"> </td>
</tr>
<Component
key={component.key}
component={component}
+ coverageMetric={coverageMetric}
onBrowse={onBrowse}/>
))
) : (
+import _ from 'underscore';
import { combineReducers } from 'redux';
import { BROWSE, RECEIVE_COMPONENTS, SHOW_SOURCE } from '../actions';
}
+function selectCoverageMetric (component) {
+ const coverage = _.findWhere(component.msr, { key: 'coverage' });
+ const itCoverage = _.findWhere(component.msr, { key: 'it_coverage' });
+ const overallCoverage = _.findWhere(component.msr, { key: 'overall_coverage' });
+
+ if (coverage != null && itCoverage != null && overallCoverage != null) {
+ return 'overall_coverage';
+ } else if (coverage != null) {
+ return 'coverage';
+ } else {
+ return 'it_coverage';
+ }
+}
+
+
+export function coverageMetric (state = null, action) {
+ switch (action.type) {
+ case BROWSE:
+ return state !== null ? state : selectCoverageMetric(action.baseComponent);
+ default:
+ return state;
+ }
+}
+
+
const rootReducer = combineReducers({
fetching,
baseComponent,
components,
breadcrumbs,
- sourceViewer
+ sourceViewer,
+ coverageMetric
});
output = shallow(
<Component
component={exampleComponent}
+ coverageMetric="coverage"
onBrowse={exampleOnBrowse}/>);
});
baseComponent,
components,
breadcrumbs,
- sourceViewer
+ sourceViewer,
+ coverageMetric
} from '../../../src/main/js/apps/code/reducers';
import {
requestComponents,
expect(sourceViewer(exampleComponent, requestComponents({})))
.to.equal(null);
});
+
+ describe('coverageMetric', () => {
+ it('should be initially null', () => {
+ expect(coverageMetric(undefined, {}))
+ .to.equal(null);
+ });
+
+ it('should be set to "coverage"', () => {
+ const componentWithCoverage = {
+ ...exampleComponent,
+ msr: [
+ { key: 'coverage', val: 13 }
+ ]
+ };
+
+ expect(coverageMetric(null, requestComponents(componentWithCoverage)))
+ .to.equal('coverage');
+ });
+
+ it('should be set to "it_coverage"', () => {
+ const componentWithCoverage = {
+ ...exampleComponent,
+ msr: [
+ { key: 'it_coverage', val: 13 }
+ ]
+ };
+
+ expect(coverageMetric(null, requestComponents(componentWithCoverage)))
+ .to.equal('it_coverage');
+ });
+
+ it('should be set to "overall_coverage"', () => {
+ const componentWithCoverage = {
+ ...exampleComponent,
+ msr: [
+ { key: 'coverage', val: 11 },
+ { key: 'it_coverage', val: 12 },
+ { key: 'overall_coverage', val: 13 }
+ ]
+ };
+
+ expect(coverageMetric(null, requestComponents(componentWithCoverage)))
+ .to.equal('overall_coverage');
+ });
+
+ it('should fallback to "it_coverage"', () => {
+ const componentWithCoverage = {
+ ...exampleComponent,
+ msr: []
+ };
+
+ expect(coverageMetric(null, requestComponents(componentWithCoverage)))
+ .to.equal('it_coverage');
+ });
+
+ it('should not be reset after set once', () => {
+ const componentWithCoverage = {
+ ...exampleComponent,
+ msr: [
+ { key: 'coverage', val: 13 }
+ ]
+ };
+
+ expect(coverageMetric('overall_coverage', requestComponents(componentWithCoverage)))
+ .to.equal('overall_coverage');
+ });
+ });
});
});
});