]> source.dussan.org Git - sonarqube.git/commitdiff
Split mocks for CurrentUser and LoggedInUser
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Fri, 22 Mar 2019 09:53:05 +0000 (10:53 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 26 Mar 2019 12:37:56 +0000 (13:37 +0100)
13 files changed:
server/sonar-web/src/main/js/apps/account/components/__tests__/Password-test.tsx
server/sonar-web/src/main/js/apps/issues/components/__tests__/App-test.tsx
server/sonar-web/src/main/js/apps/organizationMembers/__tests__/MembersList-test.tsx
server/sonar-web/src/main/js/apps/organizationMembers/__tests__/MembersListHeader-test.tsx
server/sonar-web/src/main/js/apps/organizationMembers/__tests__/OrganizationMembers-test.tsx
server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationBind-test.tsx
server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationEdit-test.tsx
server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationHeader-test.tsx
server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaContainer-test.tsx
server/sonar-web/src/main/js/apps/settings/components/__tests__/EmailForm-test.tsx
server/sonar-web/src/main/js/apps/tutorials/onboarding/__tests__/OnboardingModal-test.tsx
server/sonar-web/src/main/js/helpers/__tests__/almIntegrations-test.ts
server/sonar-web/src/main/js/helpers/testMocks.ts

index 2b5900be381f5d3b803caedb921a07a46b1964a2..efe80d9f4b82274a325d468e9dc69ce9acd27f63 100644 (file)
@@ -20,8 +20,8 @@
 import * as React from 'react';
 import { shallow } from 'enzyme';
 import Password from '../Password';
-import { mockCurrentUser } from '../../../../helpers/testMocks';
+import { mockLoggedInUser } from '../../../../helpers/testMocks';
 
 it('renders correctly', () => {
-  expect(shallow(<Password user={mockCurrentUser()} />)).toMatchSnapshot();
+  expect(shallow(<Password user={mockLoggedInUser()} />)).toMatchSnapshot();
 });
index 1c27ca4366e8469632bb15e8010f0dbf5af37216..d978c70f20878d62c125830a857bd6d0c5565f63 100644 (file)
@@ -21,7 +21,7 @@ import * as React from 'react';
 import { shallow } from 'enzyme';
 import { App } from '../App';
 import {
-  mockCurrentUser,
+  mockLoggedInUser,
   mockRouter,
   mockIssue,
   mockLocation
@@ -193,7 +193,7 @@ function shallowRender(props: Partial<App['props']> = {}) {
         organization: 'John',
         qualifier: 'Doe'
       }}
-      currentUser={mockCurrentUser()}
+      currentUser={mockLoggedInUser()}
       fetchIssues={jest.fn().mockResolvedValue({
         components: [referencedComponent],
         effortTotal: 1,
index f3746540b7aba3f7ed7824f62d7329d59b0b4121..b04b6978982a92ae92d8563ff5e15cf5d79f084d 100644 (file)
@@ -20,7 +20,7 @@
 import * as React from 'react';
 import { shallow } from 'enzyme';
 import MembersList from '../MembersList';
-import { mockOrganization, mockCurrentUser } from '../../../helpers/testMocks';
+import { mockLoggedInUser, mockOrganization } from '../../../helpers/testMocks';
 
 const members = [
   { login: 'admin', name: 'Admin Istrator', avatar: '', groupCount: 3 },
@@ -38,7 +38,7 @@ it('should render "no results"', () => {
 function shallowRender(props: Partial<MembersList['props']> = {}) {
   return shallow(
     <MembersList
-      currentUser={mockCurrentUser({ login: 'admin' })}
+      currentUser={mockLoggedInUser({ login: 'admin' })}
       members={members}
       organization={mockOrganization()}
       organizationGroups={[]}
index 7c97806d07e3808fd60a2b01085dd8eb77c884ac..69e1a371773a4ae832e8f8be5c16b2be5c4ff232 100644 (file)
@@ -21,8 +21,8 @@ import * as React from 'react';
 import { shallow } from 'enzyme';
 import MembersListHeader, { Props } from '../MembersListHeader';
 import {
+  mockLoggedInUser,
   mockOrganization,
-  mockCurrentUser,
   mockOrganizationWithAlm
 } from '../../../helpers/testMocks';
 
@@ -53,7 +53,7 @@ it('should render a help tooltip', () => {
 it('should not render link in help tooltip', () => {
   expect(
     shallowRender({
-      currentUser: mockCurrentUser({ personalOrganization: 'foo' }),
+      currentUser: mockLoggedInUser({ personalOrganization: 'foo' }),
       organization: mockOrganizationWithAlm({}, { membersSync: true })
     }).find('HelpTooltip')
   ).toMatchSnapshot();
@@ -62,7 +62,7 @@ it('should not render link in help tooltip', () => {
 function shallowRender(props: Partial<Props> = {}) {
   return shallow(
     <MembersListHeader
-      currentUser={mockCurrentUser()}
+      currentUser={mockLoggedInUser()}
       handleSearch={jest.fn()}
       organization={mockOrganization()}
       total={8}
index 1b11920966600c08639d94ebf20d1a2f64c54ec3..10c05d502af2a2642d0ab7b88f0dadbc13978263 100644 (file)
@@ -23,8 +23,8 @@ import OrganizationMembers from '../OrganizationMembers';
 import { searchMembers, addMember, removeMember } from '../../../api/organizations';
 import { searchUsersGroups, addUserToGroup, removeUserFromGroup } from '../../../api/user_groups';
 import {
+  mockLoggedInUser,
   mockOrganization,
-  mockCurrentUser,
   mockOrganizationWithAdminActions,
   mockOrganizationWithAlm
 } from '../../../helpers/testMocks';
@@ -172,7 +172,7 @@ it('should not allow to remove members when in sync mode', async () => {
 function shallowRender(props: Partial<OrganizationMembers['props']> = {}) {
   return shallow<OrganizationMembers>(
     <OrganizationMembers
-      currentUser={mockCurrentUser()}
+      currentUser={mockLoggedInUser()}
       organization={mockOrganizationWithAdminActions()}
       {...props}
     />
index 079de73c67e93483d96019e21afcbefa022e7ec0..286f9a241b4a658368f5220fa17f25ea2e25da57 100644 (file)
@@ -28,7 +28,7 @@ import { getAlmAppInfo } from '../../../../api/alm-integration';
 import { save } from '../../../../helpers/storage';
 import {
   mockAlmApplication,
-  mockCurrentUser,
+  mockLoggedInUser,
   mockOrganization
 } from '../../../../helpers/testMocks';
 
@@ -64,7 +64,7 @@ it('should save state when handling Install App click', () => {
 function shallowRender(props: Partial<OrganizationBind['props']> = {}) {
   return shallow<OrganizationBind>(
     <OrganizationBind
-      currentUser={mockCurrentUser()}
+      currentUser={mockLoggedInUser()}
       organization={mockOrganization()}
       {...props}
     />
index 1daa8265779a405cdc5dd9805e0405d99651b911..357786f3d9be19c4918bbd5aa2e67f3023795f70 100644 (file)
 import * as React from 'react';
 import { shallow } from 'enzyme';
 import { OrganizationEdit } from '../OrganizationEdit';
-import { mockCurrentUser } from '../../../../helpers/testMocks';
+import { mockLoggedInUser } from '../../../../helpers/testMocks';
 
 it('smoke test', () => {
   const organization = { key: 'foo', name: 'Foo' };
   const wrapper = shallow(
     <OrganizationEdit
-      currentUser={mockCurrentUser()}
+      currentUser={mockLoggedInUser()}
       organization={organization}
       updateOrganization={jest.fn()}
     />
index 12f1d27fb4cd71d619ffce349ce8424f63a883dd..abd265629e3f4ce8e5dad96f5597759310324e58 100644 (file)
 import * as React from 'react';
 import { shallow } from 'enzyme';
 import OrganizationNavigationHeader, { Props } from '../OrganizationNavigationHeader';
-import { mockOrganizationWithAlm, mockCurrentUser } from '../../../../helpers/testMocks';
+import {
+  mockOrganizationWithAlm,
+  mockCurrentUser,
+  mockLoggedInUser
+} from '../../../../helpers/testMocks';
 
 it('renders', () => {
   expect(shallowRender()).toMatchSnapshot();
@@ -34,7 +38,7 @@ it('renders with alm integration', () => {
 
 it('renders for external user w/o alm integration', () => {
   expect(
-    shallowRender({ currentUser: mockCurrentUser({ externalProvider: 'github' }) })
+    shallowRender({ currentUser: mockLoggedInUser({ externalProvider: 'github' }) })
   ).toMatchSnapshot();
 });
 
index 5a1378797e530892d4563ebad58b8116c6c69707..99b5e123b8dec2c6df25e48ca71a767fe1aef8a8 100644 (file)
@@ -22,7 +22,7 @@ import { shallow } from 'enzyme';
 import { Meta } from '../MetaContainer';
 import {
   mockAppState,
-  mockCurrentUser,
+  mockLoggedInUser,
   mockOrganization,
   mockComponent
 } from '../../../../helpers/testMocks';
@@ -58,7 +58,7 @@ function shallowRender(props: Partial<Meta['props']> = {}) {
     <Meta
       appState={mockAppState({ organizationsEnabled: true })}
       component={mockComponent()}
-      currentUser={mockCurrentUser()}
+      currentUser={mockLoggedInUser()}
       onComponentChange={jest.fn()}
       organization={mockOrganization()}
       userOrganizations={[mockOrganization()]}
index 6c714a8d248a8f10d9df3648eae276d263302b5d..7ec5daf83dcb0a2cfac970ad6c324024169bcc47 100644 (file)
@@ -20,8 +20,8 @@
 import * as React from 'react';
 import { shallow } from 'enzyme';
 import { EmailForm } from '../EmailForm';
-import { mockCurrentUser } from '../../../../helpers/testMocks';
+import { mockLoggedInUser } from '../../../../helpers/testMocks';
 
 it('should render correctly', () => {
-  expect(shallow(<EmailForm currentUser={mockCurrentUser()} />)).toMatchSnapshot();
+  expect(shallow(<EmailForm currentUser={mockLoggedInUser()} />)).toMatchSnapshot();
 });
index ab03de8c5d3cd02bbaebc69bf03eda94c1c7a050..23ee2e84229d9680dc9a7f6c51b85f5ee559972e 100644 (file)
@@ -21,7 +21,7 @@ import * as React from 'react';
 import { shallow } from 'enzyme';
 import { OnboardingModal, Props } from '../OnboardingModal';
 import { click } from '../../../../helpers/testUtils';
-import { mockCurrentUser, mockOrganization } from '../../../../helpers/testMocks';
+import { mockLoggedInUser, mockOrganization } from '../../../../helpers/testMocks';
 
 it('renders correctly', () => {
   expect(shallowRender()).toMatchSnapshot();
@@ -41,7 +41,7 @@ it('should open project create page', () => {
 
 it('should display organization list if any', () => {
   const wrapper = shallowRender({
-    currentUser: mockCurrentUser({ personalOrganization: 'personal' }),
+    currentUser: mockLoggedInUser({ personalOrganization: 'personal' }),
     userOrganizations: [
       mockOrganization({ key: 'a', name: 'Arthur' }),
       mockOrganization({ key: 'd', name: 'Daniel Inc' }),
@@ -56,7 +56,7 @@ it('should display organization list if any', () => {
 function shallowRender(props: Partial<Props> = {}) {
   return shallow(
     <OnboardingModal
-      currentUser={mockCurrentUser()}
+      currentUser={mockLoggedInUser()}
       onClose={jest.fn()}
       onOpenProjectOnboarding={jest.fn()}
       userOrganizations={[]}
index de98abb49683e7365ae1d7017c0fc9ff9425835e..212af84369f494995e03b73d82f465972695d4ae 100644 (file)
@@ -26,7 +26,7 @@ import {
   getAlmMembersUrl,
   getUserAlmKey
 } from '../almIntegrations';
-import { mockCurrentUser } from '../testMocks';
+import { mockCurrentUser, mockLoggedInUser } from '../testMocks';
 
 it('#getAlmMembersUrl', () => {
   expect(getAlmMembersUrl('github', 'https://github.com/Foo')).toBe(
@@ -74,7 +74,7 @@ it('#sanitizeAlmId', () => {
 
 describe('getUserAlmKey', () => {
   it('should return sanitized almKey', () => {
-    expect(getUserAlmKey(mockCurrentUser({ externalProvider: 'bitbucketcloud' }))).toBe(
+    expect(getUserAlmKey(mockLoggedInUser({ externalProvider: 'bitbucketcloud' }))).toBe(
       'bitbucket'
     );
   });
index b9399a8e99145ad85ae1e2bdb6411ea022c9b884..5a1ff87a35841a71f7e182f4e84315fe7ca9f7d5 100644 (file)
@@ -131,7 +131,14 @@ export function mockQualityGateStatusCondition(
   };
 }
 
-export function mockCurrentUser(overrides: Partial<T.LoggedInUser> = {}): T.LoggedInUser {
+export function mockCurrentUser(overrides: Partial<T.CurrentUser> = {}): T.CurrentUser {
+  return {
+    isLoggedIn: false,
+    ...overrides
+  };
+}
+
+export function mockLoggedInUser(overrides: Partial<T.LoggedInUser> = {}): T.LoggedInUser {
   return {
     groups: [],
     isLoggedIn: true,