diff options
Diffstat (limited to 'server/sonar-web/src/main/js/helpers/testMocks.ts')
-rw-r--r-- | server/sonar-web/src/main/js/helpers/testMocks.ts | 118 |
1 files changed, 76 insertions, 42 deletions
diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index bd37528c205..a6e20a88178 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -21,6 +21,17 @@ import { InjectedRouter } from 'react-router'; import { Location } from 'history'; import { Profile } from '../apps/quality-profiles/types'; +export function mockAlmApplication(overrides: Partial<T.AlmApplication> = {}): T.AlmApplication { + return { + backgroundColor: '#0052CC', + iconPath: '"/static/authbitbucket/bitbucket.svg"', + installationUrl: 'https://bitbucket.org/install/app', + key: 'bitbucket', + name: 'BitBucket', + ...overrides + }; +} + export function mockAlmOrganization(overrides: Partial<T.AlmOrganization> = {}): T.AlmOrganization { return { avatar: 'http://example.com/avatar', @@ -90,6 +101,52 @@ export function mockEvent(overrides = {}) { } as any; } +export function mockIssue(withLocations = false, overrides: Partial<T.Issue> = {}) { + const issue: T.Issue = { + actions: [], + component: 'main.js', + componentLongName: 'main.js', + componentQualifier: 'FIL', + componentUuid: 'foo1234', + creationDate: '2017-03-01T09:36:01+0100', + flows: [], + fromHotspot: false, + key: 'AVsae-CQS-9G3txfbFN2', + line: 25, + message: 'Reduce the number of conditional operators (4) used in the expression', + organization: 'myorg', + project: 'myproject', + projectKey: 'foo', + projectName: 'Foo', + projectOrganization: 'org', + rule: 'javascript:S1067', + ruleName: 'foo', + secondaryLocations: [], + severity: 'MAJOR', + status: 'OPEN', + textRange: { startLine: 25, endLine: 26, startOffset: 0, endOffset: 15 }, + transitions: [], + type: 'BUG' + }; + + function loc(): T.FlowLocation { + return { + component: 'main.js', + textRange: { startLine: 1, startOffset: 1, endLine: 2, endOffset: 2 } + }; + } + + if (withLocations) { + issue.flows = [[loc(), loc(), loc()], [loc(), loc()]]; + issue.secondaryLocations = [loc(), loc()]; + } + + return { + ...issue, + ...overrides + }; +} + export function mockLocation(overrides: Partial<Location> = {}): Location { return { action: 'PUSH', @@ -123,6 +180,14 @@ export function mockOrganizationWithAlm( }); } +export function mockQualityGate(overrides: Partial<T.QualityGate> = {}): T.QualityGate { + return { + id: 1, + name: 'qualitygate', + ...overrides + }; +} + export function mockQualityProfile(overrides: Partial<Profile> = {}): Profile { return { activeDeprecatedRuleCount: 2, @@ -157,48 +222,17 @@ export function mockRouter(overrides: { push?: Function; replace?: Function } = } as InjectedRouter; } -export function mockIssue(withLocations = false, overrides: Partial<T.Issue> = {}) { - const issue: T.Issue = { - actions: [], - component: 'main.js', - componentLongName: 'main.js', - componentQualifier: 'FIL', - componentUuid: 'foo1234', - creationDate: '2017-03-01T09:36:01+0100', - flows: [], - fromHotspot: false, - key: 'AVsae-CQS-9G3txfbFN2', - line: 25, - message: 'Reduce the number of conditional operators (4) used in the expression', - organization: 'myorg', - project: 'myproject', - projectKey: 'foo', - projectName: 'Foo', - projectOrganization: 'org', - rule: 'javascript:S1067', - ruleName: 'foo', - secondaryLocations: [], - severity: 'MAJOR', - status: 'OPEN', - textRange: { startLine: 25, endLine: 26, startOffset: 0, endOffset: 15 }, - transitions: [], - type: 'BUG' - }; - - function loc(): T.FlowLocation { - return { - component: 'main.js', - textRange: { startLine: 1, startOffset: 1, endLine: 2, endOffset: 2 } - }; - } - - if (withLocations) { - issue.flows = [[loc(), loc(), loc()], [loc(), loc()]]; - issue.secondaryLocations = [loc(), loc()]; - } - +export function mockRule(overrides: Partial<T.Rule> = {}): T.Rule { return { - ...issue, + key: 'javascript:S1067', + lang: 'js', + langName: 'JavaScript', + name: 'Use foo', + severity: 'MAJOR', + status: 'READY', + sysTags: ['a', 'b'], + tags: ['x'], + type: 'CODE_SMELL', ...overrides - }; + } as T.Rule; } |