From 41672d85daa2bef7cd18af5f97edbaaa36ceb8fb Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Fri, 7 Oct 2022 11:17:39 +0200 Subject: [PATCH] SONAR-16948 Buttons have same name but different actions --- .../__tests__/SourceViewer-it.tsx | 30 ++++++++++--------- .../SourceViewer/components/LineSCM.tsx | 4 +-- .../resources/org/sonar/l10n/core.properties | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-it.tsx b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-it.tsx index dfbffaf2828..60a824117f5 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-it.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewer-it.tsx @@ -186,7 +186,8 @@ it('should show SCM information', async () => { ).toBeInTheDocument(); await user.click( firstRowScreen.getByRole('button', { - name: 'source_viewer.author_X.stas.vilchik@sonarsource.com, source_viewer.click_for_scm_info' + name: + 'source_viewer.author_X.stas.vilchik@sonarsource.com, source_viewer.click_for_scm_info.1' }) ); @@ -210,48 +211,49 @@ it('should show SCM information', async () => { // SCM with no date row = await screen.findByRole('row', { name: /\* mailto:info AT sonarsource DOT com$/ }); expect(row).toBeInTheDocument(); - const thirdRowScreen = within(row); + const fourthRowScreen = within(row); await user.click( - thirdRowScreen.getByRole('button', { - name: 'source_viewer.author_X.stas.vilchik@sonarsource.com, source_viewer.click_for_scm_info' + fourthRowScreen.getByRole('button', { + name: + 'source_viewer.author_X.stas.vilchik@sonarsource.com, source_viewer.click_for_scm_info.4' }) ); expect( - await thirdRowScreen.findByRole('heading', { level: 4, name: 'author' }) + await fourthRowScreen.findByRole('heading', { level: 4, name: 'author' }) ).toBeInTheDocument(); expect( - thirdRowScreen.queryByRole('heading', { + fourthRowScreen.queryByRole('heading', { level: 4, name: 'source_viewer.tooltip.scm.commited_on' }) ).not.toBeInTheDocument(); expect( - thirdRowScreen.getByRole('heading', { level: 4, name: 'source_viewer.tooltip.scm.revision' }) + fourthRowScreen.getByRole('heading', { level: 4, name: 'source_viewer.tooltip.scm.revision' }) ).toBeInTheDocument(); // SCM with no date no author row = await screen.findByRole('row', { name: /\* 5$/ }); expect(row).toBeInTheDocument(); - const fourthRowScreen = within(row); - expect(fourthRowScreen.getByText('…')).toBeInTheDocument(); + const fithRowScreen = within(row); + expect(fithRowScreen.getByText('…')).toBeInTheDocument(); await user.click( - fourthRowScreen.getByRole('button', { - name: 'source_viewer.click_for_scm_info' + fithRowScreen.getByRole('button', { + name: 'source_viewer.click_for_scm_info.5' }) ); expect( - fourthRowScreen.queryByRole('heading', { level: 4, name: 'author' }) + fithRowScreen.queryByRole('heading', { level: 4, name: 'author' }) ).not.toBeInTheDocument(); expect( - fourthRowScreen.queryByRole('heading', { + fithRowScreen.queryByRole('heading', { level: 4, name: 'source_viewer.tooltip.scm.commited_on' }) ).not.toBeInTheDocument(); expect( - fourthRowScreen.getByRole('heading', { level: 4, name: 'source_viewer.tooltip.scm.revision' }) + fithRowScreen.getByRole('heading', { level: 4, name: 'source_viewer.tooltip.scm.revision' }) ).toBeInTheDocument(); // No SCM Popup diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/LineSCM.tsx b/server/sonar-web/src/main/js/components/SourceViewer/components/LineSCM.tsx index c06c6e41c5e..d50554a67dd 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/LineSCM.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/LineSCM.tsx @@ -20,7 +20,7 @@ import * as React from 'react'; import Dropdown from '../../../components/controls/Dropdown'; import { PopupPlacement } from '../../../components/ui/popups'; -import { translate, translateWithParameters } from '../../../helpers/l10n'; +import { translateWithParameters } from '../../../helpers/l10n'; import { SourceLine } from '../../../types/types'; import { ButtonPlain } from '../../controls/buttons'; import SCMPopup from './SCMPopup'; @@ -39,7 +39,7 @@ export function LineSCM({ line, previousLine }: LineSCMProps) { ); if (hasPopup) { - let ariaLabel = translate('source_viewer.click_for_scm_info'); + let ariaLabel = translateWithParameters('source_viewer.click_for_scm_info', line.line); if (line.scmAuthor) { ariaLabel = `${translateWithParameters( 'source_viewer.author_X', diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index cf9c7de65be..735c071564a 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2868,7 +2868,7 @@ source_viewer.covered=Covered by the following tests source_viewer.not_covered=Not covered by tests source_viewer.conditions=conditions source_viewer.line_X=Line: {0} -source_viewer.click_for_scm_info=Click to see SCM information +source_viewer.click_for_scm_info=Click to see SCM information for line {0} source_viewer.author_X=Author: {0} source_viewer.click_to_copy_filepath=Click to copy the filepath to clipboard -- 2.39.5