]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16885 [892404] [892409] [892231] [892423]
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Fri, 29 Jul 2022 09:12:17 +0000 (11:12 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 2 Aug 2022 20:04:05 +0000 (20:04 +0000)
* [892404] State: Selected state of the element is missing or incorrect
* [892409] Visual list is not marked up as list
* [892231] Color alone is used to convey info
* [892423] Keyboard focus is lost or misplaced due to user interaction or content update

server/sonar-web/src/main/js/components/charts/ColorBoxLegend.css
server/sonar-web/src/main/js/components/charts/ColorRatingsLegend.tsx
server/sonar-web/src/main/js/components/charts/__tests__/ColorRatingsLegend-test.tsx
server/sonar-web/src/main/js/components/charts/__tests__/__snapshots__/ColorRatingsLegend-test.tsx.snap [deleted file]
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index a370d61f22dc4c5cacedf6a65d81bd45306640b3..e9a6cc27297973e1ce1ac60f390328ba9e4a5b83 100644 (file)
   opacity: 1;
 }
 
-.color-box-legend button {
+.color-box-legend a {
   color: var(--baseFontColor);
   border-bottom: none;
   display: block;
 }
 
-.color-box-legend button.filtered {
+.color-box-legend a.filtered {
   opacity: 0.3;
 }
index 15ac6a1edda7dce966ef16fed9b6c0e952875c92..21a5f0ba9ee2e1f6a469010de3e7b23f6efcb752 100644 (file)
  */
 import classNames from 'classnames';
 import * as React from 'react';
-import { ButtonLink } from '../../components/controls/buttons';
 import Tooltip from '../../components/controls/Tooltip';
 import { RATING_COLORS } from '../../helpers/constants';
-import { translate } from '../../helpers/l10n';
+import { translateWithParameters } from '../../helpers/l10n';
 import { formatMeasure } from '../../helpers/measures';
 import './ColorBoxLegend.css';
 
@@ -37,27 +36,36 @@ const RATINGS = [1, 2, 3, 4, 5];
 export default function ColorRatingsLegend(props: ColorRatingsLegendProps) {
   const { className, filters } = props;
   return (
-    <div className={classNames('color-box-legend', className)}>
+    <ul className={classNames('color-box-legend', className)}>
       {RATINGS.map(rating => (
-        <Tooltip key={rating} overlay={translate('component_measures.legend.help')}>
-          <ButtonLink
-            className={classNames('little-padded-bottom', {
-              filtered: filters[rating]
-            })}
-            onClick={() => props.onRatingClick(rating)}
-            type="button">
-            <span
-              className="color-box-legend-rect"
-              style={{ borderColor: RATING_COLORS[rating - 1] }}>
+        <li key={rating}>
+          <Tooltip
+            overlay={translateWithParameters(
+              'component_measures.legend.help_x',
+              formatMeasure(rating, 'RATING')
+            )}>
+            <a
+              aria-checked={!filters[rating]}
+              className={classNames('little-padded-bottom', {
+                filtered: filters[rating]
+              })}
+              href="#"
+              onClick={() => props.onRatingClick(rating)}
+              role="checkbox"
+              tabIndex={0}>
               <span
-                className="color-box-legend-rect-inner"
-                style={{ backgroundColor: RATING_COLORS[rating - 1] }}
-              />
-            </span>
-            {formatMeasure(rating, 'RATING')}
-          </ButtonLink>
-        </Tooltip>
+                className="color-box-legend-rect"
+                style={{ borderColor: RATING_COLORS[rating - 1] }}>
+                <span
+                  className="color-box-legend-rect-inner"
+                  style={{ backgroundColor: RATING_COLORS[rating - 1] }}
+                />
+              </span>
+              {formatMeasure(rating, 'RATING')}
+            </a>
+          </Tooltip>
+        </li>
       ))}
-    </div>
+    </ul>
   );
 }
index d3c2ddf9bd43f086b466e854b4d347f97323be67..37b179cfa6b8607f472c7057fc5f90b36d0a1627 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { shallow } from 'enzyme';
+import { screen } from '@testing-library/dom';
 import * as React from 'react';
-import { ButtonLink } from '../../../components/controls/buttons';
+import { renderComponent } from '../../../helpers/testReactTestingUtils';
 import ColorRatingsLegend, { ColorRatingsLegendProps } from '../ColorRatingsLegend';
 
 it('should render correctly', () => {
-  expect(shallowRender()).toMatchSnapshot();
+  renderColorRatingsLegend();
+  expect(screen.getByRole('checkbox', { name: 'A' })).toBeInTheDocument();
+  expect(screen.getByRole('checkbox', { name: 'B' })).toBeInTheDocument();
+  expect(screen.getByRole('checkbox', { name: 'C' })).toBeInTheDocument();
+  expect(screen.getByRole('checkbox', { name: 'D' })).toBeInTheDocument();
+  expect(screen.getByRole('checkbox', { name: 'E' })).toBeInTheDocument();
 });
 
-it('should callback when a rating is clicked', () => {
+it('should react when a rating is clicked', () => {
   const onRatingClick = jest.fn();
-  const wrapper = shallowRender({ onRatingClick });
-
-  wrapper
-    .find(ButtonLink)
-    .at(3)
-    .simulate('click');
+  renderColorRatingsLegend({ onRatingClick });
 
+  screen.getByRole('checkbox', { name: 'D' }).click();
   expect(onRatingClick).toBeCalledWith(4);
 });
 
-function shallowRender(overrides: Partial<ColorRatingsLegendProps> = {}) {
-  return shallow(
-    <ColorRatingsLegend filters={{ 2: true }} onRatingClick={jest.fn()} {...overrides} />
+function renderColorRatingsLegend(props: Partial<ColorRatingsLegendProps> = {}) {
+  return renderComponent(
+    <ColorRatingsLegend filters={{ 2: true }} onRatingClick={jest.fn()} {...props} />
   );
 }
diff --git a/server/sonar-web/src/main/js/components/charts/__tests__/__snapshots__/ColorRatingsLegend-test.tsx.snap b/server/sonar-web/src/main/js/components/charts/__tests__/__snapshots__/ColorRatingsLegend-test.tsx.snap
deleted file mode 100644 (file)
index 52a280f..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render correctly 1`] = `
-<div
-  className="color-box-legend"
->
-  <Tooltip
-    key="1"
-    overlay="component_measures.legend.help"
-  >
-    <ButtonLink
-      className="little-padded-bottom"
-      onClick={[Function]}
-      type="button"
-    >
-      <span
-        className="color-box-legend-rect"
-        style={
-          Object {
-            "borderColor": "#00aa00",
-          }
-        }
-      >
-        <span
-          className="color-box-legend-rect-inner"
-          style={
-            Object {
-              "backgroundColor": "#00aa00",
-            }
-          }
-        />
-      </span>
-      A
-    </ButtonLink>
-  </Tooltip>
-  <Tooltip
-    key="2"
-    overlay="component_measures.legend.help"
-  >
-    <ButtonLink
-      className="little-padded-bottom filtered"
-      onClick={[Function]}
-      type="button"
-    >
-      <span
-        className="color-box-legend-rect"
-        style={
-          Object {
-            "borderColor": "#b0d513",
-          }
-        }
-      >
-        <span
-          className="color-box-legend-rect-inner"
-          style={
-            Object {
-              "backgroundColor": "#b0d513",
-            }
-          }
-        />
-      </span>
-      B
-    </ButtonLink>
-  </Tooltip>
-  <Tooltip
-    key="3"
-    overlay="component_measures.legend.help"
-  >
-    <ButtonLink
-      className="little-padded-bottom"
-      onClick={[Function]}
-      type="button"
-    >
-      <span
-        className="color-box-legend-rect"
-        style={
-          Object {
-            "borderColor": "#eabe06",
-          }
-        }
-      >
-        <span
-          className="color-box-legend-rect-inner"
-          style={
-            Object {
-              "backgroundColor": "#eabe06",
-            }
-          }
-        />
-      </span>
-      C
-    </ButtonLink>
-  </Tooltip>
-  <Tooltip
-    key="4"
-    overlay="component_measures.legend.help"
-  >
-    <ButtonLink
-      className="little-padded-bottom"
-      onClick={[Function]}
-      type="button"
-    >
-      <span
-        className="color-box-legend-rect"
-        style={
-          Object {
-            "borderColor": "#ed7d20",
-          }
-        }
-      >
-        <span
-          className="color-box-legend-rect-inner"
-          style={
-            Object {
-              "backgroundColor": "#ed7d20",
-            }
-          }
-        />
-      </span>
-      D
-    </ButtonLink>
-  </Tooltip>
-  <Tooltip
-    key="5"
-    overlay="component_measures.legend.help"
-  >
-    <ButtonLink
-      className="little-padded-bottom"
-      onClick={[Function]}
-      type="button"
-    >
-      <span
-        className="color-box-legend-rect"
-        style={
-          Object {
-            "borderColor": "#d4333f",
-          }
-        }
-      >
-        <span
-          className="color-box-legend-rect-inner"
-          style={
-            Object {
-              "backgroundColor": "#d4333f",
-            }
-          }
-        />
-      </span>
-      E
-    </ButtonLink>
-  </Tooltip>
-</div>
-`;
index 4ca50b4a48c40d74a096595c3d5ae45835ed132d..3a31c043dac7291e6aba001998c0a097491d6049 100644 (file)
@@ -3278,7 +3278,7 @@ component_measures.view_as=View as
 component_measures.legend.color_x=Color: {0}
 component_measures.legend.size_x=Size: {0}
 component_measures.legend.worse_of_x_y=Worse of {0} and {1}
-component_measures.legend.help=Click to toggle visibility.
+component_measures.legend.help_x=Click to toggle visibility for data with rating {0}.
 component_measures.legend.only_first_500_files=Only showing data for the first 500 files
 component_measures.no_history=There isn't enough data to generate an activity graph.
 component_measures.not_found=The requested measure was not found.