aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorJeremy Davis <jeremy.davis@sonarsource.com>2019-06-25 15:41:17 +0200
committersonartech <sonartech@sonarsource.com>2019-06-28 08:45:49 +0200
commit265d7cb00b7c898b24f28f5d063c400c6bd8e454 (patch)
treec69350dcd4acdf09ec228b2b187cbb0bb58eea6c /server/sonar-web
parentda838c321fe3cfc92787c4e74920da373c6f7e48 (diff)
downloadsonarqube-265d7cb00b7c898b24f28f5d063c400c6bd8e454.tar.gz
sonarqube-265d7cb00b7c898b24f28f5d063c400c6bd8e454.zip
fixup! SONAR-12232 Add security review to portfolio projects list
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx55
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/ComponentMeasure-test.tsx.snap20
2 files changed, 52 insertions, 23 deletions
diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx
index 2b38649aa39..23a3a5019b1 100644
--- a/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx
+++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/ComponentMeasure-test.tsx
@@ -20,37 +20,52 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import ComponentMeasure from '../ComponentMeasure';
-
-const METRIC = { id: '1', key: 'coverage', type: 'PERCENT', name: 'Coverage' };
-const LEAK_METRIC = { id: '2', key: 'new_coverage', type: 'PERCENT', name: 'Coverage on New Code' };
-const COMPONENT = { key: 'foo', name: 'Foo', qualifier: 'TRK' };
-const COMPONENT_MEASURE = {
- ...COMPONENT,
- measures: [{ value: '3.0', periods: [{ index: 1, value: '10.0' }], metric: METRIC.key }]
-};
+import { mockMetric, mockMeasure, mockComponentMeasure } from '../../../../helpers/testMocks';
it('renders correctly', () => {
- expect(
- shallow(<ComponentMeasure component={COMPONENT_MEASURE} metric={METRIC} />)
- ).toMatchSnapshot();
+ expect(shallowRender()).toMatchSnapshot();
});
it('renders correctly for leak values', () => {
expect(
shallow(
<ComponentMeasure
- component={{
- ...COMPONENT,
- measures: [
- { value: '3.0', periods: [{ index: 1, value: '10.0' }], metric: LEAK_METRIC.key }
- ]
- }}
- metric={LEAK_METRIC}
+ component={mockComponentMeasure(false, {
+ measures: [mockMeasure({ metric: 'new_coverage' })]
+ })}
+ metric={mockMetric({ key: 'new_coverage', name: 'Coverage on New Code' })}
/>
)
).toMatchSnapshot();
});
-it('renders correctly when no measure found', () => {
- expect(shallow(<ComponentMeasure component={COMPONENT} metric={METRIC} />)).toMatchSnapshot();
+it('renders correctly when component has no measures', () => {
+ expect(
+ shallowRender({ component: mockComponentMeasure(false, { measures: undefined }) })
+ ).toMatchSnapshot();
+});
+
+it('should render correctly when no measure matches the metric', () => {
+ expect(shallowRender({ metric: mockMetric({ key: 'nonexistent_key' }) })).toMatchSnapshot();
+});
+
+it('should render correctly for releasability rating', () => {
+ expect(
+ shallowRender({
+ component: mockComponentMeasure(false, {
+ measures: [mockMeasure({ metric: 'alert_status' })]
+ }),
+ metric: mockMetric({ key: 'releasability_rating' })
+ })
+ ).toMatchSnapshot();
});
+
+function shallowRender(overrides: Partial<ComponentMeasure['props']> = {}) {
+ return shallow(
+ <ComponentMeasure
+ component={mockComponentMeasure(false, { measures: [mockMeasure({ metric: 'coverage' })] })}
+ metric={mockMetric()}
+ {...overrides}
+ />
+ );
+}
diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/ComponentMeasure-test.tsx.snap b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/ComponentMeasure-test.tsx.snap
index 824a3eb07a0..18298c07a08 100644
--- a/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/ComponentMeasure-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/__snapshots__/ComponentMeasure-test.tsx.snap
@@ -4,7 +4,7 @@ exports[`renders correctly 1`] = `
<Measure
metricKey="coverage"
metricType="PERCENT"
- value="3.0"
+ value="1.0"
/>
`;
@@ -12,8 +12,22 @@ exports[`renders correctly for leak values 1`] = `
<Measure
metricKey="new_coverage"
metricType="PERCENT"
- value="10.0"
+ value="1.0"
/>
`;
-exports[`renders correctly when no measure found 1`] = `<span />`;
+exports[`renders correctly when component has no measures 1`] = `<span />`;
+
+exports[`should render correctly for releasability rating 1`] = `
+<Measure
+ metricKey="alert_status"
+ metricType="LEVEL"
+ value="1.0"
+/>
+`;
+
+exports[`should render correctly when no measure matches the metric 1`] = `
+<span>
+ —
+</span>
+`;