aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/code/components/__tests__/App-test.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/create/organization/__tests__/RemoteOrganizationChoose-test.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/create/project/__tests__/OrganizationInput-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/feedback/downgrade/__tests__/DowngradeFeedback-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaContainer-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaTags-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ExtendProfileForm-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx4
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/EvolutionDeprecated-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/ProfilesListHeader-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/quality-profiles/testUtils.ts39
-rw-r--r--server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx3
-rw-r--r--server/sonar-web/src/main/js/helpers/testMocks.ts126
-rw-r--r--server/sonar-web/src/main/js/helpers/testUtils.ts88
23 files changed, 159 insertions, 150 deletions
diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx
index ebf026271f9..ac376d0a8dc 100644
--- a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavPlus-test.tsx
@@ -21,7 +21,8 @@ import * as React from 'react';
import { shallow, ShallowWrapper } from 'enzyme';
import { GlobalNavPlus } from '../GlobalNavPlus';
import { isSonarCloud } from '../../../../../helpers/system';
-import { click, mockRouter } from '../../../../../helpers/testUtils';
+import { mockRouter } from '../../../../../helpers/testMocks';
+import { click } from '../../../../../helpers/testUtils';
jest.mock('../../../../../helpers/system', () => ({
isSonarCloud: jest.fn()
diff --git a/server/sonar-web/src/main/js/apps/code/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/code/components/__tests__/App-test.tsx
index dcb2a2ddc70..6fde0de8f03 100644
--- a/server/sonar-web/src/main/js/apps/code/components/__tests__/App-test.tsx
+++ b/server/sonar-web/src/main/js/apps/code/components/__tests__/App-test.tsx
@@ -20,8 +20,9 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { App } from '../App';
-import { waitAndUpdate, mockRouter } from '../../../../helpers/testUtils';
import { retrieveComponent } from '../../utils';
+import { mockRouter } from '../../../../helpers/testMocks';
+import { waitAndUpdate } from '../../../../helpers/testUtils';
jest.mock('../../utils', () => ({
retrieveComponent: jest.fn().mockResolvedValue({
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx
index 2a3638e327f..2b220a43753 100644
--- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx
+++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx
@@ -20,7 +20,7 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import RuleListItem from '../RuleListItem';
-import { mockEvent } from '../../../../helpers/testUtils';
+import { mockEvent } from '../../../../helpers/testMocks';
const rule: T.Rule = {
key: 'foo',
@@ -41,7 +41,7 @@ it('should render', () => {
it('should open rule', () => {
const onOpen = jest.fn();
const wrapper = shallowRender({ onOpen });
- wrapper.find('Link').prop<Function>('onClick')({ ...mockEvent, button: 0 });
+ wrapper.find('Link').prop<Function>('onClick')(mockEvent({ button: 0 }));
expect(onOpen).toBeCalledWith('foo');
});
diff --git a/server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx b/server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx
index d390eb2c3ec..1537668a8fb 100644
--- a/server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx
+++ b/server/sonar-web/src/main/js/apps/create/organization/__tests__/CreateOrganization-test.tsx
@@ -22,7 +22,6 @@ import { times } from 'lodash';
import { Location } from 'history';
import { shallow } from 'enzyme';
import { CreateOrganization } from '../CreateOrganization';
-import { mockRouter, waitAndUpdate } from '../../../../helpers/testUtils';
import {
getAlmAppInfo,
getAlmOrganization,
@@ -31,6 +30,8 @@ import {
import { getSubscriptionPlans } from '../../../../api/billing';
import { getOrganizations } from '../../../../api/organizations';
import { get, remove } from '../../../../helpers/storage';
+import { mockRouter } from '../../../../helpers/testMocks';
+import { waitAndUpdate } from '../../../../helpers/testUtils';
jest.mock('../../../../api/billing', () => ({
getSubscriptionPlans: jest
diff --git a/server/sonar-web/src/main/js/apps/create/organization/__tests__/RemoteOrganizationChoose-test.tsx b/server/sonar-web/src/main/js/apps/create/organization/__tests__/RemoteOrganizationChoose-test.tsx
index e83d7cbd879..d2e35c6371c 100644
--- a/server/sonar-web/src/main/js/apps/create/organization/__tests__/RemoteOrganizationChoose-test.tsx
+++ b/server/sonar-web/src/main/js/apps/create/organization/__tests__/RemoteOrganizationChoose-test.tsx
@@ -20,7 +20,8 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { RemoteOrganizationChoose } from '../RemoteOrganizationChoose';
-import { mockRouter, submit } from '../../../../helpers/testUtils';
+import { mockRouter } from '../../../../helpers/testMocks';
+import { submit } from '../../../../helpers/testUtils';
it('should render', () => {
expect(shallowRender()).toMatchSnapshot();
diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx
index 4b008c90294..9e1a6e66803 100644
--- a/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx
+++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/CreateProjectPageSonarCloud-test.tsx
@@ -20,8 +20,9 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { CreateProjectPageSonarCloud } from '../CreateProjectPageSonarCloud';
-import { waitAndUpdate, mockRouter } from '../../../../helpers/testUtils';
import { getAlmAppInfo } from '../../../../api/alm-integration';
+import { mockRouter } from '../../../../helpers/testMocks';
+import { waitAndUpdate } from '../../../../helpers/testUtils';
jest.mock('../../../../api/alm-integration', () => ({
getAlmAppInfo: jest.fn().mockResolvedValue({
diff --git a/server/sonar-web/src/main/js/apps/create/project/__tests__/OrganizationInput-test.tsx b/server/sonar-web/src/main/js/apps/create/project/__tests__/OrganizationInput-test.tsx
index 73cc14fd429..44a1183baed 100644
--- a/server/sonar-web/src/main/js/apps/create/project/__tests__/OrganizationInput-test.tsx
+++ b/server/sonar-web/src/main/js/apps/create/project/__tests__/OrganizationInput-test.tsx
@@ -20,7 +20,7 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { OrganizationInput } from '../OrganizationInput';
-import { mockRouter } from '../../../../helpers/testUtils';
+import { mockRouter } from '../../../../helpers/testMocks';
const organizations = [
{ key: 'foo', name: 'Foo' },
diff --git a/server/sonar-web/src/main/js/apps/feedback/downgrade/__tests__/DowngradeFeedback-test.tsx b/server/sonar-web/src/main/js/apps/feedback/downgrade/__tests__/DowngradeFeedback-test.tsx
index df1946a7f98..efbaf193e6e 100644
--- a/server/sonar-web/src/main/js/apps/feedback/downgrade/__tests__/DowngradeFeedback-test.tsx
+++ b/server/sonar-web/src/main/js/apps/feedback/downgrade/__tests__/DowngradeFeedback-test.tsx
@@ -21,7 +21,7 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import DowngradeFeedback, { LocationState } from '../DowngradeFeedback';
import { giveDowngradeFeedback } from '../../../../api/billing';
-import { mockRouter, mockLocation } from '../../../../helpers/testUtils';
+import { mockLocation, mockRouter } from '../../../../helpers/testMocks';
jest.mock('../../../../api/billing', () => ({
giveDowngradeFeedback: jest.fn()
diff --git a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx
index 615a785ed43..a412a1b679f 100644
--- a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx
+++ b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/ManageMemberGroupsForm-test.tsx
@@ -19,8 +19,8 @@
*/
import * as React from 'react';
import { shallow } from 'enzyme';
-import { mockEvent } from '../../../helpers/testUtils';
import ManageMemberGroupsForm from '../ManageMemberGroupsForm';
+import { mockEvent } from '../../../helpers/testMocks';
const member = { login: 'admin', name: 'Admin Istrator', avatar: '', groupCount: 3 };
const organization = { name: 'MyOrg', key: 'myorg' };
@@ -95,7 +95,7 @@ it('should correctly handle the submit event and close the modal', () => {
const instance = form.instance as ManageMemberGroupsForm;
instance.onCheck('11', false);
instance.onCheck('7', true);
- instance.handleSubmit(mockEvent as any);
+ instance.handleSubmit(mockEvent());
expect(updateMemberGroups.mock.calls).toMatchSnapshot();
expect(form.wrapper.state()).toMatchSnapshot();
});
diff --git a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx
index d9fdf2ace77..6e7caf42f18 100644
--- a/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx
+++ b/server/sonar-web/src/main/js/apps/organizationMembers/__tests__/RemoveMemberForm-test.tsx
@@ -19,8 +19,8 @@
*/
import * as React from 'react';
import { shallow } from 'enzyme';
-import { mockEvent } from '../../../helpers/testUtils';
import RemoveMemberForm from '../RemoveMemberForm';
+import { mockEvent } from '../../../helpers/testMocks';
const member = { login: 'admin', name: 'Admin Istrator', avatar: '', groupCount: 3 };
const organization = { key: 'myorg', name: 'MyOrg' };
@@ -39,7 +39,7 @@ it('should render ', () => {
it('should correctly handle user interactions', () => {
const removeMember = jest.fn();
- const wrapper = shallow(
+ const wrapper = shallow<RemoveMemberForm>(
<RemoveMemberForm
member={member}
onClose={jest.fn()}
@@ -47,7 +47,7 @@ it('should correctly handle user interactions', () => {
removeMember={removeMember}
/>
);
- (wrapper.instance() as RemoveMemberForm).handleSubmit(mockEvent as any);
+ wrapper.instance().handleSubmit(mockEvent());
expect(removeMember).toBeCalledWith({
avatar: '',
groupCount: 3,
diff --git a/server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaContainer-test.tsx b/server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaContainer-test.tsx
index 75f8c53fe40..5a1378797e5 100644
--- a/server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaContainer-test.tsx
+++ b/server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaContainer-test.tsx
@@ -25,7 +25,7 @@ import {
mockCurrentUser,
mockOrganization,
mockComponent
-} from '../../../../helpers/testUtils';
+} from '../../../../helpers/testMocks';
it('should render correctly', () => {
const wrapper = shallowRender();
diff --git a/server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaTags-test.tsx b/server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaTags-test.tsx
index e601f094276..c3b32b28fa5 100644
--- a/server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaTags-test.tsx
+++ b/server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaTags-test.tsx
@@ -20,7 +20,7 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import MetaTags from '../MetaTags';
-import { mockComponent } from '../../../../helpers/testUtils';
+import { mockComponent } from '../../../../helpers/testMocks';
const component = mockComponent({
configuration: {
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.tsx
index 14f71216a8b..514a7acd2d0 100644
--- a/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.tsx
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/compare/__tests__/ComparisonForm-test.tsx
@@ -20,7 +20,7 @@
import { shallow } from 'enzyme';
import * as React from 'react';
import ComparisonForm from '../ComparisonForm';
-import { mockQualityProfile } from '../../testUtils';
+import { mockQualityProfile } from '../../../../helpers/testMocks';
it('should render Select with right options', () => {
const profile = mockQualityProfile();
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ExtendProfileForm-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ExtendProfileForm-test.tsx
index 167a27703c8..457e9b503c5 100644
--- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ExtendProfileForm-test.tsx
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ExtendProfileForm-test.tsx
@@ -21,7 +21,7 @@ import * as React from 'react';
import { shallow } from 'enzyme';
import ExtendProfileForm from '../ExtendProfileForm';
import { createQualityProfile, changeProfileParent } from '../../../../api/quality-profiles';
-import { mockQualityProfile } from '../../testUtils';
+import { mockQualityProfile } from '../../../../helpers/testMocks';
import { click } from '../../../../helpers/testUtils';
jest.mock('../../../../api/quality-profiles', () => ({
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx
index 8b4bfdd4c6b..badae2e66a0 100644
--- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileActions-test.tsx
@@ -20,8 +20,8 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { ProfileActions } from '../ProfileActions';
-import { click, waitAndUpdate, mockRouter } from '../../../../helpers/testUtils';
-import { mockQualityProfile } from '../../testUtils';
+import { mockQualityProfile, mockRouter } from '../../../../helpers/testMocks';
+import { click, waitAndUpdate } from '../../../../helpers/testUtils';
const PROFILE = mockQualityProfile({
activeRuleCount: 68,
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.tsx
index 41fad58dc06..20aae44fc0b 100644
--- a/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.tsx
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/__tests__/ProfileContainer-test.tsx
@@ -24,7 +24,7 @@ import { WithRouterProps } from 'react-router';
import ProfileContainer from '../ProfileContainer';
import ProfileNotFound from '../ProfileNotFound';
import ProfileHeader from '../../details/ProfileHeader';
-import { mockQualityProfile } from '../../testUtils';
+import { mockQualityProfile } from '../../../../helpers/testMocks';
const routerProps = { router: {} } as WithRouterProps;
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx
index a273f9a19a8..f7a9b045ea1 100644
--- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx
@@ -22,8 +22,8 @@ import { shallow } from 'enzyme';
import ProfileRules from '../ProfileRules';
import * as apiRules from '../../../../api/rules';
import * as apiQP from '../../../../api/quality-profiles';
+import { mockQualityProfile } from '../../../../helpers/testMocks';
import { waitAndUpdate } from '../../../../helpers/testUtils';
-import { mockQualityProfile } from '../../testUtils';
const PROFILE = mockQualityProfile({
activeRuleCount: 68,
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/EvolutionDeprecated-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/EvolutionDeprecated-test.tsx
index 3a1a0bb3204..ae320ce8ef7 100644
--- a/server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/EvolutionDeprecated-test.tsx
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/EvolutionDeprecated-test.tsx
@@ -20,7 +20,7 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import EvolutionDeprecated from '../EvolutionDeprecated';
-import { mockQualityProfile } from '../../testUtils';
+import { mockQualityProfile } from '../../../../helpers/testMocks';
it('should render correctly', () => {
const wrapper = shallow(
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/ProfilesListHeader-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/ProfilesListHeader-test.tsx
index d7c8aa2b3bf..377d9a8b016 100644
--- a/server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/ProfilesListHeader-test.tsx
+++ b/server/sonar-web/src/main/js/apps/quality-profiles/home/__tests__/ProfilesListHeader-test.tsx
@@ -20,7 +20,7 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { ProfilesListHeader } from '../ProfilesListHeader';
-import { mockRouter } from '../../../../helpers/testUtils';
+import { mockRouter } from '../../../../helpers/testMocks';
it('should render correctly', () => {
const wrapper = shallowRender();
diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/testUtils.ts b/server/sonar-web/src/main/js/apps/quality-profiles/testUtils.ts
deleted file mode 100644
index d944ce07c5d..00000000000
--- a/server/sonar-web/src/main/js/apps/quality-profiles/testUtils.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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 { Profile } from './types';
-
-export function mockQualityProfile(overrides = {}): Profile {
- return {
- activeDeprecatedRuleCount: 2,
- activeRuleCount: 10,
- childrenCount: 0,
- depth: 1,
- isBuiltIn: false,
- isDefault: false,
- isInherited: false,
- key: 'key',
- language: 'js',
- languageName: 'JavaScript',
- name: 'name',
- projectCount: 3,
- organization: 'foo',
- ...overrides
- };
-}
diff --git a/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx b/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx
index 1c863aedd75..ffab89a8596 100644
--- a/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx
+++ b/server/sonar-web/src/main/js/components/hoc/__tests__/withKeyboardNavigation-test.tsx
@@ -20,7 +20,8 @@
import * as React from 'react';
import { mount, shallow } from 'enzyme';
import withKeyboardNavigation, { WithKeyboardNavigationProps } from '../withKeyboardNavigation';
-import { mockComponent, keydown, KEYCODE_MAP } from '../../../helpers/testUtils';
+import { mockComponent } from '../../../helpers/testMocks';
+import { keydown, KEYCODE_MAP } from '../../../helpers/testUtils';
class X extends React.Component<{
components?: T.ComponentMeasure[];
diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts
new file mode 100644
index 00000000000..daa961765ab
--- /dev/null
+++ b/server/sonar-web/src/main/js/helpers/testMocks.ts
@@ -0,0 +1,126 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 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 { InjectedRouter } from 'react-router';
+import { Location } from 'history';
+import { Profile } from '../apps/quality-profiles/types';
+
+export function mockAppState(overrides: Partial<T.AppState> = {}): T.AppState {
+ return {
+ defaultOrganization: 'foo',
+ edition: 'community',
+ productionDatabase: true,
+ qualifiers: ['TRK'],
+ settings: {},
+ version: '1.0',
+ ...overrides
+ };
+}
+
+export function mockComponent(overrides: Partial<T.Component> = {}): T.Component {
+ return {
+ breadcrumbs: [],
+ key: 'my-project',
+ name: 'MyProject',
+ organization: 'foo',
+ qualifier: 'TRK',
+ qualityGate: { isDefault: true, key: '30', name: 'Sonar way' },
+ qualityProfiles: [
+ {
+ deleted: false,
+ key: 'my-qp',
+ language: 'ts',
+ name: 'Sonar way'
+ }
+ ],
+ tags: [],
+ ...overrides
+ };
+}
+
+export function mockCurrentUser(overrides: Partial<T.CurrentUser> = {}): T.CurrentUser {
+ return {
+ isLoggedIn: true,
+ ...overrides
+ };
+}
+
+export function mockEvent(overrides = {}) {
+ return {
+ target: { blur() {} },
+ currentTarget: { blur() {} },
+ preventDefault() {},
+ stopPropagation() {},
+ ...overrides
+ } as any;
+}
+
+export function mockLocation(overrides: Partial<Location> = {}): Location {
+ return {
+ action: 'PUSH',
+ key: 'key',
+ pathname: '/path',
+ query: {},
+ search: '',
+ state: {},
+ ...overrides
+ };
+}
+
+export function mockOrganization(overrides: Partial<T.Organization> = {}): T.Organization {
+ return {
+ key: 'foo',
+ name: 'Foo',
+ ...overrides
+ };
+}
+
+export function mockQualityProfile(overrides: Partial<Profile> = {}): Profile {
+ return {
+ activeDeprecatedRuleCount: 2,
+ activeRuleCount: 10,
+ childrenCount: 0,
+ depth: 1,
+ isBuiltIn: false,
+ isDefault: false,
+ isInherited: false,
+ key: 'key',
+ language: 'js',
+ languageName: 'JavaScript',
+ name: 'name',
+ projectCount: 3,
+ organization: 'foo',
+ ...overrides
+ };
+}
+
+export function mockRouter(overrides: { push?: Function; replace?: Function } = {}) {
+ return {
+ createHref: jest.fn(),
+ createPath: jest.fn(),
+ go: jest.fn(),
+ goBack: jest.fn(),
+ goForward: jest.fn(),
+ isActive: jest.fn(),
+ push: jest.fn(),
+ replace: jest.fn(),
+ setRouteLeaveHook: jest.fn(),
+ ...overrides
+ } as InjectedRouter;
+}
diff --git a/server/sonar-web/src/main/js/helpers/testUtils.ts b/server/sonar-web/src/main/js/helpers/testUtils.ts
index 8e376ea5853..065bba4e340 100644
--- a/server/sonar-web/src/main/js/helpers/testUtils.ts
+++ b/server/sonar-web/src/main/js/helpers/testUtils.ts
@@ -18,16 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { ShallowWrapper, ReactWrapper } from 'enzyme';
-import { InjectedRouter } from 'react-router';
-import { Location } from 'history';
-import { EditionKey } from '../apps/marketplace/utils';
-
-export const mockEvent = {
- target: { blur() {} },
- currentTarget: { blur() {} },
- preventDefault() {},
- stopPropagation() {}
-};
+import { mockEvent } from './testMocks';
export function click(element: ShallowWrapper | ReactWrapper, event = {}): void {
// `type()` returns a component constructor for a composite element and string for DOM nodes
@@ -37,7 +28,7 @@ export function click(element: ShallowWrapper | ReactWrapper, event = {}): void
// https://github.com/airbnb/enzyme/blob/master/packages/enzyme/src/ReactWrapper.js#L109
(element as any).root().update();
} else {
- element.simulate('click', { ...mockEvent, ...event });
+ element.simulate('click', mockEvent(event));
}
}
@@ -152,78 +143,3 @@ export async function waitAndUpdate(wrapper: ShallowWrapper<any, any> | ReactWra
await new Promise(setImmediate);
wrapper.update();
}
-
-export function mockLocation(overrides = {}): Location {
- return {
- action: 'PUSH',
- key: 'key',
- pathname: '/path',
- query: {},
- search: '',
- state: {},
- ...overrides
- };
-}
-
-export function mockRouter(overrides: { push?: Function; replace?: Function } = {}) {
- return {
- createHref: jest.fn(),
- createPath: jest.fn(),
- go: jest.fn(),
- goBack: jest.fn(),
- goForward: jest.fn(),
- isActive: jest.fn(),
- push: jest.fn(),
- replace: jest.fn(),
- setRouteLeaveHook: jest.fn(),
- ...overrides
- } as InjectedRouter;
-}
-
-export function mockAppState(overrides = {}): T.AppState {
- return {
- defaultOrganization: 'foo',
- edition: EditionKey.community,
- productionDatabase: true,
- qualifiers: ['TRK'],
- settings: {},
- version: '1.0',
- ...overrides
- };
-}
-
-export function mockComponent(overrides = {}): T.Component {
- return {
- breadcrumbs: [],
- key: 'my-project',
- name: 'MyProject',
- organization: 'foo',
- qualifier: 'TRK',
- qualityGate: { isDefault: true, key: '30', name: 'Sonar way' },
- qualityProfiles: [
- {
- deleted: false,
- key: 'my-qp',
- language: 'ts',
- name: 'Sonar way'
- }
- ],
- tags: [],
- ...overrides
- };
-}
-
-export function mockCurrentUser(overrides = {}): T.CurrentUser {
- return {
- isLoggedIn: true,
- ...overrides
- };
-}
-
-export function mockOrganization(overrides = {}): T.Organization {
- return {
- key: 'foo',
- name: 'Foo',
- ...overrides
- };
-}