From 3c93ddc45bbd9210d55a9d6b7a8802e330247640 Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 22 Oct 2019 10:15:56 +0200 Subject: [PATCH] SONAR-12395 Upgrade download link should point to correct edition --- .../system-upgrade/SystemUpgradeForm.tsx | 15 +- .../SystemUpgradeIntermediate.tsx | 41 +- .../system-upgrade/SystemUpgradeItem.tsx | 48 ++- .../system-upgrade/SystemUpgradeNotif.tsx | 3 +- .../__tests__/SystemUpgradeForm-test.tsx | 11 +- .../__tests__/SystemUpgradeItem-test.tsx | 90 ++-- .../__tests__/SystemUpgradeNotif-test.tsx | 34 +- .../SystemUpgradeForm-test.tsx.snap | 2 + .../SystemUpgradeItem-test.tsx.snap | 390 +++++++++++++++++- .../SystemUpgradeNotif-test.tsx.snap | 71 +++- 10 files changed, 601 insertions(+), 104 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeForm.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeForm.tsx index a6de6790b7f..fa0fbc96707 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeForm.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeForm.tsx @@ -21,23 +21,27 @@ import * as React from 'react'; import { ResetButtonLink } from 'sonar-ui-common/components/controls/buttons'; import Modal from 'sonar-ui-common/components/controls/Modal'; import { translate } from 'sonar-ui-common/helpers/l10n'; +import { withAppState } from '../../../../components/hoc/withAppState'; +import { EditionKey } from '../../../../types/editions'; +import { SystemUpgrade } from '../../../../types/system'; import SystemUpgradeItem from './SystemUpgradeItem'; interface Props { - systemUpgrades: T.SystemUpgrade[][]; + appState: Pick; onClose: () => void; + systemUpgrades: SystemUpgrade[][]; } interface State { upgrading: boolean; } -export default class SystemUpgradeForm extends React.PureComponent { +export class SystemUpgradeForm extends React.PureComponent { state: State = { upgrading: false }; render() { const { upgrading } = this.state; - const { systemUpgrades } = this.props; + const { appState, systemUpgrades } = this.props; const header = translate('system.system_upgrade'); return ( @@ -47,6 +51,9 @@ export default class SystemUpgradeForm extends React.PureComponent
{systemUpgrades.map((upgrades, idx) => ( ); } } + +export default withAppState(SystemUpgradeForm); diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeIntermediate.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeIntermediate.tsx index 86135043784..1b1902a67bb 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeIntermediate.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeIntermediate.tsx @@ -22,10 +22,11 @@ import { ButtonLink } from 'sonar-ui-common/components/controls/buttons'; import DropdownIcon from 'sonar-ui-common/components/icons/DropdownIcon'; import { translate } from 'sonar-ui-common/helpers/l10n'; import DateFormatter from '../../../../components/intl/DateFormatter'; +import { SystemUpgrade } from '../../../../types/system'; interface Props { className?: string; - upgrades: T.SystemUpgrade[]; + upgrades: SystemUpgrade[]; } interface State { @@ -57,24 +58,26 @@ export default class SystemUpgradeIntermediate extends React.PureComponent (
- - {formattedDate => ( -

- SonarQube {upgrade.version} - {formattedDate} - {upgrade.changeLogUrl && ( - - {translate('system.release_notes')} - - )} -

- )} -
-

{upgrade.description}

+ {upgrade.releaseDate && ( + + {formattedDate => ( +

+ SonarQube {upgrade.version} + {formattedDate} + {upgrade.changeLogUrl && ( + + {translate('system.release_notes')} + + )} +

+ )} +
+ )} + {upgrade.description &&

{upgrade.description}

}
))}
diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeItem.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeItem.tsx index 71494e0ab77..7d3a870ab99 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeItem.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeItem.tsx @@ -21,22 +21,34 @@ import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n'; import DateFormatter from '../../../../components/intl/DateFormatter'; +import { + getEdition, + getEditionDownloadFilename, + getEditionDownloadUrl +} from '../../../../helpers/editions'; +import { EditionKey } from '../../../../types/editions'; +import { SystemUpgrade } from '../../../../types/system'; import SystemUpgradeIntermediate from './SystemUpgradeIntermediate'; interface Props { - type?: string; - systemUpgrades: T.SystemUpgrade[]; + edition: EditionKey | undefined; + type: string; + systemUpgrades: SystemUpgrade[]; } -export default function SystemUpgradeItem({ type, systemUpgrades }: Props) { +export default function SystemUpgradeItem(props: Props) { + const { edition, type, systemUpgrades } = props; const lastUpgrade = systemUpgrades[0]; + const downloadUrl = getEditionDownloadUrl( + getEdition(edition || EditionKey.community), + lastUpgrade + ); + return (
- {type && ( -

- {type} -

- )} +

+ {type} +

{lastUpgrade.description}

- - {formattedDate => ( - {translateWithParameters('system.released_x', formattedDate)} - )} - + {lastUpgrade.releaseDate && ( + + {formattedDate => ( + {translateWithParameters('system.released_x', formattedDate)} + )} + + )} {lastUpgrade.changeLogUrl && ( + download={getEditionDownloadFilename(downloadUrl)} + href={downloadUrl} + rel="noopener noreferrer" + target="_blank"> {translateWithParameters('system.download_x', lastUpgrade.version)} {translate('system.how_to_upgrade')} diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeNotif.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeNotif.tsx index 9db71aa7c22..e76bf1de85a 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeNotif.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/SystemUpgradeNotif.tsx @@ -22,11 +22,12 @@ import { Button } from 'sonar-ui-common/components/controls/buttons'; import { Alert } from 'sonar-ui-common/components/ui/Alert'; import { translate } from 'sonar-ui-common/helpers/l10n'; import { getSystemUpgrades } from '../../../../api/system'; +import { SystemUpgrade } from '../../../../types/system'; import { groupUpgrades, sortUpgrades } from '../../utils'; import SystemUpgradeForm from './SystemUpgradeForm'; interface State { - systemUpgrades: T.SystemUpgrade[][]; + systemUpgrades: SystemUpgrade[][]; openSystemUpgradeForm: boolean; } diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeForm-test.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeForm-test.tsx index be4a15b7a33..e78ca01b834 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeForm-test.tsx @@ -19,7 +19,8 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; -import SystemUpgradeForm from '../SystemUpgradeForm'; +import { EditionKey } from '../../../../../types/editions'; +import { SystemUpgradeForm } from '../SystemUpgradeForm'; const UPGRADES = [ [ @@ -70,6 +71,12 @@ const UPGRADES = [ it('should display correctly', () => { expect( - shallow() + shallow( + + ) ).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeItem-test.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeItem-test.tsx index ef7b7c632d2..dfde4ad1d4d 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeItem-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeItem-test.tsx @@ -19,41 +19,65 @@ */ import { shallow } from 'enzyme'; import * as React from 'react'; +import { EditionKey } from '../../../../../types/editions'; import SystemUpgradeItem from '../SystemUpgradeItem'; -const UPGRADES = [ - { - version: '5.6.7', - description: 'Version 5.6.7 description', - releaseDate: '2017-03-01', - changeLogUrl: 'changelogurl', - downloadUrl: 'downloadurl', - plugins: {} - }, - { - version: '5.6.6', - description: 'Version 5.6.6 description', - releaseDate: '2017-04-02', - changeLogUrl: 'changelogurl', - downloadUrl: 'downloadurl', - plugins: {} - }, - { - version: '5.6.5', - description: 'Version 5.6.5 description', - releaseDate: '2017-03-01', - changeLogUrl: 'changelogurl', - downloadUrl: 'downloadurl', - plugins: {} - } -]; - it('should display correctly', () => { - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); + expect(shallowRender()).toMatchSnapshot(); + expect(shallowRender({ edition: EditionKey.developer })).toMatchSnapshot(); + expect(shallowRender({ edition: EditionKey.enterprise })).toMatchSnapshot(); + expect(shallowRender({ edition: EditionKey.datacenter })).toMatchSnapshot(); + // Fallback to Community. + expect( + shallowRender({ + edition: EditionKey.datacenter, + systemUpgrades: [ + { + version: '5.6.7', + description: 'Version 5.6.7 description', + releaseDate: '2017-03-01', + changeLogUrl: 'http://changelog.url/', + downloadUrl: 'http://download.url/community' + } + ] + }) + ).toMatchSnapshot(); }); -it('should display a badge', () => { - const wrapper = shallow(); - expect(wrapper.find('h1').exists()).toBeTruthy(); -}); +function shallowRender(props = {}) { + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeNotif-test.tsx b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeNotif-test.tsx index 28dcdf86aa0..eb1d7c7bdd0 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeNotif-test.tsx +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/SystemUpgradeNotif-test.tsx @@ -21,6 +21,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { click, waitAndUpdate } from 'sonar-ui-common/helpers/testUtils'; +import { getSystemUpgrades } from '../../../../../api/system'; import SystemUpgradeNotif from '../SystemUpgradeNotif'; jest.mock('../../../../../api/system', () => ({ @@ -73,36 +74,31 @@ jest.mock('../../../../../api/system', () => ({ ) })); -const getSystemUpgrades = require('../../../../../api/system').getSystemUpgrades as jest.Mock; - beforeEach(() => { - getSystemUpgrades.mockClear(); + jest.clearAllMocks(); }); -it('should display correctly', async () => { - const wrapper = shallow(); - expect(wrapper.type()).toBeNull(); +it('should render correctly', async () => { + const wrapper = shallowRender(); await waitAndUpdate(wrapper); + expect(getSystemUpgrades).toHaveBeenCalled(); + + expect(wrapper).toMatchSnapshot(); + + click(wrapper.find('Button')); expect(wrapper).toMatchSnapshot(); }); it('should display nothing', async () => { - getSystemUpgrades.mockImplementationOnce(() => { + (getSystemUpgrades as jest.Mock).mockImplementationOnce(() => { return Promise.resolve({ updateCenterRefresh: '', upgrades: [] }); }); - const wrapper = shallow(); + const wrapper = shallowRender(); await waitAndUpdate(wrapper); - expect(wrapper.type()).toBeNull(); -}); -it('should fetch upgrade when mounting', () => { - shallow(); - expect(getSystemUpgrades).toHaveBeenCalled(); + expect(wrapper.type()).toBeNull(); }); -it('should open the upgrade form', async () => { - const wrapper = shallow(); - await waitAndUpdate(wrapper); - click(wrapper.find('Button')); - expect(wrapper.find('SystemUpgradeForm').exists()).toBeTruthy(); -}); +function shallowRender() { + return shallow(); +} diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeForm-test.tsx.snap index d061c790af2..6301f09e45c 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeForm-test.tsx.snap @@ -16,6 +16,7 @@ exports[`should display correctly 1`] = ` className="modal-body" > +

+ + Latest Version + +

+

+ + SonarQube + 5.6.7 + , + } + } + /> +

+

+ Version 5.6.7 description +

+ + + +
+`; + +exports[`should display correctly 2`] = ` +
+

+ + Latest Version + +

+

+ + SonarQube + 5.6.7 + , + } + } + /> +

+

+ Version 5.6.7 description +

+ + + +
+`; + +exports[`should display correctly 3`] = ` +
+

+ + Latest Version + +

@@ -46,18 +243,18 @@ exports[`should display correctly 1`] = ` upgrades={ Array [ Object { - "changeLogUrl": "changelogurl", + "changeLogUrl": "http://changelog.url/", "description": "Version 5.6.6 description", - "downloadUrl": "downloadurl", - "plugins": Object {}, + "downloadDeveloperUrl": "http://download.url/developer", + "downloadUrl": "http://download.url/community", "releaseDate": "2017-04-02", "version": "5.6.6", }, Object { - "changeLogUrl": "changelogurl", + "changeLogUrl": "http://changelog.url/", "description": "Version 5.6.5 description", - "downloadUrl": "downloadurl", - "plugins": Object {}, + "downloadDeveloperUrl": "http://download.url/developer", + "downloadUrl": "http://download.url/community", "releaseDate": "2017-03-01", "version": "5.6.5", }, @@ -69,15 +266,188 @@ exports[`should display correctly 1`] = ` > system.download_x.5.6.7 + system.how_to_upgrade + +

+
+`; + +exports[`should display correctly 4`] = ` +
+

+ + Latest Version + +

+

+ + SonarQube + 5.6.7 + , + } + } + /> +

+

+ Version 5.6.7 description +

+ + + +
+`; + +exports[`should display correctly 5`] = ` +
+

+ + Latest Version + +

+

+ + SonarQube + 5.6.7 + , + } + } + /> +

+

+ Version 5.6.7 description +

+ + +
+ + system.download_x.5.6.7 + + system.how_to_upgrade diff --git a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeNotif-test.tsx.snap b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeNotif-test.tsx.snap index 6e9ef3d00dd..88e3fa2d032 100644 --- a/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeNotif-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/system/components/system-upgrade/__tests__/__snapshots__/SystemUpgradeNotif-test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`should display correctly 1`] = ` +exports[`should render correctly 1`] = `
@@ -17,3 +17,72 @@ exports[`should display correctly 1`] = `
`; + +exports[`should render correctly 2`] = ` +
+ + system.new_version_available + + + +
+`; -- 2.39.5