diff options
author | Pascal Mugnier <pascal.mugnier@sonarsource.com> | 2018-03-07 14:28:11 +0100 |
---|---|---|
committer | Pascal Mugnier <pascal.mugnier@sonarsource.com> | 2018-03-07 14:28:11 +0100 |
commit | ec739303a171b09089a1987d69777fa988b19eb3 (patch) | |
tree | 5cccb0517561af90764113510bb6aa655df3c975 | |
parent | d39405a06b3ec3af82ec70ff71170a578ffbe284 (diff) | |
parent | da6a97014a1aba426ca6253623f6ff71281a64ac (diff) | |
download | sonarqube-ec739303a171b09089a1987d69777fa988b19eb3.tar.gz sonarqube-ec739303a171b09089a1987d69777fa988b19eb3.zip |
Merge branch 'master' of https://github.com/SonarSource/sonarqube
3 files changed, 214 insertions, 5 deletions
diff --git a/server/sonar-web/src/main/js/apps/component-measures/sidebar/DomainFacet.js b/server/sonar-web/src/main/js/apps/component-measures/sidebar/DomainFacet.js index 6ea4bc1afd1..47338d7ac0d 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/sidebar/DomainFacet.js +++ b/server/sonar-web/src/main/js/apps/component-measures/sidebar/DomainFacet.js @@ -67,9 +67,10 @@ export default class DomainFacet extends React.PureComponent { const { domain, selected } = this.props; const measureSelected = domain.measures.find(measure => measure.metric.key === selected); const overviewSelected = domain.name === selected && hasBubbleChart(domain.name); - return measureSelected - ? [getLocalizedMetricName(measureSelected.metric)] - : overviewSelected ? [translate('component_measures.domain_overview')] : []; + if (measureSelected) { + return [getLocalizedMetricName(measureSelected.metric)]; + } + return overviewSelected ? [translate('component_measures.domain_overview')] : []; }; renderItemFacetStat = (item /*: MeasureEnhanced */) => @@ -80,11 +81,19 @@ export default class DomainFacet extends React.PureComponent { const items = addMeasureCategories(domain.name, filterMeasures(domain.measures)); const hasCategories = items.some(item => typeof item === 'string'); const translateMetric = hasCategories ? getLocalizedCategoryMetricName : getLocalizedMetricName; - const sortedItems = sortMeasures(domain.name, items); + let sortedItems = sortMeasures(domain.name, items); + + sortedItems = sortedItems.filter((item, index) => { + return ( + typeof item !== 'string' || + (index + 1 !== sortedItems.length && typeof sortedItems[index + 1] !== 'string') + ); + }); + return sortedItems.map( item => typeof item === 'string' ? ( - <span key={item} className="facet search-navigator-facet facet-category"> + <span className="facet search-navigator-facet facet-category" key={item}> <span className="facet-name"> {translate('component_measures.facet_category', item)} </span> diff --git a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/DomainFacet-test.js b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/DomainFacet-test.js index a33095b87f6..551d11831e8 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/DomainFacet-test.js +++ b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/DomainFacet-test.js @@ -69,3 +69,51 @@ it('should render closed', () => { const wrapper = shallow(<DomainFacet {...PROPS} open={false} />); expect(wrapper.find('FacetItemsList')).toHaveLength(0); }); + +it('should not display subtitles of new measures if there is none', () => { + const domain = { + name: 'Reliability', + measures: [ + { + metric: { key: 'bugs', type: 'INT', name: 'Bugs', domain: 'Reliability' }, + value: '5' + } + ] + }; + + expect( + shallow( + <DomainFacet + domain={domain} + onChange={() => {}} + onToggle={() => {}} + open={true} + selected={'foo'} + /> + ) + ).toMatchSnapshot(); +}); + +it('should not display subtitles of new measures if there is none, even on last line', () => { + const domain = { + name: 'Reliability', + measures: [ + { + metric: { key: 'new_bugs', type: 'INT', name: 'New Bugs', domain: 'Reliability' }, + value: '5' + } + ] + }; + + expect( + shallow( + <DomainFacet + domain={domain} + onChange={() => {}} + onToggle={() => {}} + open={true} + selected={'foo'} + /> + ) + ).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/__snapshots__/DomainFacet-test.js.snap b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/__snapshots__/DomainFacet-test.js.snap index 864073e6026..aad1591cb67 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/__snapshots__/DomainFacet-test.js.snap +++ b/server/sonar-web/src/main/js/apps/component-measures/sidebar/__tests__/__snapshots__/DomainFacet-test.js.snap @@ -263,3 +263,155 @@ exports[`should display facet item list with bugs selected 1`] = ` </FacetItemsList> </FacetBox> `; + +exports[`should not display subtitles of new measures if there is none 1`] = ` +<FacetBox + property="Reliability" +> + <FacetHeader + name="Reliability" + onClick={[Function]} + open={true} + values={Array []} + /> + <FacetItemsList> + <FacetItem + active={false} + disabled={false} + halfWidth={false} + key="Reliability" + name={ + <span + id="measure-overview-Reliability-name" + > + component_measures.domain_overview + </span> + } + onClick={[Function]} + stat={ + <BubblesIcon + size={14} + /> + } + value="Reliability" + /> + <span + className="facet search-navigator-facet facet-category" + key="overall_category" + > + <span + className="facet-name" + > + component_measures.facet_category.overall_category + </span> + </span> + <FacetItem + active={false} + disabled={false} + halfWidth={false} + key="bugs" + name={ + <span + className="big-spacer-left" + id="measure-bugs-name" + > + Bugs + </span> + } + onClick={[Function]} + stat={ + <FacetMeasureValue + measure={ + Object { + "metric": Object { + "domain": "Reliability", + "key": "bugs", + "name": "Bugs", + "type": "INT", + }, + "value": "5", + } + } + /> + } + value="bugs" + /> + </FacetItemsList> +</FacetBox> +`; + +exports[`should not display subtitles of new measures if there is none, even on last line 1`] = ` +<FacetBox + property="Reliability" +> + <FacetHeader + name="Reliability" + onClick={[Function]} + open={true} + values={Array []} + /> + <FacetItemsList> + <FacetItem + active={false} + disabled={false} + halfWidth={false} + key="Reliability" + name={ + <span + id="measure-overview-Reliability-name" + > + component_measures.domain_overview + </span> + } + onClick={[Function]} + stat={ + <BubblesIcon + size={14} + /> + } + value="Reliability" + /> + <span + className="facet search-navigator-facet facet-category" + key="new_code_category" + > + <span + className="facet-name" + > + component_measures.facet_category.new_code_category + </span> + </span> + <FacetItem + active={false} + disabled={false} + halfWidth={false} + key="new_bugs" + name={ + <span + className="big-spacer-left" + id="measure-new_bugs-name" + > + New Bugs + </span> + } + onClick={[Function]} + stat={ + <FacetMeasureValue + measure={ + Object { + "metric": Object { + "domain": "Reliability", + "key": "new_bugs", + "name": "New Bugs", + "type": "INT", + }, + "value": "5", + } + } + /> + } + value="new_bugs" + /> + </FacetItemsList> +</FacetBox> +`; |