]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13258 Sort release plugin by date
authorMathieu Suen <mathieu.suen@sonarsource.com>
Thu, 7 Jan 2021 15:19:30 +0000 (16:19 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 12 Jan 2021 20:26:06 +0000 (20:26 +0000)
server/sonar-web/src/main/js/apps/issues/sidebar/__tests__/__snapshots__/FileFacet-test.tsx.snap
server/sonar-web/src/main/js/apps/marketplace/__tests__/PluginUpdates-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/marketplace/__tests__/__snapshots__/PluginUpdates-test.tsx.snap [new file with mode: 0644]
server/sonar-web/src/main/js/apps/marketplace/components/PluginChangeLog.tsx
server/sonar-web/src/main/js/apps/marketplace/components/PluginUpdates.tsx
server/sonar-web/src/main/js/apps/marketplace/components/__tests__/PluginChangeLog-test.tsx
server/sonar-web/src/main/js/apps/marketplace/components/__tests__/__snapshots__/PluginChangeLog-test.tsx.snap

index 7b6d8c387212797401e4f772afb3c4156672c73f..011f2b6c056336dae465e75e967ff145039dc43d 100644 (file)
@@ -37,6 +37,7 @@ exports[`should render correctly 2`] = `
   />
   <React.Fragment>
     foo
+    /
     <React.Fragment>
       <mark>
         bar
diff --git a/server/sonar-web/src/main/js/apps/marketplace/__tests__/PluginUpdates-test.tsx b/server/sonar-web/src/main/js/apps/marketplace/__tests__/PluginUpdates-test.tsx
new file mode 100644 (file)
index 0000000..f83b4be
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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 { shallow } from 'enzyme';
+import * as React from 'react';
+import PluginUpdates, { PluginUpdatesProps } from '../components/PluginUpdates';
+
+it('should render correctly', () => {
+  expect(shallowRender()).toMatchSnapshot('default');
+  expect(
+    shallowRender({
+      updates: [
+        {
+          requires: [],
+          status: '',
+          release: { date: '2012-02-10', version: '1.3' }
+        },
+        {
+          requires: [],
+          status: '',
+          release: { date: '2012-02-01', version: '1.1' }
+        },
+        {
+          requires: [],
+          status: '',
+          release: { date: '2012-02-02', version: '1.2' }
+        }
+      ]
+    })
+  ).toMatchSnapshot('with status');
+});
+
+function shallowRender(props: Partial<PluginUpdatesProps> = {}) {
+  return shallow<PluginUpdatesProps>(<PluginUpdates {...props} />);
+}
diff --git a/server/sonar-web/src/main/js/apps/marketplace/__tests__/__snapshots__/PluginUpdates-test.tsx.snap b/server/sonar-web/src/main/js/apps/marketplace/__tests__/__snapshots__/PluginUpdates-test.tsx.snap
new file mode 100644 (file)
index 0000000..00144a8
--- /dev/null
@@ -0,0 +1,75 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly: default 1`] = `""`;
+
+exports[`should render correctly: with status 1`] = `
+<li
+  className="spacer-top"
+>
+  <strong>
+    marketplace.updates
+    :
+  </strong>
+  <ul
+    className="little-spacer-top"
+  >
+    <PluginUpdateItem
+      key="1.3"
+      release={
+        Object {
+          "date": "2012-02-10",
+          "version": "1.3",
+        }
+      }
+      update={
+        Object {
+          "release": Object {
+            "date": "2012-02-10",
+            "version": "1.3",
+          },
+          "requires": Array [],
+          "status": "",
+        }
+      }
+    />
+    <PluginUpdateItem
+      key="1.1"
+      release={
+        Object {
+          "date": "2012-02-01",
+          "version": "1.1",
+        }
+      }
+      update={
+        Object {
+          "release": Object {
+            "date": "2012-02-01",
+            "version": "1.1",
+          },
+          "requires": Array [],
+          "status": "",
+        }
+      }
+    />
+    <PluginUpdateItem
+      key="1.2"
+      release={
+        Object {
+          "date": "2012-02-02",
+          "version": "1.2",
+        }
+      }
+      update={
+        Object {
+          "release": Object {
+            "date": "2012-02-02",
+            "version": "1.2",
+          },
+          "requires": Array [],
+          "status": "",
+        }
+      }
+    />
+  </ul>
+</li>
+`;
index 69bcc54143ae9195944801a41f4e204ce4dc2447..306b79c07c09506d3211b2bb0d9366246c0daac1 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
+import { sortBy } from 'lodash';
 import * as React from 'react';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import { Release, Update } from '../../../types/plugins';
