]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22049 Tests for urls helper
authorViktor Vorona <viktor.vorona@sonarsource.com>
Wed, 24 Apr 2024 14:35:11 +0000 (16:35 +0200)
committerMatteo Mara <matteo.mara@sonarsource.com>
Tue, 30 Apr 2024 08:59:04 +0000 (10:59 +0200)
server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts
server/sonar-web/src/main/js/sonar-aligned/helpers/__tests__/urls-test.ts

index 9baea69ab1d5dccac8e72ffd36c6e403c64a558f..0cd087323f20fec096a46108515e037a475344c6 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import { searchParamsToQuery } from '~sonar-aligned/helpers/router';
-import {
-  getComponentIssuesUrl,
-  getComponentSecurityHotspotsUrl,
-  queryToSearch,
-} from '~sonar-aligned/helpers/urls';
-import { DEFAULT_ISSUES_QUERY } from '../../components/shared/utils';
+import { queryToSearch } from '~sonar-aligned/helpers/urls';
 import { AlmKeys } from '../../types/alm-settings';
 import { ComponentQualifier } from '../../types/component';
 import { IssueType } from '../../types/issues';
 import { MeasurePageView } from '../../types/measures';
-import { SecurityStandard } from '../../types/security';
 import { mockBranch, mockMainBranch, mockPullRequest } from '../mocks/branch-like';
 import { mockLocation } from '../testMocks';
 import {
@@ -94,66 +88,6 @@ describe('getComponentAdminUrl', () => {
   });
 });
 
-describe('#getComponentIssuesUrl', () => {
-  it('should work without parameters', () => {
-    expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY)).toEqual(
-      expect.objectContaining({
-        pathname: '/project/issues',
-        search: queryToSearch({ id: SIMPLE_COMPONENT_KEY }),
-      }),
-    );
-  });
-
-  it('should work with parameters', () => {
-    expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, DEFAULT_ISSUES_QUERY)).toEqual(
-      expect.objectContaining({
-        pathname: '/project/issues',
-        search: queryToSearch({ ...DEFAULT_ISSUES_QUERY, id: SIMPLE_COMPONENT_KEY }),
-      }),
-    );
-  });
-});
-
-describe('#getComponentSecurityHotspotsUrl', () => {
-  it('should work with no extra parameters', () => {
-    expect(getComponentSecurityHotspotsUrl(SIMPLE_COMPONENT_KEY)).toEqual(
-      expect.objectContaining({
-        pathname: '/security_hotspots',
-        search: queryToSearch({ id: SIMPLE_COMPONENT_KEY }),
-      }),
-    );
-  });
-
-  it('should forward some query parameters', () => {
-    expect(
-      getComponentSecurityHotspotsUrl(SIMPLE_COMPONENT_KEY, undefined, {
-        inNewCodePeriod: 'true',
-        [SecurityStandard.OWASP_TOP10_2021]: 'a1',
-        [SecurityStandard.CWE]: '213',
-        [SecurityStandard.OWASP_TOP10]: 'a1',
-        [SecurityStandard.SONARSOURCE]: 'command-injection',
-        [SecurityStandard.PCI_DSS_3_2]: '4.2',
-        [SecurityStandard.PCI_DSS_4_0]: '4.1',
-        ignoredParam: '1234',
-      }),
-    ).toEqual(
-      expect.objectContaining({
-        pathname: '/security_hotspots',
-        search: queryToSearch({
-          id: SIMPLE_COMPONENT_KEY,
-          inNewCodePeriod: 'true',
-          [SecurityStandard.OWASP_TOP10_2021]: 'a1',
-          [SecurityStandard.OWASP_TOP10]: 'a1',
-          [SecurityStandard.SONARSOURCE]: 'command-injection',
-          [SecurityStandard.CWE]: '213',
-          [SecurityStandard.PCI_DSS_3_2]: '4.2',
-          [SecurityStandard.PCI_DSS_4_0]: '4.1',
-        }),
-      }),
-    );
-  });
-});
-
 describe('#getComponentOverviewUrl', () => {
   it('should return a portfolio url for a portfolio', () => {
     expect(getComponentOverviewUrl(SIMPLE_COMPONENT_KEY, ComponentQualifier.Portfolio)).toEqual(
index 89b2961baf4b582c835b5100c2fad5f2a92849da..9b9defbc7a40d4348d61f6cdf48fcf3b3dd91245 100644 (file)
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { queryToSearch } from '../urls';
+import { DEFAULT_ISSUES_QUERY } from '../../../components/shared/utils';
+import { SecurityStandard } from '../../../types/security';
+import { getComponentIssuesUrl, getComponentSecurityHotspotsUrl, queryToSearch } from '../urls';
+
+const SIMPLE_COMPONENT_KEY = 'sonarqube';
 
 describe('queryToSearch', () => {
   it('should return query by default', () => {
@@ -36,3 +40,63 @@ describe('queryToSearch', () => {
     expect(queryToSearch({ key: ['value1', 'value2'] })).toBe('?key=value1&key=value2');
   });
 });
+
+describe('#getComponentIssuesUrl', () => {
+  it('should work without parameters', () => {
+    expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY)).toEqual(
+      expect.objectContaining({
+        pathname: '/project/issues',
+        search: queryToSearch({ id: SIMPLE_COMPONENT_KEY }),
+      }),
+    );
+  });
+
+  it('should work with parameters', () => {
+    expect(getComponentIssuesUrl(SIMPLE_COMPONENT_KEY, DEFAULT_ISSUES_QUERY)).toEqual(
+      expect.objectContaining({
+        pathname: '/project/issues',
+        search: queryToSearch({ ...DEFAULT_ISSUES_QUERY, id: SIMPLE_COMPONENT_KEY }),
+      }),
+    );
+  });
+});
+
+describe('#getComponentSecurityHotspotsUrl', () => {
+  it('should work with no extra parameters', () => {
+    expect(getComponentSecurityHotspotsUrl(SIMPLE_COMPONENT_KEY)).toEqual(
+      expect.objectContaining({
+        pathname: '/security_hotspots',
+        search: queryToSearch({ id: SIMPLE_COMPONENT_KEY }),
+      }),
+    );
+  });
+
+  it('should forward some query parameters', () => {
+    expect(
+      getComponentSecurityHotspotsUrl(SIMPLE_COMPONENT_KEY, undefined, {
+        inNewCodePeriod: 'true',
+        [SecurityStandard.OWASP_TOP10_2021]: 'a1',
+        [SecurityStandard.CWE]: '213',
+        [SecurityStandard.OWASP_TOP10]: 'a1',
+        [SecurityStandard.SONARSOURCE]: 'command-injection',
+        [SecurityStandard.PCI_DSS_3_2]: '4.2',
+        [SecurityStandard.PCI_DSS_4_0]: '4.1',
+        ignoredParam: '1234',
+      }),
+    ).toEqual(
+      expect.objectContaining({
+        pathname: '/security_hotspots',
+        search: queryToSearch({
+          id: SIMPLE_COMPONENT_KEY,
+          inNewCodePeriod: 'true',
+          [SecurityStandard.OWASP_TOP10_2021]: 'a1',
+          [SecurityStandard.OWASP_TOP10]: 'a1',
+          [SecurityStandard.SONARSOURCE]: 'command-injection',
+          [SecurityStandard.CWE]: '213',
+          [SecurityStandard.PCI_DSS_3_2]: '4.2',
+          [SecurityStandard.PCI_DSS_4_0]: '4.1',
+        }),
+      }),
+    );
+  });
+});