aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2018-12-20 10:54:16 +0100
committerSonarTech <sonartech@sonarsource.com>2018-12-24 20:20:54 +0100
commit0225aef248c18e61246b1f50e4ec189e8192511a (patch)
treecf9e5e5c71ed7d92bf131c9a124e43b25b7f4a0c
parent722c2cdd1b8d37002e96bc6d48a11538e5961789 (diff)
downloadsonarqube-0225aef248c18e61246b1f50e4ec189e8192511a.tar.gz
sonarqube-0225aef248c18e61246b1f50e4ec189e8192511a.zip
Provide new test helper functions for creating mocks
-rw-r--r--server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaTags-test.tsx22
-rw-r--r--server/sonar-web/src/main/js/helpers/testUtils.ts52
2 files changed, 59 insertions, 15 deletions
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 b2ed2b1ac1e..a9bbe419265 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,30 +20,22 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import MetaTags from '../MetaTags';
+import { mockComponent } from '../../../../helpers/testUtils';
-const component = {
- key: 'my-project',
- tags: [],
+const component = mockComponent({
configuration: {
showSettings: false
- },
- organization: 'foo',
- qualifier: 'TRK',
- name: 'MyProject',
- breadcrumbs: []
-};
+ }
+});
-const componentWithTags = {
+const componentWithTags = mockComponent({
key: 'my-second-project',
tags: ['foo', 'bar'],
configuration: {
showSettings: true
},
- organization: 'foo',
- qualifier: 'TRK',
- name: 'MySecondProject',
- breadcrumbs: []
-};
+ name: 'MySecondProject'
+});
it('should render without tags and admin rights', () => {
expect(
diff --git a/server/sonar-web/src/main/js/helpers/testUtils.ts b/server/sonar-web/src/main/js/helpers/testUtils.ts
index 399363f6418..429d60e4d14 100644
--- a/server/sonar-web/src/main/js/helpers/testUtils.ts
+++ b/server/sonar-web/src/main/js/helpers/testUtils.ts
@@ -19,6 +19,7 @@
*/
import { ShallowWrapper, ReactWrapper } from 'enzyme';
import { InjectedRouter } from 'react-router';
+import { EditionKey } from '../apps/marketplace/utils';
export const mockEvent = {
target: { blur() {} },
@@ -130,3 +131,54 @@ export function mockRouter(overrides: { push?: Function; replace?: Function } =
...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: [mockQualityProfile()],
+ tags: [],
+ ...overrides
+ };
+}
+
+export function mockCurrentUser(overrides = {}): T.CurrentUser {
+ return {
+ isLoggedIn: true,
+ ...overrides
+ };
+}
+
+export function mockOrganization(overrides = {}): T.Organization {
+ return {
+ key: 'foo',
+ name: 'Foo',
+ ...overrides
+ };
+}
+
+export function mockQualityProfile(overrides = {}): T.ComponentQualityProfile {
+ return {
+ deleted: false,
+ key: 'my-qp',
+ language: 'ts',
+ name: 'Sonar way',
+ ...overrides
+ };
+}