@@ -33,7 +34,10 @@ export default function PluginChangeLog({ release, update }: Props) {
       <h6>{translate('changelog')}</h6>
       <ul className="js-plugin-changelog-list">
         {update.previousUpdates &&
-          update.previousUpdates.map(previousUpdate =>
+          sortBy(
+            update.previousUpdates,
+            prevUpdate => prevUpdate.release?.date
+          ).map(previousUpdate =>
             previousUpdate.release ? (
               <PluginChangeLogItem
                 key={previousUpdate.release.version}
index f49ddd5f74ad2a9dbc74166be327767d6450ff42..cc09aeb68d9013ecd99a736dd5378685815ee66c 100644 (file)
@@ -22,11 +22,11 @@ import { translate } from 'sonar-ui-common/helpers/l10n';
 import { Update } from '../../../types/plugins';
 import PluginUpdateItem from './PluginUpdateItem';
 
-interface Props {
+export interface PluginUpdatesProps {
   updates?: Update[];
 }
 
-export default function PluginUpdates({ updates }: Props) {
+export default function PluginUpdates({ updates }: PluginUpdatesProps) {
   if (!updates || updates.length <= 0) {
     return null;
   }
index c7ad77c0b52875b492954455328355164e3acb94..b889f5d94df420da84ab577d4c2b4425af18276a 100644 (file)
@@ -37,6 +37,16 @@ function shallowRender(props: Partial<Props> = {}) {
       }}
       update={{
         previousUpdates: [
+          {
+            release: {
+              version: '0.11',
+              date: '2018-06-08',
+              description: 'Change version description',
+              changeLogUrl: 'https://my.change.log/url'
+            },
+            requires: [],
+            status: 'COMPATIBLE'
+          },
           {
             release: {
               version: '0.10',
index c45bedc60a9b6592beddf4a4c6fed9e68fcb3d2e..faa44946273d7392a4b1e508f2b096c70c335049 100644 (file)
@@ -33,6 +33,29 @@ exports[`should render correctly 1`] = `
         }
       }
     />
+    <PluginChangeLogItem
+      key="0.11"
+      release={
+        Object {
+          "changeLogUrl": "https://my.change.log/url",
+          "date": "2018-06-08",
+          "description": "Change version description",
+          "version": "0.11",
+        }
+      }
+      update={
+        Object {
+          "release": Object {
+            "changeLogUrl": "https://my.change.log/url",
+            "date": "2018-06-08",
+            "description": "Change version description",
+            "version": "0.11",
+          },
+          "requires": Array [],
+          "status": "COMPATIBLE",
+        }
+      }
+    />
     <PluginChangeLogItem
       release={
         Object {
@@ -45,6 +68,16 @@ exports[`should render correctly 1`] = `
       update={
         Object {
           "previousUpdates": Array [
+            Object {
+              "release": Object {
+                "changeLogUrl": "https://my.change.log/url",
+                "date": "2018-06-08",
+                "description": "Change version description",
+                "version": "0.11",
+              },
+              "requires": Array [],
+              "status": "COMPATIBLE",
+            },
             Object {
               "release": Object {
                 "changeLogUrl": "https://my.change.log/url",