From 71cc0592365fc7ff36694c726c1a8ca4e1fcc6cd Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Tue, 22 Sep 2020 14:20:28 +0200 Subject: SONAR-13880 internationalize tooltips --- .../js/components/common/DocumentationTooltip.tsx | 72 +++++++++++++ .../common/__tests__/DocumentationTooltip-test.tsx | 40 ++++++++ .../DocumentationTooltip-test.tsx.snap | 112 +++++++++++++++++++++ 3 files changed, 224 insertions(+) create mode 100644 server/sonar-web/src/main/js/components/common/DocumentationTooltip.tsx create mode 100644 server/sonar-web/src/main/js/components/common/__tests__/DocumentationTooltip-test.tsx create mode 100644 server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/DocumentationTooltip-test.tsx.snap (limited to 'server/sonar-web/src/main/js/components/common') diff --git a/server/sonar-web/src/main/js/components/common/DocumentationTooltip.tsx b/server/sonar-web/src/main/js/components/common/DocumentationTooltip.tsx new file mode 100644 index 00000000000..c2ede9b95f1 --- /dev/null +++ b/server/sonar-web/src/main/js/components/common/DocumentationTooltip.tsx @@ -0,0 +1,72 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import HelpTooltip from 'sonar-ui-common/components/controls/HelpTooltip'; +import DetachIcon from 'sonar-ui-common/components/icons/DetachIcon'; +import { isWebUri } from 'valid-url'; + +export interface DocumentationTooltipProps { + children?: React.ReactNode; + className?: string; + content?: React.ReactNode; + links?: Array<{ href: string; label: string }>; + title?: string; +} + +export default function DocumentationTooltip(props: DocumentationTooltipProps) { + const { className, content, links, title } = props; + + return ( + + {title && ( +
+ {title} +
+ )} + + {content &&

{content}

} + + {links && ( + <> +
+ + {links.map(({ href, label }) => ( +
+ + {isWebUri(href) && } + {label} + +
+ ))} + + )} + + }> + {props.children} +
+ ); +} diff --git a/server/sonar-web/src/main/js/components/common/__tests__/DocumentationTooltip-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/DocumentationTooltip-test.tsx new file mode 100644 index 00000000000..fc7ae766eb8 --- /dev/null +++ b/server/sonar-web/src/main/js/components/common/__tests__/DocumentationTooltip-test.tsx @@ -0,0 +1,40 @@ +/* + * SonarQube + * Copyright (C) 2009-2020 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * 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 * as React from 'react'; +import DocumentationTooltip, { DocumentationTooltipProps } from '../DocumentationTooltip'; + +it('renders correctly', () => { + expect(shallowRender()).toMatchSnapshot('basic'); + expect( + shallowRender({ + links: [ + { href: 'http://link.tosome.place', label: 'external link' }, + { href: '/documentation/guide', label: 'internal link' } + ] + }) + ).toMatchSnapshot('with links'); + expect(shallowRender({ title: undefined })).toMatchSnapshot('no title'); + expect(shallowRender({ content: undefined })).toMatchSnapshot('no content'); +}); + +function shallowRender(props: Partial = {}) { + return shallow(); +} diff --git a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/DocumentationTooltip-test.tsx.snap b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/DocumentationTooltip-test.tsx.snap new file mode 100644 index 00000000000..423376fa2ce --- /dev/null +++ b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/DocumentationTooltip-test.tsx.snap @@ -0,0 +1,112 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders correctly: basic 1`] = ` + +
+ + title + +
+

+ content +

+ + } +/> +`; + +exports[`renders correctly: no content 1`] = ` + +
+ + title + +
+ + } +/> +`; + +exports[`renders correctly: no title 1`] = ` + +

+ content +

+ + } +/> +`; + +exports[`renders correctly: with links 1`] = ` + +
+ + title + +
+

+ content +

+ +
+ + +
+ + } +/> +`; -- cgit v1.2.3