From b0ec1cac4b207f45bf578e61bda423da46605461 Mon Sep 17 00:00:00 2001 From: Viktor Vorona Date: Wed, 24 Apr 2024 16:35:11 +0200 Subject: [PATCH] SONAR-22049 Tests for urls helper --- .../main/js/helpers/__tests__/urls-test.ts | 68 +------------------ .../helpers/__tests__/urls-test.ts | 66 +++++++++++++++++- 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', + }), + }), + ); + }); +}); -- 2.39.5