import { mockSourceLine } from '../../helpers/mocks/sources';
import { getStandards } from '../../helpers/security-standard';
import { mockPaging, mockRuleDetails, mockUser } from '../../helpers/testMocks';
-import { BranchParameters } from '../../types/branch-like';
import {
Hotspot,
HotspotAssignRequest,
});
};
- handleGetSecurityHotspotList = () => {
+ handleGetSecurityHotspotList = (
+ hotspotKeys: string[],
+ data: {
+ projectKey: string;
+ branch?: string;
+ }
+ ) => {
+ if (data?.branch === 'b1') {
+ return this.reply({
+ paging: mockPaging(),
+ hotspots: [
+ mockRawHotspot({
+ assignee: 'John Doe',
+ key: 'b1-test-1',
+ message: "'F' is a magic number.",
+ }),
+ mockRawHotspot({ assignee: 'John Doe', key: 'b1-test-2' }),
+ ].filter((h) => hotspotKeys.includes(h.key) || hotspotKeys.length === 0),
+ components: [
+ {
+ key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed:index.php',
+ qualifier: 'FIL',
+ name: 'index.php',
+ longName: 'index.php',
+ path: 'index.php',
+ },
+ {
+ key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed',
+ qualifier: 'TRK',
+ name: 'benflix',
+ longName: 'benflix',
+ },
+ ],
+ });
+ }
return this.reply({
paging: mockPaging(),
- hotspots: [mockRawHotspot({ assignee: 'John Doe' })],
+ hotspots: this.mockRawHotspots(false).filter(
+ (h) => hotspotKeys.includes(h.key) || hotspotKeys.length === 0
+ ),
components: [
{
key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed:index.php',
});
};
- handleGetSecurityHotspots = (
- data: {
- projectKey: string;
- p: number;
- ps: number;
- status?: HotspotStatus;
- resolution?: HotspotResolution;
- onlyMine?: boolean;
- inNewCodePeriod?: boolean;
- } & BranchParameters
- ) => {
+ handleGetSecurityHotspots = (data: {
+ projectKey: string;
+ p: number;
+ ps: number;
+ status?: HotspotStatus;
+ resolution?: HotspotResolution;
+ onlyMine?: boolean;
+ inNewCodePeriod?: boolean;
+ branch?: string;
+ }) => {
+ if (data?.branch === 'b1') {
+ return this.reply({
+ paging: mockPaging({ pageIndex: 1, pageSize: data.ps, total: 2 }),
+ hotspots: [
+ mockRawHotspot({
+ assignee: 'John Doe',
+ key: 'b1-test-1',
+ message: "'F' is a magic number.",
+ }),
+ mockRawHotspot({ assignee: 'John Doe', key: 'b1-test-2' }),
+ ],
+ components: [
+ {
+ key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed:index.php',
+ qualifier: 'FIL',
+ name: 'index.php',
+ longName: 'index.php',
+ path: 'index.php',
+ },
+ {
+ key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed',
+ qualifier: 'TRK',
+ name: 'benflix',
+ longName: 'benflix',
+ },
+ ],
+ });
+ }
+
return this.reply({
paging: mockPaging({ pageIndex: 1, pageSize: data.ps, total: this.hotspots.length }),
hotspots: this.mockRawHotspots(data.onlyMine),
reset = () => {
this.hotspots = [
+ mockHotspot({
+ assignee: 'John Doe',
+ key: 'b1-test-1',
+ message: "'F' is a magic number.",
+ }),
+ mockHotspot({ assignee: 'John Doe', key: 'b1-test-2' }),
mockHotspot({ key: 'test-1', status: HotspotStatus.TO_REVIEW }),
mockHotspot({
key: 'test-2',
import SecurityHotspotServiceMock from '../../../api/mocks/SecurityHotspotServiceMock';
import { getSecurityHotspots, setSecurityHotspotStatus } from '../../../api/security-hotspots';
import { searchUsers } from '../../../api/users';
-import { mockMainBranch } from '../../../helpers/mocks/branch-like';
+import { mockBranch, mockMainBranch } from '../../../helpers/mocks/branch-like';
import { mockComponent } from '../../../helpers/mocks/component';
import { mockLoggedInUser } from '../../../helpers/testMocks';
import { renderAppWithComponentContext } from '../../../helpers/testReactTestingUtils';
+import { ComponentContextShape } from '../../../types/component';
import SecurityHotspotsApp from '../SecurityHotspotsApp';
jest.mock('../../../api/measures');
changeStatus: byRole('button', { name: 'hotspots.status.change_status' }),
hotspotTitle: (name: string | RegExp) => byRole('heading', { name }),
hotspotStatus: byRole('heading', { name: 'status: hotspots.status_option.FIXED' }),
- hotpostListTitle: byRole('heading', { name: 'hotspots.list_title.TO_REVIEW.2' }),
+ hotpostListTitle: byRole('heading', { name: 'hotspots.list_title.TO_REVIEW.4' }),
hotspotCommentBox: byRole('textbox', { name: 'hotspots.comment.field' }),
commentSubmitButton: byRole('button', { name: 'hotspots.comment.submit' }),
commentEditButton: byRole('button', { name: 'issue.comment.edit' }),
handler.reset();
});
+it('should navigate when comming from SonarLint', async () => {
+ // On main branch
+ const rtl = renderSecurityHotspotsApp(
+ 'security_hotspots?id=guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed&hotspots=test-1'
+ );
+
+ expect(await ui.hotspotTitle(/'3' is a magic number./).find()).toBeInTheDocument();
+
+ // On specific branch
+ rtl.unmount();
+ renderSecurityHotspotsApp(
+ 'security_hotspots?id=guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed&hotspots=b1-test-1&branch=b1',
+ { branchLike: mockBranch({ name: 'b1' }) }
+ );
+
+ expect(await ui.hotspotTitle(/'F' is a magic number./).find()).toBeInTheDocument();
+});
+
it('should be able to self-assign a hotspot', async () => {
const user = userEvent.setup();
renderSecurityHotspotsApp();
expect(screen.queryByText(`${comment} test`)).not.toBeInTheDocument();
});
-function renderSecurityHotspotsApp(navigateTo?: string) {
- renderAppWithComponentContext(
+function renderSecurityHotspotsApp(
+ navigateTo?: string,
+ component?: Partial<ComponentContextShape>
+) {
+ return renderAppWithComponentContext(
'security_hotspots',
() => <Route path="security_hotspots" element={<SecurityHotspotsApp />} />,
{
key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed',
name: 'benflix',
}),
+ ...component,
}
);
}