aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorViktor Vorona <viktor.vorona@sonarsource.com>2024-04-24 16:35:11 +0200
committerMatteo Mara <matteo.mara@sonarsource.com>2024-04-30 10:59:04 +0200
commitb0ec1cac4b207f45bf578e61bda423da46605461 (patch)
treef117443efee8fa71f933cb0e0ccc7c9eb33d8e82
parent80e8eb730b5d437a0c0a38087bba9399fe39fb5b (diff)
downloadsonarqube-b0ec1cac4b207f45bf578e61bda423da46605461.tar.gz
sonarqube-b0ec1cac4b207f45bf578e61bda423da46605461.zip
SONAR-22049 Tests for urls helper
-rw-r--r--server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts68
-rw-r--r--server/sonar-web/src/main/js/sonar-aligned/helpers/__tests__/urls-test.ts66
2 files changed, 66 insertions, 68 deletions
diff --git a/server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts
index 9baea69ab1d..0cd087323f2 100644
--- a/server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts
+++ b/server/sonar-web/src/main/js/helpers/__tests__/urls-test.ts
@@ -18,17 +18,11 @@
* 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(
diff --git a/server/sonar-web/src/main/js/sonar-aligned/helpers/__tests__/urls-test.ts b/server/sonar-web/src/main/js/sonar-aligned/helpers/__tests__/urls-test.ts
index 89b2961baf4..9b9defbc7a4 100644
--- a/server/sonar-web/src/main/js/sonar-aligned/helpers/__tests__/urls-test.ts
+++ b/server/sonar-web/src/main/js/sonar-aligned/helpers/__tests__/urls-test.ts
@@ -17,7 +17,11 @@
* 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',
+ }),
+ }),
+ );
+ });
+});