import { getSecurityHotspotList, getSecurityHotspots } from '../../api/security-hotspots';
import withComponentContext from '../../app/components/componentContext/withComponentContext';
import withCurrentUserContext from '../../app/components/current-user/withCurrentUserContext';
+import withIndexationGuard from '../../components/hoc/withIndexationGuard';
import { Location, Router, withRouter } from '../../components/hoc/withRouter';
import { getLeakValue } from '../../components/measure/utils';
import { getBranchLikeQuery, isPullRequest, isSameBranchLike } from '../../helpers/branch-like';
import { getStandards } from '../../helpers/security-standard';
import { withBranchLikes } from '../../queries/branch';
import { BranchLike } from '../../types/branch-like';
+import { ComponentQualifier } from '../../types/component';
import { MetricKey } from '../../types/metrics';
import { SecurityStandard, Standards } from '../../types/security';
import {
componentDidMount() {
this.mounted = true;
+
this.fetchInitialData();
+
this.registerKeyboardEvents();
}
this.props.router.push({
pathname: this.props.location.pathname,
query: {
+ assignedToMe: undefined,
file: undefined,
fileUuid: undefined,
hotspots: [],
- sinceLeakPeriod: undefined,
- assignedToMe: undefined,
id: this.props.component.key,
+ sinceLeakPeriod: undefined,
},
});
};
render() {
const { branchLike, component } = this.props;
+
const {
filterByCategory,
filterByCWE,
<SecurityHotspotsAppRenderer
branchLike={branchLike}
component={component}
- filters={filters}
filterByCategory={filterByCategory}
filterByCWE={filterByCWE}
filterByFile={filterByFile}
+ filters={filters}
hotspots={hotspots}
hotspotsReviewedMeasure={hotspotsReviewedMeasure}
hotspotsTotal={hotspotsTotal}
loadingMeasure={loadingMeasure}
loadingMore={loadingMore}
onChangeFilters={this.handleChangeFilters}
- onShowAllHotspots={this.handleShowAllHotspots}
onHotspotClick={this.handleHotspotClick}
onLoadMore={this.handleLoadMore}
+ onLocationClick={this.handleLocationClick}
+ onShowAllHotspots={this.handleShowAllHotspots}
onSwitchStatusFilter={this.handleChangeStatusFilter}
onUpdateHotspot={this.handleHotspotUpdate}
- onLocationClick={this.handleLocationClick}
securityCategories={standards[SecurityStandard.SONARSOURCE]}
selectedHotspot={selectedHotspot}
selectedHotspotLocation={selectedHotspotLocationIndex}
}
export default withRouter(
- withComponentContext(withCurrentUserContext(withBranchLikes(SecurityHotspotsApp)))
+ withComponentContext(
+ withCurrentUserContext(
+ withBranchLikes(
+ withIndexationGuard({
+ Component: SecurityHotspotsApp,
+ showIndexationMessage: ({ component }) =>
+ !!(component.qualifier === ComponentQualifier.Application && component.needIssueSync),
+ })
+ )
+ )
+ )
);
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { mount } from 'enzyme';
+
+import { render, screen } from '@testing-library/react';
import * as React from 'react';
import { IndexationContext } from '../../../app/components/indexation/IndexationContext';
-import { IndexationContextInterface } from '../../../types/indexation';
import withIndexationGuard from '../withIndexationGuard';
-it('should not render children because indexation is in progress', () => {
- const wrapper = mountRender();
- expect(wrapper.find(TestComponent).exists()).toBe(false);
-});
+describe('withIndexationGuard', () => {
+ it('should render indexation message when showIndexationMessage returns true', () => {
+ renderComponentWithIndexationGuard(() => true);
+ expect(screen.getByText(/indexation\.page_unavailable\.description/)).toBeInTheDocument();
+ });
-it('should not render children because indexation has failures', () => {
- const wrapper = mountRender({
- status: { isCompleted: true, percentCompleted: 100, hasFailures: true },
+ it('should render children when showIndexationMessage returns false', () => {
+ renderComponentWithIndexationGuard(() => false);
+ expect(screen.getByText('TestComponent')).toBeInTheDocument();
});
- expect(wrapper.find(TestComponent).exists()).toBe(false);
});
-it('should render children because indexation is completed without failures', () => {
- const wrapper = mountRender({
- status: { isCompleted: true, percentCompleted: 100, hasFailures: false },
+function renderComponentWithIndexationGuard(showIndexationMessage: () => boolean) {
+ const TestComponentWithGuard = withIndexationGuard({
+ Component: TestComponent,
+ showIndexationMessage,
});
- expect(wrapper.find(TestComponent).exists()).toBe(true);
-});
-function mountRender(context?: Partial<IndexationContextInterface>) {
- return mount(
+ return render(
<IndexationContext.Provider
value={{
status: { isCompleted: false, percentCompleted: 23, hasFailures: false },
- ...context,
}}
>
<TestComponentWithGuard />
);
}
-class TestComponent extends React.PureComponent {
- render() {
- return <h1>TestComponent</h1>;
- }
+function TestComponent() {
+ return <h1>TestComponent</h1>;
}
-
-const TestComponentWithGuard = withIndexationGuard(TestComponent);
*/
import * as React from 'react';
-import { IndexationContext } from '../../app/components/indexation/IndexationContext';
import PageUnavailableDueToIndexation from '../../app/components/indexation/PageUnavailableDueToIndexation';
-export default function withIndexationGuard<P>(WrappedComponent: React.ComponentType<P>) {
+export default function withIndexationGuard<P>({
+ Component,
+ showIndexationMessage,
+}: {
+ Component: React.ComponentType<P>;
+ showIndexationMessage: (props: P) => boolean;
+}) {
return function WithIndexationGuard(props: React.PropsWithChildren<P>) {
- return (
- <IndexationContext.Consumer>
- {(context) =>
- context?.status.isCompleted && !context?.status.hasFailures ? (
- <WrappedComponent {...props} />
- ) : (
- <PageUnavailableDueToIndexation />
- )
- }
- </IndexationContext.Consumer>
+ return showIndexationMessage(props) ? (
+ <PageUnavailableDueToIndexation />
+ ) : (
+ <Component {...props} />
);
};
}