From 48b8689538428a89594ded182d8572f9959bba18 Mon Sep 17 00:00:00 2001 From: guillaume-peoch-sonarsource Date: Tue, 13 Jun 2023 16:44:02 +0200 Subject: [PATCH] [NO JIRA] Fix Code Smells --- .../js/app/components/__tests__/SystemAnnouncement-test.tsx | 3 ++- .../metrics/__tests__/MetricsContextProvider-test.tsx | 2 +- .../src/main/js/apps/account/__tests__/Account-it.tsx | 6 +++--- .../sonar-web/src/main/js/apps/overview/components/App.tsx | 2 +- server/sonar-web/src/main/js/apps/quality-gates/utils.ts | 2 +- .../src/main/js/apps/users/components/UserListItem.tsx | 2 +- .../src/main/js/components/controls/ManagedFilter.tsx | 2 +- .../src/main/js/components/rules/RuleTabViewer.tsx | 2 +- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx index 686e7c50a7c..429b0d4a1e9 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx @@ -36,7 +36,8 @@ jest.mock('lodash', () => { }); it('should display system announcement', async () => { - (getValues as jest.Mock) + jest + .mocked(getValues) .mockResolvedValueOnce([ { key: 'sonar.announcement.displayMessage', diff --git a/server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx b/server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx index 92d438cd1f7..e1a2ddc03de 100644 --- a/server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx +++ b/server/sonar-web/src/main/js/app/components/metrics/__tests__/MetricsContextProvider-test.tsx @@ -30,7 +30,7 @@ jest.mock('../../../../api/metrics', () => ({ it('should call metric', async () => { const metrics = { coverage: mockMetric() }; - (getAllMetrics as jest.Mock).mockResolvedValueOnce(Object.values(metrics)); + jest.mocked(getAllMetrics).mockResolvedValueOnce(Object.values(metrics)); const wrapper = shallowRender(); expect(getAllMetrics).toHaveBeenCalled(); diff --git a/server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx b/server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx index afdf7ead08e..dbacff25417 100644 --- a/server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx +++ b/server/sonar-web/src/main/js/apps/account/__tests__/Account-it.tsx @@ -389,7 +389,7 @@ describe('security page', () => { }); it("should not suggest creating a Project token if the user doesn't have at least one scannable Projects", () => { - (getScannableProjects as jest.Mock).mockResolvedValueOnce({ + jest.mocked(getScannableProjects).mockResolvedValueOnce({ projects: [], }); renderAccountApp( @@ -402,7 +402,7 @@ describe('security page', () => { }); it('should preselect the user token type if the user has no scan rights', async () => { - (getScannableProjects as jest.Mock).mockResolvedValueOnce({ + jest.mocked(getScannableProjects).mockResolvedValueOnce({ projects: [], }); renderAccountApp(mockLoggedInUser(), securityPagePath); @@ -412,7 +412,7 @@ describe('security page', () => { }); it('should preselect the only project the user has access to if they select project token', async () => { - (getScannableProjects as jest.Mock).mockResolvedValueOnce({ + jest.mocked(getScannableProjects).mockResolvedValueOnce({ projects: [ { key: 'project-key-1', diff --git a/server/sonar-web/src/main/js/apps/overview/components/App.tsx b/server/sonar-web/src/main/js/apps/overview/components/App.tsx index 73be0c7cc86..b3af0f38b15 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/App.tsx @@ -69,7 +69,7 @@ export function App(props: AppProps) { branchLike={branchLike} branchLikes={branchLikes} component={component} - hasAnalyses={isPending || isInProgress} + hasAnalyses={isPending ?? isInProgress} projectBinding={projectBinding} /> )} diff --git a/server/sonar-web/src/main/js/apps/quality-gates/utils.ts b/server/sonar-web/src/main/js/apps/quality-gates/utils.ts index 502f32cb511..df0f6dd6c6e 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/utils.ts +++ b/server/sonar-web/src/main/js/apps/quality-gates/utils.ts @@ -243,7 +243,7 @@ export function getPossibleOperators(metric: Metric) { } function metricKeyExists(key: string, metrics: Dict) { - return metrics && metrics[key] !== undefined; + return metrics[key] !== undefined; } function getNoDiffMetric(metric: Metric, metrics: Dict) { diff --git a/server/sonar-web/src/main/js/apps/users/components/UserListItem.tsx b/server/sonar-web/src/main/js/apps/users/components/UserListItem.tsx index a3840b67f3a..cd6bdef46f0 100644 --- a/server/sonar-web/src/main/js/apps/users/components/UserListItem.tsx +++ b/server/sonar-web/src/main/js/apps/users/components/UserListItem.tsx @@ -80,7 +80,7 @@ export default function UserListItem(props: UserListItemProps) { tab.key === TabKeys.WhyIsThisAnIssue) || tabs[0], + selectedTab: tabs.find((tab) => tab.key === TabKeys.WhyIsThisAnIssue) ?? tabs[0], }); } } -- 2.39.5