浏览代码

Split mocks for CurrentUser and LoggedInUser

tags/7.8
Wouter Admiraal 5 年前
父节点
当前提交
16f267a80f

+ 2
- 2
server/sonar-web/src/main/js/apps/account/components/__tests__/Password-test.tsx 查看文件

@@ -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();
});

+ 2
- 2
server/sonar-web/src/main/js/apps/issues/components/__tests__/App-test.tsx 查看文件

@@ -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,

+ 2
- 2
server/sonar-web/src/main/js/apps/organizationMembers/__tests__/MembersList-test.tsx 查看文件

@@ -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={[]}

+ 3
- 3
server/sonar-web/src/main/js/apps/organizationMembers/__tests__/MembersListHeader-test.tsx 查看文件

@@ -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}

+ 2
- 2
server/sonar-web/src/main/js/apps/organizationMembers/__tests__/OrganizationMembers-test.tsx 查看文件

@@ -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}
/>

+ 2
- 2
server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationBind-test.tsx 查看文件

@@ -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}
/>

+ 2
- 2
server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationEdit-test.tsx 查看文件

@@ -20,13 +20,13 @@
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()}
/>

+ 6
- 2
server/sonar-web/src/main/js/apps/organizations/navigation/__tests__/OrganizationNavigationHeader-test.tsx 查看文件

@@ -20,7 +20,11 @@
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();
});


+ 2
- 2
server/sonar-web/src/main/js/apps/overview/meta/__tests__/MetaContainer-test.tsx 查看文件

@@ -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()]}

+ 2
- 2
server/sonar-web/src/main/js/apps/settings/components/__tests__/EmailForm-test.tsx 查看文件

@@ -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();
});

+ 3
- 3
server/sonar-web/src/main/js/apps/tutorials/onboarding/__tests__/OnboardingModal-test.tsx 查看文件

@@ -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={[]}

+ 2
- 2
server/sonar-web/src/main/js/helpers/__tests__/almIntegrations-test.ts 查看文件

@@ -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'
);
});

+ 8
- 1
server/sonar-web/src/main/js/helpers/testMocks.ts 查看文件

@@ -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,

正在加载...
取消
保存