]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18561 Add IT to document SonarLint URL access
authorMathieu Suen <mathieu.suen@sonarsource.com>
Mon, 27 Feb 2023 08:34:36 +0000 (09:34 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 1 Mar 2023 20:03:05 +0000 (20:03 +0000)
server/sonar-web/src/main/js/api/mocks/SecurityHotspotServiceMock.ts
server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx

index d906c95bd4d5fe31044ac1667fc910f3d5c40de7..32ba90c04267bd456e08c788fc99f0f1bab4390b 100644 (file)
@@ -27,7 +27,6 @@ import {
 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,
@@ -132,10 +131,46 @@ export default class SecurityHotspotServiceMock {
     });
   };
 
-  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',
@@ -154,17 +189,45 @@ export default class SecurityHotspotServiceMock {
     });
   };
 
-  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),
@@ -245,6 +308,12 @@ export default class SecurityHotspotServiceMock {
 
   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',
index a7ba5c392ef07d7dd893297b21cd642597ba8a86..0ee7b5b5e7475d406f22a20538d879708619b3a3 100644 (file)
@@ -26,10 +26,11 @@ import { byDisplayValue, byRole, byTestId, byText } from 'testing-library-select
 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');
@@ -59,7 +60,7 @@ const ui = {
   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' }),
@@ -81,6 +82,24 @@ afterEach(() => {
   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();
@@ -242,8 +261,11 @@ it('should be able to add, edit and remove own comments', async () => {
   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 />} />,
     {
@@ -261,6 +283,7 @@ function renderSecurityHotspotsApp(navigateTo?: string) {
         key: 'guillaume-peoch-sonarsource_benflix_AYGpXq2bd8qy4i0eO9ed',
         name: 'benflix',
       }),
+      ...component,
     }
   );
 }