aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-ui-common/components/controls/__tests__
diff options
context:
space:
mode:
authorPhilippe Perrin <philippe.perrin@sonarsource.com>2021-07-16 14:50:53 +0200
committersonartech <sonartech@sonarsource.com>2021-07-21 20:03:01 +0000
commit22e0696a0924aee4746155771412460085ccb0df (patch)
tree672a899f67c1df1cc8e582d9329a656c41e236d3 /server/sonar-ui-common/components/controls/__tests__
parenta57b5dd4d8ba48dd55a80111f1c6db54cb36c63d (diff)
downloadsonarqube-22e0696a0924aee4746155771412460085ccb0df.tar.gz
sonarqube-22e0696a0924aee4746155771412460085ccb0df.zip
SONAR-14617 Target local sonar-ui-common project
Diffstat (limited to 'server/sonar-ui-common/components/controls/__tests__')
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ActionsDropdown-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/BackButton-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/BoxedGroupAccordion-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/BoxedTabs-test.tsx6
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/Checkbox-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ClickEventBoundary-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ConfirmButton-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ConfirmModal-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/Dropdown-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/EscKeydownHandler-test.tsx5
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/FavoriteButton-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/GlobalMessages-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/HelpTooltip-test.tsx5
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/IdentityProviderLink-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/InputValidationField-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ListFooter-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ModalButton-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ModalValidationField-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/OutsideClickHandler-test.tsx74
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/Radio-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/RadioCard-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/RadioToggle-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ReloadButton-test.tsx5
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ScreenPositionFixer-test.tsx14
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/SearchBox-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/SearchSelect-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/SelectList-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/SelectListListContainer-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/SelectListListElement-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/SimpleModal-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/Tabs-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/Toggle-test.tsx5
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/Toggler-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/Tooltip-test.tsx88
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ValidationForm-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ValidationInput-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/ValidationModal-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/__snapshots__/OutsideClickHandler-test.tsx.snap7
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/buttons-test.tsx4
-rw-r--r--server/sonar-ui-common/components/controls/__tests__/clipboard-test.tsx8
40 files changed, 211 insertions, 126 deletions
diff --git a/server/sonar-ui-common/components/controls/__tests__/ActionsDropdown-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ActionsDropdown-test.tsx
index 93c5a8d7d37..a74b20fd933 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ActionsDropdown-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ActionsDropdown-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/BackButton-test.tsx b/server/sonar-ui-common/components/controls/__tests__/BackButton-test.tsx
index 77ad09c9f5e..0f206076ad9 100644
--- a/server/sonar-ui-common/components/controls/__tests__/BackButton-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/BackButton-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/BoxedGroupAccordion-test.tsx b/server/sonar-ui-common/components/controls/__tests__/BoxedGroupAccordion-test.tsx
index 7feece1ecdd..970a3546c3a 100644
--- a/server/sonar-ui-common/components/controls/__tests__/BoxedGroupAccordion-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/BoxedGroupAccordion-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/BoxedTabs-test.tsx b/server/sonar-ui-common/components/controls/__tests__/BoxedTabs-test.tsx
index d597369ea1d..6db0b5c28e1 100644
--- a/server/sonar-ui-common/components/controls/__tests__/BoxedTabs-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/BoxedTabs-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -42,7 +42,7 @@ function mountRender(overrides: Partial<BoxedTabsProps<string>> = {}) {
return mount(dom(overrides));
}
-function dom(overrides) {
+function dom<K>(overrides: Partial<BoxedTabsProps<K>>) {
return (
<BoxedTabs
className="boxed-tabs"
diff --git a/server/sonar-ui-common/components/controls/__tests__/Checkbox-test.tsx b/server/sonar-ui-common/components/controls/__tests__/Checkbox-test.tsx
index e05e0c87d74..b56cce6c559 100644
--- a/server/sonar-ui-common/components/controls/__tests__/Checkbox-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/Checkbox-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ClickEventBoundary-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ClickEventBoundary-test.tsx
index c20dc06a910..c2f6d701a76 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ClickEventBoundary-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ClickEventBoundary-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ConfirmButton-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ConfirmButton-test.tsx
index abd1ae483e6..69b6fde10d5 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ConfirmButton-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ConfirmButton-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ConfirmModal-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ConfirmModal-test.tsx
index 15fd56c0622..cfefbac465a 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ConfirmModal-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ConfirmModal-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/Dropdown-test.tsx b/server/sonar-ui-common/components/controls/__tests__/Dropdown-test.tsx
index 0595d595a27..6c051fefb3e 100644
--- a/server/sonar-ui-common/components/controls/__tests__/Dropdown-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/Dropdown-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/EscKeydownHandler-test.tsx b/server/sonar-ui-common/components/controls/__tests__/EscKeydownHandler-test.tsx
index 12641596f46..6c852477b81 100644
--- a/server/sonar-ui-common/components/controls/__tests__/EscKeydownHandler-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/EscKeydownHandler-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -17,7 +17,6 @@
* 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 { KeyCodes } from '../../../helpers/keycodes';
diff --git a/server/sonar-ui-common/components/controls/__tests__/FavoriteButton-test.tsx b/server/sonar-ui-common/components/controls/__tests__/FavoriteButton-test.tsx
index 61919eb6eb7..d0978f050d4 100644
--- a/server/sonar-ui-common/components/controls/__tests__/FavoriteButton-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/FavoriteButton-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/GlobalMessages-test.tsx b/server/sonar-ui-common/components/controls/__tests__/GlobalMessages-test.tsx
index 3dc4eda5661..af48c1a9701 100644
--- a/server/sonar-ui-common/components/controls/__tests__/GlobalMessages-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/GlobalMessages-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/HelpTooltip-test.tsx b/server/sonar-ui-common/components/controls/__tests__/HelpTooltip-test.tsx
index ecd7a50539e..6bd89e53b25 100644
--- a/server/sonar-ui-common/components/controls/__tests__/HelpTooltip-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/HelpTooltip-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -17,7 +17,6 @@
* 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 testTheme from '../../../config/jest/testTheme';
diff --git a/server/sonar-ui-common/components/controls/__tests__/IdentityProviderLink-test.tsx b/server/sonar-ui-common/components/controls/__tests__/IdentityProviderLink-test.tsx
index 9a8b0a49481..0050cd6f277 100644
--- a/server/sonar-ui-common/components/controls/__tests__/IdentityProviderLink-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/IdentityProviderLink-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/InputValidationField-test.tsx b/server/sonar-ui-common/components/controls/__tests__/InputValidationField-test.tsx
index 363e3d79a8a..6c7c421452c 100644
--- a/server/sonar-ui-common/components/controls/__tests__/InputValidationField-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/InputValidationField-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ListFooter-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ListFooter-test.tsx
index 6ea69c990ae..8970e984359 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ListFooter-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ListFooter-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ModalButton-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ModalButton-test.tsx
index 91756df5a55..490609803a7 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ModalButton-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ModalButton-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ModalValidationField-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ModalValidationField-test.tsx
index 1f5cbb5b7e3..27f9743870d 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ModalValidationField-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ModalValidationField-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/OutsideClickHandler-test.tsx b/server/sonar-ui-common/components/controls/__tests__/OutsideClickHandler-test.tsx
new file mode 100644
index 00000000000..4f540f59fec
--- /dev/null
+++ b/server/sonar-ui-common/components/controls/__tests__/OutsideClickHandler-test.tsx
@@ -0,0 +1,74 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 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 { mount, shallow } from 'enzyme';
+import * as React from 'react';
+import OutsideClickHandler from '../OutsideClickHandler';
+
+jest.useFakeTimers();
+
+it('should render correctly', () => {
+ expect(shallowRender()).toMatchSnapshot();
+});
+
+it('should register for click event', () => {
+ const addEventListener = jest.spyOn(window, 'addEventListener');
+ const removeEventListener = jest.spyOn(window, 'removeEventListener');
+
+ const wrapper = shallowRender();
+
+ jest.runAllTimers();
+
+ expect(addEventListener).toHaveBeenCalledWith('click', expect.anything());
+
+ wrapper.instance().componentWillUnmount();
+
+ expect(removeEventListener).toHaveBeenCalledWith('click', expect.anything());
+});
+
+it('should call event handler on click on window', () => {
+ const onClickOutside = jest.fn();
+
+ const map: { [key: string]: EventListener } = {};
+ window.addEventListener = jest.fn((event, callback) => {
+ map[event] = callback as EventListener;
+ });
+
+ mount(
+ <div id="outside-element">
+ <OutsideClickHandler onClickOutside={onClickOutside}>
+ <div id="children" />
+ </OutsideClickHandler>
+ </div>
+ );
+
+ jest.runAllTimers();
+
+ map['click'](new Event('click'));
+ expect(onClickOutside).toHaveBeenCalled();
+});
+
+function shallowRender(props: Partial<OutsideClickHandler['props']> = {}) {
+ return shallow<OutsideClickHandler>(
+ <OutsideClickHandler onClickOutside={jest.fn()} {...props}>
+ <div id="children" />
+ </OutsideClickHandler>
+ );
+}
diff --git a/server/sonar-ui-common/components/controls/__tests__/Radio-test.tsx b/server/sonar-ui-common/components/controls/__tests__/Radio-test.tsx
index feb1a6e060e..60d2050a45d 100644
--- a/server/sonar-ui-common/components/controls/__tests__/Radio-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/Radio-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/RadioCard-test.tsx b/server/sonar-ui-common/components/controls/__tests__/RadioCard-test.tsx
index 27ed8f6eadc..2232f38b252 100644
--- a/server/sonar-ui-common/components/controls/__tests__/RadioCard-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/RadioCard-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/RadioToggle-test.tsx b/server/sonar-ui-common/components/controls/__tests__/RadioToggle-test.tsx
index 6d5aa2e5840..3653374e31a 100644
--- a/server/sonar-ui-common/components/controls/__tests__/RadioToggle-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/RadioToggle-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ReloadButton-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ReloadButton-test.tsx
index f6a92859d69..c22fd1f313e 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ReloadButton-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ReloadButton-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -17,7 +17,6 @@
* 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 testTheme from '../../../config/jest/testTheme';
diff --git a/server/sonar-ui-common/components/controls/__tests__/ScreenPositionFixer-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ScreenPositionFixer-test.tsx
index aae3a9e0cc3..f857666cecd 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ScreenPositionFixer-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ScreenPositionFixer-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -19,11 +19,12 @@
*/
import { mount } from 'enzyme';
import * as React from 'react';
+import testTheme from '../../../config/jest/testTheme';
import { resizeWindowTo, setNodeRect } from '../../../helpers/testUtils';
-import ScreenPositionFixer from '../ScreenPositionFixer';
+import { ScreenPositionFixer } from '../ScreenPositionFixer';
jest.mock('lodash', () => {
- const lodash = require.requireActual('lodash');
+ const lodash = jest.requireActual('lodash');
lodash.throttle = (fn: any) => () => fn();
return lodash;
});
@@ -88,6 +89,7 @@ it('should re-position when window is resized', () => {
expect(children).toHaveBeenCalledTimes(3);
});
-function mountRender(props: ScreenPositionFixer['props']) {
- return mount(<ScreenPositionFixer {...props} />);
+function mountRender(props: Partial<ScreenPositionFixer['props']>) {
+ // eslint-disable-next-line react/no-children-prop
+ return mount(<ScreenPositionFixer theme={testTheme} children={() => <div />} {...props} />);
}
diff --git a/server/sonar-ui-common/components/controls/__tests__/SearchBox-test.tsx b/server/sonar-ui-common/components/controls/__tests__/SearchBox-test.tsx
index aaed9ed16c0..7afa1839c5f 100644
--- a/server/sonar-ui-common/components/controls/__tests__/SearchBox-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/SearchBox-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/SearchSelect-test.tsx b/server/sonar-ui-common/components/controls/__tests__/SearchSelect-test.tsx
index 71ca3e79932..ed13eea6fa7 100644
--- a/server/sonar-ui-common/components/controls/__tests__/SearchSelect-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/SearchSelect-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/SelectList-test.tsx b/server/sonar-ui-common/components/controls/__tests__/SelectList-test.tsx
index e4a4ed22346..ab3eb4f8072 100644
--- a/server/sonar-ui-common/components/controls/__tests__/SelectList-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/SelectList-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/SelectListListContainer-test.tsx b/server/sonar-ui-common/components/controls/__tests__/SelectListListContainer-test.tsx
index 61d53f4825f..1b24bc866c1 100644
--- a/server/sonar-ui-common/components/controls/__tests__/SelectListListContainer-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/SelectListListContainer-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/SelectListListElement-test.tsx b/server/sonar-ui-common/components/controls/__tests__/SelectListListElement-test.tsx
index 82a1a40455c..ca127222e04 100644
--- a/server/sonar-ui-common/components/controls/__tests__/SelectListListElement-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/SelectListListElement-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/SimpleModal-test.tsx b/server/sonar-ui-common/components/controls/__tests__/SimpleModal-test.tsx
index 6b5271450fb..5a8e6bb0cd7 100644
--- a/server/sonar-ui-common/components/controls/__tests__/SimpleModal-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/SimpleModal-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/Tabs-test.tsx b/server/sonar-ui-common/components/controls/__tests__/Tabs-test.tsx
index 7db674a16db..11cf4e5e353 100644
--- a/server/sonar-ui-common/components/controls/__tests__/Tabs-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/Tabs-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/Toggle-test.tsx b/server/sonar-ui-common/components/controls/__tests__/Toggle-test.tsx
index 79fc605afb3..f3e39aca5df 100644
--- a/server/sonar-ui-common/components/controls/__tests__/Toggle-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/Toggle-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -17,7 +17,6 @@
* 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 { click } from '../../../helpers/testUtils';
diff --git a/server/sonar-ui-common/components/controls/__tests__/Toggler-test.tsx b/server/sonar-ui-common/components/controls/__tests__/Toggler-test.tsx
index dfcbe6b0b9a..679177cfda3 100644
--- a/server/sonar-ui-common/components/controls/__tests__/Toggler-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/Toggler-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/Tooltip-test.tsx b/server/sonar-ui-common/components/controls/__tests__/Tooltip-test.tsx
index d490fd5179c..e2a395b609e 100644
--- a/server/sonar-ui-common/components/controls/__tests__/Tooltip-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/Tooltip-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -19,24 +19,20 @@
*/
import { shallow } from 'enzyme';
import * as React from 'react';
-import Tooltip, { TooltipInner } from '../Tooltip';
+import Tooltip, { TooltipInner, TooltipProps } from '../Tooltip';
jest.useFakeTimers();
jest.mock('react-dom', () => {
- const actual = require.requireActual('react-dom');
+ const actual = jest.requireActual('react-dom');
return Object.assign({}, actual, {
- findDOMNode: () => undefined,
+ findDOMNode: jest.fn().mockReturnValue(undefined),
});
});
+beforeEach(jest.clearAllMocks);
+
it('should render', () => {
- expect(
- shallow(
- <TooltipInner overlay={<span id="overlay" />} visible={false}>
- <div id="tooltip" />
- </TooltipInner>
- )
- ).toMatchSnapshot();
+ expect(shallowRenderTooltipInner()).toMatchSnapshot();
expect(
shallow(
<TooltipInner overlay={<span id="overlay" />} visible={true}>
@@ -50,11 +46,8 @@ it('should render', () => {
it('should open & close', () => {
const onShow = jest.fn();
const onHide = jest.fn();
- const wrapper = shallow(
- <TooltipInner onHide={onHide} onShow={onShow} overlay={<span id="overlay" />}>
- <div id="tooltip" />
- </TooltipInner>
- );
+ const wrapper = shallowRenderTooltipInner({ onHide, onShow });
+
wrapper.find('#tooltip').simulate('mouseenter');
jest.runOnlyPendingTimers();
wrapper.update();
@@ -71,11 +64,7 @@ it('should open & close', () => {
it('should not open when mouse goes away quickly', () => {
const onShow = jest.fn();
const onHide = jest.fn();
- const wrapper = shallow(
- <TooltipInner onHide={onHide} onShow={onShow} overlay={<span id="overlay" />}>
- <div id="tooltip" />
- </TooltipInner>
- );
+ const wrapper = shallowRenderTooltipInner({ onHide, onShow });
wrapper.find('#tooltip').simulate('mouseenter');
wrapper.find('#tooltip').simulate('mouseleave');
@@ -86,27 +75,44 @@ it('should not open when mouse goes away quickly', () => {
});
it('should not render tooltip without overlay', () => {
- const wrapper = shallow(
- <Tooltip overlay={undefined}>
- <div id="tooltip" />
- </Tooltip>
- );
+ const wrapper = shallowRenderTooltip();
expect(wrapper.type()).toBe('div');
});
it('should not render empty tooltips', () => {
- expect(
- shallow(
- <Tooltip overlay={undefined} visible={true}>
- <div id="tooltip" />
- </Tooltip>
- )
- ).toMatchSnapshot();
- expect(
- shallow(
- <Tooltip overlay="" visible={true}>
- <div id="tooltip" />
- </Tooltip>
- )
- ).toMatchSnapshot();
+ expect(shallowRenderTooltip()).toMatchSnapshot();
+ expect(shallowRenderTooltip()).toMatchSnapshot();
});
+
+it('should adjust arrow position', () => {
+ const wrapper = shallowRenderTooltipInner();
+
+ expect(wrapper.instance().adjustArrowPosition('left', { leftFix: 10, topFix: 20 })).toEqual({
+ marginTop: -20,
+ });
+ expect(wrapper.instance().adjustArrowPosition('right', { leftFix: 10, topFix: 20 })).toEqual({
+ marginTop: -20,
+ });
+ expect(wrapper.instance().adjustArrowPosition('top', { leftFix: 10, topFix: 20 })).toEqual({
+ marginLeft: -10,
+ });
+ expect(wrapper.instance().adjustArrowPosition('bottom', { leftFix: 10, topFix: 20 })).toEqual({
+ marginLeft: -10,
+ });
+});
+
+function shallowRenderTooltip() {
+ return shallow<TooltipProps>(
+ <Tooltip overlay={undefined}>
+ <div id="tooltip" />
+ </Tooltip>
+ );
+}
+
+function shallowRenderTooltipInner(props?: Partial<TooltipProps>) {
+ return shallow<TooltipInner>(
+ <TooltipInner overlay={<span id="overlay" />} {...props}>
+ <div id="tooltip" />
+ </TooltipInner>
+ );
+}
diff --git a/server/sonar-ui-common/components/controls/__tests__/ValidationForm-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ValidationForm-test.tsx
index 295967f7ed0..64827f932ed 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ValidationForm-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ValidationForm-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ValidationInput-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ValidationInput-test.tsx
index 716978090da..97d4a2a5937 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ValidationInput-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ValidationInput-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/ValidationModal-test.tsx b/server/sonar-ui-common/components/controls/__tests__/ValidationModal-test.tsx
index 810b864c8b2..e3825083577 100644
--- a/server/sonar-ui-common/components/controls/__tests__/ValidationModal-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/ValidationModal-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/__snapshots__/OutsideClickHandler-test.tsx.snap b/server/sonar-ui-common/components/controls/__tests__/__snapshots__/OutsideClickHandler-test.tsx.snap
new file mode 100644
index 00000000000..a4f533d8e3a
--- /dev/null
+++ b/server/sonar-ui-common/components/controls/__tests__/__snapshots__/OutsideClickHandler-test.tsx.snap
@@ -0,0 +1,7 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<div
+ id="children"
+/>
+`;
diff --git a/server/sonar-ui-common/components/controls/__tests__/buttons-test.tsx b/server/sonar-ui-common/components/controls/__tests__/buttons-test.tsx
index 59e554f972c..c199c5778cc 100644
--- a/server/sonar-ui-common/components/controls/__tests__/buttons-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/buttons-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
diff --git a/server/sonar-ui-common/components/controls/__tests__/clipboard-test.tsx b/server/sonar-ui-common/components/controls/__tests__/clipboard-test.tsx
index 0563651027e..36b2d6f02db 100644
--- a/server/sonar-ui-common/components/controls/__tests__/clipboard-test.tsx
+++ b/server/sonar-ui-common/components/controls/__tests__/clipboard-test.tsx
@@ -1,6 +1,6 @@
/*
- * Sonar UI Common
- * Copyright (C) 2019-2020 SonarSource SA
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
@@ -69,11 +69,11 @@ describe('ClipboardBase', () => {
});
function shallowRender(children?: ClipboardBase['props']['children']) {
- return shallow<ClipboardBase>(<ClipboardBase>{children}</ClipboardBase>);
+ return shallow<ClipboardBase>(<ClipboardBase>{children || (() => null)}</ClipboardBase>);
}
function mountRender(children?: ClipboardBase['props']['children']) {
- return mount<ClipboardBase>(<ClipboardBase>{children}</ClipboardBase>);
+ return mount<ClipboardBase>(<ClipboardBase>{children || (() => null)}</ClipboardBase>);
}
});