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()
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({
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',
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');
});
import { Location } from 'history';
import { shallow } from 'enzyme';
import { CreateOrganization } from '../CreateOrganization';
-import { mockRouter, waitAndUpdate } from '../../../../helpers/testUtils';
import {
getAlmAppInfo,
getAlmOrganization,
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
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();
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({
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' },
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()
*/
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' };
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();
});
*/
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' };
it('should correctly handle user interactions', () => {
const removeMember = jest.fn();
- const wrapper = shallow(
+ const wrapper = shallow<RemoveMemberForm>(
<RemoveMemberForm
member={member}
onClose={jest.fn()}
removeMember={removeMember}
/>
);
- (wrapper.instance() as RemoveMemberForm).handleSubmit(mockEvent as any);
+ wrapper.instance().handleSubmit(mockEvent());
expect(removeMember).toBeCalledWith({
avatar: '',
groupCount: 3,
mockCurrentUser,
mockOrganization,
mockComponent
-} from '../../../../helpers/testUtils';
+} from '../../../../helpers/testMocks';
it('should render correctly', () => {
const wrapper = shallowRender();
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: {
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();
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', () => ({
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,
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;
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,
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(
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();
+++ /dev/null
-/*
- * 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
- };
-}
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[];
--- /dev/null
+/*
+ * 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;
+}
* 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
// 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));
}
}
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
- };
-}