]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12585 Fix missing releasability badges in portfolio project list
authorJeremy Davis <jeremy.davis@sonarsource.com>
Wed, 6 Nov 2019 07:19:42 +0000 (16:19 +0900)
committerSonarTech <sonartech@sonarsource.com>
Fri, 8 Nov 2019 19:21:12 +0000 (20:21 +0100)
server/sonar-web/src/main/js/apps/code/__tests__/__snapshots__/utils-test.tsx.snap [new file with mode: 0644]
server/sonar-web/src/main/js/apps/code/__tests__/utils-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/code/utils.ts

diff --git a/server/sonar-web/src/main/js/apps/code/__tests__/__snapshots__/utils-test.tsx.snap b/server/sonar-web/src/main/js/apps/code/__tests__/__snapshots__/utils-test.tsx.snap
new file mode 100644 (file)
index 0000000..208dae9
--- /dev/null
@@ -0,0 +1,61 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`getCodeMetrics should return the right metrics for apps 1`] = `
+Array [
+  "alert_status",
+  "ncloc",
+  "bugs",
+  "vulnerabilities",
+  "code_smells",
+  "security_hotspots",
+  "coverage",
+  "duplicated_lines_density",
+]
+`;
+
+exports[`getCodeMetrics should return the right metrics for portfolios 1`] = `
+Array [
+  "releasability_rating",
+  "reliability_rating",
+  "security_rating",
+  "security_review_rating",
+  "sqale_rating",
+  "ncloc",
+]
+`;
+
+exports[`getCodeMetrics should return the right metrics for portfolios 2`] = `
+Array [
+  "releasability_rating",
+  "reliability_rating",
+  "security_rating",
+  "security_review_rating",
+  "sqale_rating",
+  "ncloc",
+  "alert_status",
+]
+`;
+
+exports[`getCodeMetrics should return the right metrics for projects 1`] = `
+Array [
+  "ncloc",
+  "bugs",
+  "vulnerabilities",
+  "code_smells",
+  "security_hotspots",
+  "coverage",
+  "duplicated_lines_density",
+]
+`;
+
+exports[`getCodeMetrics should return the right metrics for projects 2`] = `
+Array [
+  "new_lines",
+  "bugs",
+  "vulnerabilities",
+  "code_smells",
+  "security_hotspots",
+  "new_coverage",
+  "new_duplicated_lines_density",
+]
+`;
diff --git a/server/sonar-web/src/main/js/apps/code/__tests__/utils-test.tsx b/server/sonar-web/src/main/js/apps/code/__tests__/utils-test.tsx
new file mode 100644 (file)
index 0000000..84a22b4
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2019 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import { getChildren } from '../../../api/components';
+import { mockMainBranch, mockPullRequest } from '../../../helpers/testMocks';
+import { addComponent, addComponentChildren, getComponentBreadcrumbs } from '../bucket';
+import { getCodeMetrics, loadMoreChildren, retrieveComponentChildren } from '../utils';
+
+jest.mock('../../../api/components', () => ({
+  getChildren: jest.fn().mockRejectedValue({})
+}));
+
+jest.mock('../bucket', () => ({
+  addComponent: jest.fn(),
+  addComponentBreadcrumbs: jest.fn(),
+  addComponentChildren: jest.fn(),
+  getComponent: jest.fn(),
+  getComponentBreadcrumbs: jest.fn(),
+  getComponentChildren: jest.fn()
+}));
+
+beforeEach(() => {
+  jest.clearAllMocks();
+});
+
+describe('getCodeMetrics', () => {
+  it('should return the right metrics for portfolios', () => {
+    expect(getCodeMetrics('VW')).toMatchSnapshot();
+    expect(getCodeMetrics('VW', undefined, { includeQGStatus: true })).toMatchSnapshot();
+  });
+
+  it('should return the right metrics for apps', () => {
+    expect(getCodeMetrics('APP')).toMatchSnapshot();
+  });
+
+  it('should return the right metrics for projects', () => {
+    expect(getCodeMetrics('TRK', mockMainBranch())).toMatchSnapshot();
+    expect(getCodeMetrics('TRK', mockPullRequest())).toMatchSnapshot();
+  });
+});
+
+describe('retrieveComponentChildren', () => {
+  it('should retrieve children correctly', async () => {
+    const components = [{}, {}];
+    (getChildren as jest.Mock).mockResolvedValueOnce({
+      components,
+      paging: { total: 2, pageIndex: 0 }
+    });
+
+    await retrieveComponentChildren('key', 'TRK', mockMainBranch());
+
+    expect(addComponentChildren).toHaveBeenCalledWith('key', components, 2, 0);
+    expect(addComponent).toHaveBeenCalledTimes(2);
+    expect(getComponentBreadcrumbs).toHaveBeenCalledWith('key');
+  });
+});
+
+describe('loadMoreChildren', () => {
+  it('should load more children', async () => {
+    const components = [{}, {}, {}];
+    (getChildren as jest.Mock).mockResolvedValueOnce({
+      components,
+      paging: { total: 6, pageIndex: 1 }
+    });
+
+    await loadMoreChildren('key', 1, 'TRK', mockMainBranch());
+
+    expect(addComponentChildren).toHaveBeenCalledWith('key', components, 6, 1);
+    expect(addComponent).toHaveBeenCalledTimes(3);
+    expect(getComponentBreadcrumbs).toHaveBeenCalledWith('key');
+  });
+});
index fe238eae14ac69f4936ddc5688846b6b5c1dae9a..2e05df99a9514b85cabbda773c539cbbbc24c332 100644 (file)
@@ -99,9 +99,14 @@ function storeChildrenBreadcrumbs(parentComponentKey: string, children: T.Breadc
   }
 }
 
-export function getCodeMetrics(qualifier: string, branchLike?: T.BranchLike) {
+export function getCodeMetrics(
+  qualifier: string,
+  branchLike?: T.BranchLike,
+  options: { includeQGStatus?: boolean } = {}
+) {
   if (['VW', 'SVW'].includes(qualifier)) {
-    return [...PORTFOLIO_METRICS];
+    const metrics = [...PORTFOLIO_METRICS];
+    return options.includeQGStatus ? metrics.concat('alert_status') : metrics;
   }
   if (qualifier === 'APP') {
     return [...APPLICATION_METRICS];
@@ -144,10 +149,7 @@ export function retrieveComponentChildren(
     });
   }
 
-  const metrics = getCodeMetrics(qualifier, branchLike);
-  if (['VW', 'SVW'].includes(qualifier)) {
-    metrics.push('alert_status');
-  }
+  const metrics = getCodeMetrics(qualifier, branchLike, { includeQGStatus: true });
 
   return getChildren(componentKey, metrics, {
     ps: PAGE_SIZE,
@@ -212,7 +214,7 @@ export function loadMoreChildren(
   qualifier: string,
   branchLike?: T.BranchLike
 ): Promise<Children> {
-  const metrics = getCodeMetrics(qualifier, branchLike);
+  const metrics = getCodeMetrics(qualifier, branchLike, { includeQGStatus: true });
 
   return getChildren(componentKey, metrics, {
     ps: PAGE_SIZE,