diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2019-02-05 09:01:11 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-02-11 09:11:44 +0100 |
commit | 7dadf3959310e9693c8ee7e32d5c3ff09d8235c5 (patch) | |
tree | a61adaa6eb8d100f15b351efaf143816f4609b15 /server/sonar-web/src/main/js/helpers/testUtils.ts | |
parent | 8405a5d9e7e4c2cad0411bf331954bce339c6589 (diff) | |
download | sonarqube-7dadf3959310e9693c8ee7e32d5c3ff09d8235c5.tar.gz sonarqube-7dadf3959310e9693c8ee7e32d5c3ff09d8235c5.zip |
Split test utils and mocks, better type mocks
Diffstat (limited to 'server/sonar-web/src/main/js/helpers/testUtils.ts')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/testUtils.ts | 88 |
1 files changed, 2 insertions, 86 deletions
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 - }; -} |