import withBranchStatusActions from '../../app/components/branch-status/withBranchStatusActions';
import withComponentContext from '../../app/components/componentContext/withComponentContext';
import withCurrentUserContext from '../../app/components/current-user/withCurrentUserContext';
-import { Location, Router, withRouter } from '../../components/hoc/withRouter';
+import { Location, withRouter } from '../../components/hoc/withRouter';
import { getLeakValue } from '../../components/measure/utils';
import { getBranchLikeQuery, isPullRequest, isSameBranchLike } from '../../helpers/branch-like';
import { isInput } from '../../helpers/keyboardEventHelpers';
currentUser: CurrentUser;
component: Component;
location: Location;
- router: Router;
}
type Props = DispatchProps & OwnProps;
.then(this.fetchSecurityHotspotsReviewed);
};
- handleShowAllHotspots = () => {
- this.props.router.push({
- ...this.props.location,
- query: {
- ...this.props.location.query,
- hotspots: undefined,
- [SecurityStandard.CWE]: undefined,
- [SecurityStandard.OWASP_TOP10]: undefined,
- [SecurityStandard.SANS_TOP25]: undefined,
- [SecurityStandard.SONARSOURCE]: undefined,
- [SecurityStandard.OWASP_TOP10_2021]: undefined,
- [SecurityStandard.PCI_DSS_3_2]: undefined,
- [SecurityStandard.PCI_DSS_4_0]: undefined,
- [SecurityStandard.OWASP_ASVS_4_0]: undefined,
- file: undefined,
- },
- });
- };
-
handleLoadMore = () => {
const { hotspots, hotspotsPageIndex: hotspotPages } = this.state;
onChangeFilters={this.handleChangeFilters}
onHotspotClick={this.handleHotspotClick}
onLoadMore={this.handleLoadMore}
- onShowAllHotspots={this.handleShowAllHotspots}
onSwitchStatusFilter={this.handleChangeStatusFilter}
onUpdateHotspot={this.handleHotspotUpdate}
onLocationClick={this.handleLocationClick}
onHotspotClick: (hotspot: RawHotspot) => void;
onLocationClick: (index?: number) => void;
onLoadMore: () => void;
- onShowAllHotspots: () => void;
onSwitchStatusFilter: (option: HotspotStatusFilter) => void;
onUpdateHotspot: (hotspotKey: string) => Promise<void>;
selectedHotspot?: RawHotspot;
loadingMeasure={loadingMeasure}
onBranch={isBranch(branchLike)}
onChangeFilters={props.onChangeFilters}
- onShowAllHotspots={props.onShowAllHotspots}
/>
{loading && (
mockFlowLocation,
mockLocation,
mockLoggedInUser,
- mockRouter,
} from '../../../helpers/testMocks';
import { mockEvent, waitAndUpdate } from '../../../helpers/testUtils';
import { SecurityStandard } from '../../../types/security';
});
const location = mockLocation({ query: { hotspots: hotspotKeys.join() } });
- const router = mockRouter();
const wrapper = shallowRender({
location,
- router,
});
await waitAndUpdate(wrapper);
// Reset
(getSecurityHotspots as jest.Mock).mockClear();
(getSecurityHotspotList as jest.Mock).mockClear();
- wrapper.find(SecurityHotspotsAppRenderer).props().onShowAllHotspots();
- expect(router.push).toHaveBeenCalledWith({
- ...location,
- query: { ...location.query, hotspots: undefined },
- });
// Simulate a new location
wrapper.setProps({
component={mockComponent()}
currentUser={mockCurrentUser()}
location={mockLocation()}
- router={mockRouter()}
{...props}
/>
);
import { scrollToElement } from '../../../helpers/scrolling';
import { SecurityStandard } from '../../../types/security';
import { HotspotStatusFilter } from '../../../types/security-hotspots';
-import FilterBar from '../components/FilterBar';
import SecurityHotspotsAppRenderer, {
SecurityHotspotsAppRendererProps,
} from '../SecurityHotspotsAppRenderer';
).toMatchSnapshot('category');
});
-it('should properly propagate the "show all" call', () => {
- const onShowAllHotspots = jest.fn();
- const wrapper = shallowRender({ onShowAllHotspots });
-
- wrapper.find(FilterBar).props().onShowAllHotspots();
-
- expect(onShowAllHotspots).toHaveBeenCalled();
-});
-
describe('side effect', () => {
const fakeElement = document.createElement('span');
const fakeParent = document.createElement('div');
onChangeFilters={jest.fn()}
onHotspotClick={jest.fn()}
onLoadMore={jest.fn()}
- onShowAllHotspots={jest.fn()}
onSwitchStatusFilter={jest.fn()}
onUpdateHotspot={jest.fn()}
onLocationClick={jest.fn()}
onHotspotClick={[Function]}
onLoadMore={[Function]}
onLocationClick={[Function]}
- onShowAllHotspots={[Function]}
onSwitchStatusFilter={[Function]}
onUpdateHotspot={[Function]}
securityCategories={{}}
loadingMeasure={false}
onBranch={false}
onChangeFilters={[MockFunction]}
- onShowAllHotspots={[MockFunction]}
/>
<EmptyHotspotsPage
filterByFile={false}
loadingMeasure={false}
onBranch={false}
onChangeFilters={[MockFunction]}
- onShowAllHotspots={[MockFunction]}
/>
<EmptyHotspotsPage
filterByFile={false}
loadingMeasure={false}
onBranch={false}
onChangeFilters={[MockFunction]}
- onShowAllHotspots={[MockFunction]}
/>
<div
className="layout-page"
loadingMeasure={false}
onBranch={false}
onChangeFilters={[MockFunction]}
- onShowAllHotspots={[MockFunction]}
/>
<EmptyHotspotsPage
filterByFile={false}
*/
import * as React from 'react';
import withCurrentUserContext from '../../../app/components/current-user/withCurrentUserContext';
+import Link from '../../../components/common/Link';
import ButtonToggle from '../../../components/controls/ButtonToggle';
import HelpTooltip from '../../../components/controls/HelpTooltip';
import Select from '../../../components/controls/Select';
import CoverageRating from '../../../components/ui/CoverageRating';
import DeferredSpinner from '../../../components/ui/DeferredSpinner';
import { translate } from '../../../helpers/l10n';
+import { getProjectSecurityHotspots } from '../../../helpers/urls';
import { ComponentQualifier } from '../../../types/component';
import { HotspotFilters, HotspotStatusFilter } from '../../../types/security-hotspots';
import { Component } from '../../../types/types';
loadingMeasure: boolean;
onBranch: boolean;
onChangeFilters: (filters: Partial<HotspotFilters>) => void;
- onShowAllHotspots: () => void;
}
const statusOptions: Array<{ label: string; value: HotspotStatusFilter }> = [
<div className="filter-bar">
<div className="filter-bar-inner display-flex-center">
{isStaticListOfHotspots ? (
- <a
- id="show_all_hotspot"
- onClick={() => props.onShowAllHotspots()}
- role="link"
- tabIndex={0}
- >
+ <Link to={getProjectSecurityHotspots(component.key)}>
{translate('hotspot.filters.show_all')}
- </a>
+ </Link>
) : (
<div className="display-flex-space-between width-100">
<div className="display-flex-center">
});
it('should render correctly when the list of hotspot is static', () => {
- const onShowAllHotspots = jest.fn();
-
const wrapper = shallowRender({
isStaticListOfHotspots: true,
- onShowAllHotspots,
});
expect(wrapper).toMatchSnapshot();
-
- wrapper.find('a').simulate('click');
- expect(onShowAllHotspots).toHaveBeenCalled();
});
it('should trigger onChange for status', () => {
loadingMeasure={false}
onBranch={true}
onChangeFilters={jest.fn()}
- onShowAllHotspots={jest.fn()}
{...props}
/>
);
<div
className="filter-bar-inner display-flex-center"
>
- <a
- id="show_all_hotspot"
- onClick={[Function]}
- role="link"
- tabIndex={0}
+ <ForwardRef(Link)
+ to={
+ {
+ "pathname": "/security_hotspots",
+ "search": "?id=my-project",
+ }
+ }
>
hotspot.filters.show_all
- </a>
+ </ForwardRef(Link)>
</div>
</div>
</div>
};
}
+export function getProjectSecurityHotspots(project: string): To {
+ return {
+ pathname: '/security_hotspots',
+ search: queryToSearch({ id: project }),
+ };
+}
+
export function getProjectQueryUrl(
project: string,
branchParameters?: BranchParameters,