From afbb758004d62375c5d91c1180ad6050e8f4e253 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Wed, 3 Apr 2019 14:08:00 +0200 Subject: [PATCH] SONAR-11856 Display true pull request target instead of base --- .../__tests__/ComponentContainer-test.tsx | 88 +++++------- .../nav/component/ComponentNavBranch.tsx | 2 +- .../__tests__/ComponentNavBranch-test.tsx | 29 ++-- .../ComponentNavBranchesMenu-test.tsx | 60 +++----- .../ComponentNavBranch-test.tsx.snap | 61 +++++--- .../ComponentNavBranchesMenu-test.tsx.snap | 16 ++- .../ComponentNavMeta-test.tsx.snap | 5 +- server/sonar-web/src/main/js/app/types.d.ts | 1 + .../components/__tests__/App-test.tsx | 6 +- .../__tests__/__snapshots__/App-test.tsx.snap | 1 + .../__tests__/EmptyOverview-test.tsx | 38 ++--- .../__snapshots__/EmptyOverview-test.tsx.snap | 133 +++++++++++++----- .../__snapshots__/IssueRating-test.tsx.snap | 3 + .../MeasurementLabel-test.tsx.snap | 8 +- .../__snapshots__/ReviewApp-test.tsx.snap | 25 ++++ .../components/__tests__/App-test.tsx | 42 +++--- .../components/__tests__/BranchRow-test.tsx | 16 +-- .../__tests__/DeleteBranchModal-test.tsx | 35 ++--- .../__tests__/__snapshots__/App-test.tsx.snap | 16 ++- .../__snapshots__/BranchRow-test.tsx.snap | 40 +++--- .../DeleteBranchModal-test.tsx.snap | 4 +- .../src/main/js/helpers/testMocks.ts | 5 +- .../resources/org/sonar/l10n/core.properties | 2 +- 23 files changed, 349 insertions(+), 287 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx index 501f1c72365..f534409f7cf 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx @@ -27,33 +27,30 @@ import { getComponentNavigation } from '../../../api/nav'; import { STATUSES } from '../../../apps/background-tasks/constants'; import { waitAndUpdate } from '../../../helpers/testUtils'; import { isSonarCloud } from '../../../helpers/system'; -import { mockLocation, mockRouter, mockComponent } from '../../../helpers/testMocks'; - -jest.mock('../../../api/branches', () => ({ - getBranches: jest.fn().mockResolvedValue([ - { - isMain: true, - name: 'master', - type: 'LONG', - status: { qualityGateStatus: 'OK' } - } - ]), - getPullRequests: jest.fn().mockResolvedValue([ - { - base: 'feature', - branch: 'feature', - key: 'pr-89', - title: 'PR Feature', - status: { qualityGateStatus: 'ERROR' } - }, - { - base: 'feature', - branch: 'feature', - key: 'pr-90', - title: 'PR Feature 2' - } - ]) -})); +import { + mockLocation, + mockRouter, + mockComponent, + mockPullRequest, + mockLongLivingBranch, + mockShortLivingBranch, + mockMainBranch +} from '../../../helpers/testMocks'; + +jest.mock('../../../api/branches', () => { + const { mockMainBranch, mockPullRequest } = require.requireActual('../../../helpers/testMocks'); + return { + getBranches: jest + .fn() + .mockResolvedValue([mockMainBranch({ status: { qualityGateStatus: 'OK' } })]), + getPullRequests: jest + .fn() + .mockResolvedValue([ + mockPullRequest({ key: 'pr-89', status: { qualityGateStatus: 'ERROR' } }), + mockPullRequest({ key: 'pr-90', title: 'PR Feature 2' }) + ]) + }; +}); jest.mock('../../../api/ce', () => ({ getAnalysisStatus: jest.fn().mockResolvedValue({ component: { warnings: [] } }), @@ -152,30 +149,16 @@ it('fetches status', async () => { it('filters correctly the pending tasks for a main branch', () => { const wrapper = shallowRender(); const component = wrapper.instance(); - const mainBranch: T.MainBranch = { isMain: true, name: 'master' }; - const shortBranch: T.ShortLivingBranch = { - isMain: false, - mergeBranch: 'master', - name: 'feature', - type: 'SHORT' - }; - const longBranch: T.LongLivingBranch = { - isMain: false, - name: 'branch-7.2', - type: 'LONG' - }; - const pullRequest: T.PullRequest = { - base: 'feature', - branch: 'feature', - key: 'pr-89', - title: 'PR Feature' - }; + const mainBranch = mockMainBranch(); + const shortBranch = mockShortLivingBranch(); + const longBranch = mockLongLivingBranch(); + const pullRequest = mockPullRequest(); expect(component.isSameBranch({}, undefined)).toBeTruthy(); expect(component.isSameBranch({}, mainBranch)).toBeTruthy(); expect(component.isSameBranch({}, shortBranch)).toBeFalsy(); expect( - component.isSameBranch({ branch: 'feature', branchType: 'SHORT' }, shortBranch) + component.isSameBranch({ branch: shortBranch.name, branchType: 'SHORT' }, shortBranch) ).toBeTruthy(); expect( component.isSameBranch({ branch: 'feature', branchType: 'SHORT' }, longBranch) @@ -184,18 +167,21 @@ it('filters correctly the pending tasks for a main branch', () => { component.isSameBranch({ branch: 'feature', branchType: 'SHORT' }, longBranch) ).toBeFalsy(); expect( - component.isSameBranch({ branch: 'branch-7.1', branchType: 'LONG' }, longBranch) + component.isSameBranch({ branch: 'branch-6.6', branchType: 'LONG' }, longBranch) ).toBeFalsy(); expect( - component.isSameBranch({ branch: 'branch-7.2', branchType: 'LONG' }, pullRequest) + component.isSameBranch({ branch: longBranch.name, branchType: 'LONG' }, longBranch) + ).toBeTruthy(); + expect( + component.isSameBranch({ branch: 'branch-6.7', branchType: 'LONG' }, pullRequest) ).toBeFalsy(); - expect(component.isSameBranch({ pullRequest: 'pr-89' }, pullRequest)).toBeTruthy(); + expect(component.isSameBranch({ pullRequest: pullRequest.key }, pullRequest)).toBeTruthy(); - const currentTask = { pullRequest: 'pr-89', status: STATUSES.IN_PROGRESS } as T.Task; + const currentTask = { pullRequest: pullRequest.key, status: STATUSES.IN_PROGRESS } as T.Task; const failedTask = { ...currentTask, status: STATUSES.FAILED }; const pendingTasks = [ currentTask, - { branch: 'feature', branchType: 'SHORT' } as T.Task, + { branch: shortBranch.name, branchType: 'SHORT' } as T.Task, {} as T.Task ]; expect(component.getCurrentTask(currentTask, undefined)).toBe(undefined); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranch.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranch.tsx index 0905f0143ef..3b6ffb947eb 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranch.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranch.tsx @@ -109,7 +109,7 @@ export class ComponentNavBranch extends React.PureComponent { defaultMessage={translate('branches.pull_request.for_merge_into_x_from_y')} id="branches.pull_request.for_merge_into_x_from_y" values={{ - base: {currentBranchLike.base}, + target: {currentBranchLike.target}, branch: {currentBranchLike.branch} }} /> diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranch-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranch-test.tsx index 21a8a1ccb3b..59ef798f2d6 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranch-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranch-test.tsx @@ -22,11 +22,17 @@ import { shallow } from 'enzyme'; import { ComponentNavBranch } from '../ComponentNavBranch'; import { click } from '../../../../../helpers/testUtils'; import { isSonarCloud } from '../../../../../helpers/system'; +import { + mockPullRequest, + mockShortLivingBranch, + mockMainBranch, + mockLongLivingBranch +} from '../../../../../helpers/testMocks'; jest.mock('../../../../../helpers/system', () => ({ isSonarCloud: jest.fn() })); -const mainBranch: T.MainBranch = { isMain: true, name: 'master' }; -const fooBranch: T.LongLivingBranch = { isMain: false, name: 'foo', type: 'LONG' }; +const mainBranch = mockMainBranch(); +const fooBranch = mockLongLivingBranch(); beforeEach(() => { (isSonarCloud as jest.Mock).mockImplementation(() => false); @@ -47,13 +53,9 @@ it('renders main branch', () => { }); it('renders short-living branch', () => { - const branch: T.ShortLivingBranch = { - isMain: false, - mergeBranch: 'master', - name: 'foo', - status: { qualityGateStatus: 'OK' }, - type: 'SHORT' - }; + const branch: T.ShortLivingBranch = mockShortLivingBranch({ + status: { qualityGateStatus: 'OK' } + }); const component = {} as T.Component; expect( shallow( @@ -68,13 +70,10 @@ it('renders short-living branch', () => { }); it('renders pull request', () => { - const pullRequest: T.PullRequest = { - base: 'master', - branch: 'feature', - key: '1234', - title: 'Feature PR', + const pullRequest = mockPullRequest({ + target: 'feature/foo', url: 'https://example.com/pull/1234' - }; + }); const component = {} as T.Component; expect( shallow( diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenu-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenu-test.tsx index 96ec59ddb2e..24b0411de31 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenu-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenu-test.tsx @@ -21,6 +21,12 @@ import * as React from 'react'; import { shallow } from 'enzyme'; import { ComponentNavBranchesMenu } from '../ComponentNavBranchesMenu'; import { elementKeydown } from '../../../../../helpers/testUtils'; +import { + mockPullRequest, + mockShortLivingBranch, + mockLongLivingBranch, + mockMainBranch +} from '../../../../../helpers/testMocks'; const component = { key: 'component' } as T.Component; @@ -29,14 +35,14 @@ it('renders list', () => { shallow( @@ -48,14 +54,14 @@ it('searches', () => { const wrapper = shallow( @@ -67,9 +73,14 @@ it('searches', () => { it('selects next & previous', () => { const wrapper = shallow( @@ -85,31 +96,6 @@ it('selects next & previous', () => { expect(wrapper.state().selected).toEqual(shortBranch('foo')); }); -function mainBranch(): T.MainBranch { - return { isMain: true, name: 'master' }; -} - -function shortBranch(name: string, isOrphan?: true): T.ShortLivingBranch { - return { - isMain: false, - isOrphan, - mergeBranch: 'master', - name, - status: { qualityGateStatus: 'OK' }, - type: 'SHORT' - }; -} - -function longBranch(name: string): T.LongLivingBranch { - return { isMain: false, name, type: 'LONG' }; -} - -function pullRequest(title: string): T.PullRequest { - return { - base: 'master', - branch: 'feature', - key: '1234', - status: { qualityGateStatus: 'OK' }, - title - }; +function shortBranch(name: string, isOrphan?: true) { + return mockShortLivingBranch({ name, isOrphan, status: { qualityGateStatus: 'OK' } }); } diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranch-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranch-test.tsx.snap index f9e722af305..41d56c5bb58 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranch-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranch-test.tsx.snap @@ -15,12 +15,14 @@ exports[`renders main branch 1`] = ` branchLikes={ Array [ Object { + "analysisDate": "2018-01-01", "isMain": true, "name": "master", }, Object { + "analysisDate": "2018-01-01", "isMain": false, - "name": "foo", + "name": "branch-6.7", "type": "LONG", }, ] @@ -28,6 +30,7 @@ exports[`renders main branch 1`] = ` component={Object {}} currentBranchLike={ Object { + "analysisDate": "2018-01-01", "isMain": true, "name": "master", } @@ -44,6 +47,7 @@ exports[`renders main branch 1`] = ` - 1234 – Feature PR + 1001 – Foo Bar feature - master - , "branch": - feature + feature/foo/bar + , + "target": + feature/foo , } } @@ -184,17 +195,19 @@ exports[`renders short-living branch 1`] = ` branchLikes={ Array [ Object { + "analysisDate": "2018-01-01", "isMain": false, "mergeBranch": "master", - "name": "foo", + "name": "feature/foo", "status": Object { "qualityGateStatus": "OK", }, "type": "SHORT", }, Object { + "analysisDate": "2018-01-01", "isMain": false, - "name": "foo", + "name": "branch-6.7", "type": "LONG", }, ] @@ -202,9 +215,10 @@ exports[`renders short-living branch 1`] = ` component={Object {}} currentBranchLike={ Object { + "analysisDate": "2018-01-01", "isMain": false, "mergeBranch": "master", - "name": "foo", + "name": "feature/foo", "status": Object { "qualityGateStatus": "OK", }, @@ -223,9 +237,10 @@ exports[`renders short-living branch 1`] = ` - foo + feature/foo @@ -81,6 +84,7 @@ exports[`renders list 1`] = ` ({ getAllMetrics: jest.fn().mockResolvedValue([ @@ -64,7 +65,7 @@ jest.mock('../../../../api/measures', () => ({ const COMPONENT = { key: 'foo', name: 'Foo', qualifier: 'TRK' }; const PROPS: App['props'] = { - branchLike: { isMain: true, name: 'master' }, + branchLike: mockMainBranch(), component: COMPONENT, location: { pathname: '/component_measures', query: { metric: 'coverage' } } as Location, params: {}, @@ -109,8 +110,7 @@ it('should render a message when there are no measures', async () => { }); it('should not render drilldown for estimated duplications', async () => { - const pullRequest = { base: 'master', branch: 'feature-x', key: '5', title: '' }; - const wrapper = shallow(); + const wrapper = shallow(); await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/App-test.tsx.snap b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/App-test.tsx.snap index e90f3b035ea..2de9484e8fd 100644 --- a/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/App-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/component-measures/components/__tests__/__snapshots__/App-test.tsx.snap @@ -76,6 +76,7 @@ exports[`should render correctly 1`] = ` { expect( @@ -99,17 +91,7 @@ it('should render warning message', () => { it('should not render warning message', () => { expect( - shallow( - - ) + shallow() .find('FormattedMessage') .exists() ).toBeFalsy(); diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/EmptyOverview-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/EmptyOverview-test.tsx.snap index ed33bf33c66..22173c3d13f 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/EmptyOverview-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/EmptyOverview-test.tsx.snap @@ -13,20 +13,35 @@ exports[`renders correctly 1`] = ` @@ -37,19 +52,32 @@ exports[`renders correctly 1`] = ` diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/IssueRating-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/IssueRating-test.tsx.snap index d21f078275d..7025894710c 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/IssueRating-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/IssueRating-test.tsx.snap @@ -18,6 +18,7 @@ exports[`should render correctly for bugs 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -52,6 +53,7 @@ exports[`should render correctly for code smells 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -86,6 +88,7 @@ exports[`should render correctly for vulnerabilities 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/MeasurementLabel-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/MeasurementLabel-test.tsx.snap index 4885a7e5822..80d2067bc1b 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/MeasurementLabel-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/MeasurementLabel-test.tsx.snap @@ -16,7 +16,7 @@ exports[`should render correctly for coverage 1`] = ` "analysisDate": "2018-01-01", "isMain": false, "mergeBranch": "master", - "name": "release-1.0", + "name": "feature/foo", "type": "SHORT", } } @@ -49,7 +49,7 @@ exports[`should render correctly for coverage 2`] = ` "analysisDate": "2018-01-01", "isMain": false, "mergeBranch": "master", - "name": "release-1.0", + "name": "feature/foo", "type": "SHORT", } } @@ -72,7 +72,7 @@ exports[`should render correctly for coverage 2`] = ` "analysisDate": "2018-01-01", "isMain": false, "mergeBranch": "master", - "name": "release-1.0", + "name": "feature/foo", "type": "SHORT", } } @@ -104,7 +104,7 @@ exports[`should render correctly for duplications 1`] = ` "analysisDate": "2018-01-01", "isMain": false, "mergeBranch": "master", - "name": "release-1.0", + "name": "feature/foo", "type": "SHORT", } } diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/ReviewApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/ReviewApp-test.tsx.snap index a850b2f999b..af5bcaf2da0 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/ReviewApp-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/ReviewApp-test.tsx.snap @@ -67,6 +67,7 @@ exports[`should correctly handle a WS failure 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -108,6 +109,7 @@ exports[`should correctly handle a WS failure 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -153,6 +155,7 @@ exports[`should correctly handle a WS failure 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -194,6 +197,7 @@ exports[`should correctly handle a WS failure 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -239,6 +243,7 @@ exports[`should correctly handle a WS failure 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -280,6 +285,7 @@ exports[`should correctly handle a WS failure 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -325,6 +331,7 @@ exports[`should correctly handle a WS failure 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -379,6 +386,7 @@ exports[`should correctly handle a WS failure 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -485,6 +493,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -548,6 +557,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -628,6 +638,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -712,6 +723,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -792,6 +804,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -876,6 +889,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -956,6 +970,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1040,6 +1055,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1172,6 +1188,7 @@ exports[`should render correctly for a failed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1363,6 +1380,7 @@ exports[`should render correctly for a passed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1443,6 +1461,7 @@ exports[`should render correctly for a passed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1527,6 +1546,7 @@ exports[`should render correctly for a passed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1607,6 +1627,7 @@ exports[`should render correctly for a passed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1691,6 +1712,7 @@ exports[`should render correctly for a passed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1771,6 +1793,7 @@ exports[`should render correctly for a passed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1855,6 +1878,7 @@ exports[`should render correctly for a passed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } @@ -1987,6 +2011,7 @@ exports[`should render correctly for a passed QG 1`] = ` "base": "master", "branch": "feature/foo/bar", "key": "1001", + "target": "master", "title": "Foo Bar feature", } } diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/App-test.tsx index 964a369e572..0d8aa106578 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/App-test.tsx @@ -17,40 +17,32 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* eslint-disable import/first, import/order */ -jest.mock('../../../../api/settings', () => ({ - getValues: jest.fn(() => Promise.resolve([])) -})); - import * as React from 'react'; import { mount, shallow } from 'enzyme'; import App from '../App'; +import { getValues } from '../../../../api/settings'; +import { + mockMainBranch, + mockLongLivingBranch, + mockShortLivingBranch, + mockPullRequest +} from '../../../../helpers/testMocks'; -const getValues = require('../../../../api/settings').getValues as jest.Mock; +jest.mock('../../../../api/settings', () => ({ + getValues: jest.fn(() => Promise.resolve([])) +})); beforeEach(() => { - getValues.mockClear(); + jest.clearAllMocks(); }); it('renders sorted list of branches', () => { - const branchLikes: [ - T.MainBranch, - T.LongLivingBranch, - T.ShortLivingBranch, - T.PullRequest, - T.ShortLivingBranch - ] = [ - { isMain: true, name: 'master' }, - { isMain: false, name: 'branch-1.0', type: 'LONG' }, - { isMain: false, mergeBranch: 'master', name: 'feature', type: 'SHORT' }, - { base: 'master', branch: 'feature', key: '1234', title: 'Feature PR' }, - { - isMain: false, - mergeBranch: 'foobar', - isOrphan: true, - name: 'feature', - type: 'SHORT' - } + const branchLikes = [ + mockMainBranch(), + mockLongLivingBranch(), + mockShortLivingBranch(), + mockPullRequest(), + mockShortLivingBranch({ mergeBranch: 'foobar', name: 'feature', isOrphan: true }) ]; const wrapper = shallow( { expect(shallowRender(mainBranch)).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/DeleteBranchModal-test.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/DeleteBranchModal-test.tsx index c1c1ef571b0..63ded5dceff 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/DeleteBranchModal-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/DeleteBranchModal-test.tsx @@ -17,28 +17,22 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* eslint-disable import/first */ -jest.mock('../../../../api/branches', () => ({ - deleteBranch: jest.fn(), - deletePullRequest: jest.fn() -})); - import * as React from 'react'; import { shallow, ShallowWrapper } from 'enzyme'; import DeleteBranchModal from '../DeleteBranchModal'; import { submit, doAsync, click, waitAndUpdate } from '../../../../helpers/testUtils'; import { deleteBranch, deletePullRequest } from '../../../../api/branches'; +import { mockShortLivingBranch, mockPullRequest } from '../../../../helpers/testMocks'; + +jest.mock('../../../../api/branches', () => ({ + deleteBranch: jest.fn(), + deletePullRequest: jest.fn() +})); -const branch: T.ShortLivingBranch = { - isMain: false, - name: 'feature', - mergeBranch: 'master', - type: 'SHORT' -}; +const branch = mockShortLivingBranch(); beforeEach(() => { - (deleteBranch as jest.Mock).mockClear(); - (deletePullRequest as jest.Mock).mockClear(); + jest.clearAllMocks(); }); it('renders', () => { @@ -58,17 +52,12 @@ it('deletes branch', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().loading).toBe(false); expect(onDelete).toBeCalled(); - expect(deleteBranch).toBeCalledWith({ branch: 'feature', project: 'foo' }); + expect(deleteBranch).toBeCalledWith({ branch: 'feature/foo', project: 'foo' }); }); it('deletes pull request', async () => { (deletePullRequest as jest.Mock).mockImplementationOnce(() => Promise.resolve()); - const pullRequest: T.PullRequest = { - base: 'master', - branch: 'feature', - key: '1234', - title: 'Feature PR' - }; + const pullRequest = mockPullRequest(); const onDelete = jest.fn(); const wrapper = shallowRender(pullRequest, onDelete); @@ -77,7 +66,7 @@ it('deletes pull request', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().loading).toBe(false); expect(onDelete).toBeCalled(); - expect(deletePullRequest).toBeCalledWith({ project: 'foo', pullRequest: '1234' }); + expect(deletePullRequest).toBeCalledWith({ project: 'foo', pullRequest: '1001' }); }); it('cancels', () => { @@ -101,7 +90,7 @@ it('stops loading on WS error', async () => { await waitAndUpdate(wrapper); expect(wrapper.state().loading).toBe(false); expect(onDelete).not.toBeCalled(); - expect(deleteBranch).toBeCalledWith({ branch: 'feature', project: 'foo' }); + expect(deleteBranch).toBeCalledWith({ branch: 'feature/foo', project: 'foo' }); }); function shallowRender( diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/App-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/App-test.tsx.snap index c706d117447..94ea8832c73 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/App-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/App-test.tsx.snap @@ -82,6 +82,7 @@ exports[`renders sorted list of branches 1`] = ` - 1234 – Feature PR + 1001 – Foo Bar feature + > + + @@ -110,16 +118,16 @@ exports[`renders short-living branch 1`] = ` - feature + feature/foo - branches.delete.are_you_sure.feature + branches.delete.are_you_sure.feature/foo