*/
import { getJSON, post } from 'sonar-ui-common/helpers/request';
import throwGlobalError from '../app/utils/throwGlobalError';
+import { BranchParameters } from '../types/branch-like';
import {
DetailedHotspot,
HotspotSearchResponse,
return post('/api/hotspots/change_status', data).catch(throwGlobalError);
}
-export function getSecurityHotspots(data: {
- projectKey: string;
- p: number;
- ps: number;
-}): Promise<HotspotSearchResponse> {
+export function getSecurityHotspots(
+ data: {
+ projectKey: string;
+ p: number;
+ ps: number;
+ } & BranchParameters
+): Promise<HotspotSearchResponse> {
return getJSON('/api/hotspots/search', data).catch(throwGlobalError);
}
import * as React from 'react';
import { addNoFooterPageClass, removeNoFooterPageClass } from 'sonar-ui-common/helpers/pages';
import { getSecurityHotspots } from '../../api/security-hotspots';
+import { getBranchLikeQuery } from '../../helpers/branch-like';
import { getStandards } from '../../helpers/security-standard';
import { BranchLike } from '../../types/branch-like';
import { HotspotUpdate, RawHotspot } from '../../types/security-hotspots';
}
fetchInitialData() {
+ const { branchLike, component } = this.props;
+
return Promise.all([
getStandards(),
- getSecurityHotspots({ projectKey: this.props.component.key, p: 1, ps: PAGE_SIZE })
+ getSecurityHotspots({
+ projectKey: component.key,
+ p: 1,
+ ps: PAGE_SIZE,
+ ...getBranchLikeQuery(branchLike)
+ })
])
.then(([{ sonarsourceSecurity }, response]) => {
if (!this.mounted) {
import { addNoFooterPageClass } from 'sonar-ui-common/helpers/pages';
import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
import { getSecurityHotspots } from '../../../api/security-hotspots';
-import { mockMainBranch } from '../../../helpers/mocks/branch-like';
+import { mockBranch } from '../../../helpers/mocks/branch-like';
import { mockRawHotspot } from '../../../helpers/mocks/security-hotspots';
import { getStandards } from '../../../helpers/security-standard';
import { mockComponent } from '../../../helpers/testMocks';
getStandards: jest.fn()
}));
+const branch = mockBranch();
+
it('should render correctly', () => {
expect(shallowRender()).toMatchSnapshot();
});
expect(addNoFooterPageClass).toBeCalled();
expect(getStandards).toBeCalled();
- expect(getSecurityHotspots).toBeCalled();
+ expect(getSecurityHotspots).toBeCalledWith(
+ expect.objectContaining({
+ branch: branch.name
+ })
+ );
await waitAndUpdate(wrapper);
function shallowRender(props: Partial<SecurityHotspotsApp['props']> = {}) {
return shallow<SecurityHotspotsApp>(
- <SecurityHotspotsApp branchLike={mockMainBranch()} component={mockComponent()} {...props} />
+ <SecurityHotspotsApp branchLike={branch} component={mockComponent()} {...props} />
);
}
Object {
"analysisDate": "2018-01-01",
"excludedFromPurge": true,
- "isMain": true,
- "name": "master",
+ "isMain": false,
+ "name": "branch-6.7",
}
}
hotspots={Array []}
}
fetchSources() {
- const { component, textRange } = this.props.hotspot;
+ const {
+ branchLike,
+ hotspot: { component, textRange }
+ } = this.props;
const from = Math.max(1, textRange.startLine - BUFFER_LINES);
// Add 1 to check for end-of-file:
const to = textRange.endLine + BUFFER_LINES + 1;
this.setState({ loading: true });
- return getSources({ key: component.key, from, to })
+ return getSources({ key: component.key, from, to, ...getBranchLikeQuery(branchLike) })
.then(sourceLines => {
if (this.mounted) {
const lastLine = this.checkLastLine(sourceLines, to);
import * as React from 'react';
import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
import { getSources } from '../../../../api/components';
+import { mockBranch } from '../../../../helpers/mocks/branch-like';
import { mockDetailledHotspot } from '../../../../helpers/mocks/security-hotspots';
import { mockSourceLine } from '../../../../helpers/testMocks';
import HotspotSnippetContainer from '../HotspotSnippetContainer';
getSources: jest.fn().mockResolvedValue([])
}));
+const branch = mockBranch();
+
it('should render correctly', () => {
expect(shallowRender()).toMatchSnapshot();
});
await waitAndUpdate(wrapper);
- expect(getSources).toBeCalled();
+ expect(getSources).toBeCalledWith(
+ expect.objectContaining({
+ branch: branch.name
+ })
+ );
expect(wrapper.state().lastLine).toBeUndefined();
expect(wrapper.state().sourceLines).toHaveLength(12);
});
await waitAndUpdate(wrapper);
+ expect(getSources).toBeCalledWith(
+ expect.objectContaining({
+ branch: branch.name
+ })
+ );
expect(wrapper.state().sourceLines).toHaveLength(16);
});
function shallowRender(props?: Partial<HotspotSnippetContainer['props']>) {
return shallow<HotspotSnippetContainer>(
- <HotspotSnippetContainer hotspot={mockDetailledHotspot()} {...props} />
+ <HotspotSnippetContainer branchLike={branch} hotspot={mockDetailledHotspot()} {...props} />
);
}
exports[`should render correctly 1`] = `
<HotspotSnippetContainerRenderer
+ branchLike={
+ Object {
+ "analysisDate": "2018-01-01",
+ "excludedFromPurge": true,
+ "isMain": false,
+ "name": "branch-6.7",
+ }
+ }
highlightedSymbols={Array []}
hotspot={
Object {