From cee5a9e686a9f6492d59e98a16017186ec78dfea Mon Sep 17 00:00:00 2001 From: Mozafar Haider Date: Wed, 13 Dec 2023 11:45:41 +0000 Subject: [PATCH] fix(DHIS2-13252): disable install button when no compatible versions are available --- .github/workflows/dhis2-preview-pr.yml | 2 +- .github/workflows/dhis2-verify-app.yml | 41 +- .gitignore | 4 +- README.md | 2 + jest-setup.js | 6 + jest.config.js | 20 + package.json | 7 +- .../AppDetails/ManageInstalledVersion.js | 24 +- src/components/AppDetails/Versions.js | 105 +- src/components/AppDetails/Versions.spec.js | 147 ++ src/pages/CoreApps/CoreApps.js | 2 +- src/pages/CustomApps/CustomApps.js | 2 +- src/semver-gt.js | 10 - src/semver-helpers.js | 36 + yarn.lock | 1536 ++++++++++++++++- 15 files changed, 1852 insertions(+), 92 deletions(-) create mode 100644 jest-setup.js create mode 100644 jest.config.js create mode 100644 src/components/AppDetails/Versions.spec.js delete mode 100644 src/semver-gt.js create mode 100644 src/semver-helpers.js diff --git a/.github/workflows/dhis2-preview-pr.yml b/.github/workflows/dhis2-preview-pr.yml index 5db1950c..696dbe0e 100644 --- a/.github/workflows/dhis2-preview-pr.yml +++ b/.github/workflows/dhis2-preview-pr.yml @@ -24,7 +24,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.x - uses: c-hive/gha-yarn-cache@v1 - run: yarn install --frozen-lockfile diff --git a/.github/workflows/dhis2-verify-app.yml b/.github/workflows/dhis2-verify-app.yml index 232188b3..2b74f6a8 100644 --- a/.github/workflows/dhis2-verify-app.yml +++ b/.github/workflows/dhis2-verify-app.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.x - uses: c-hive/gha-yarn-cache@v1 - run: yarn install --frozen-lockfile @@ -42,7 +42,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.x - uses: c-hive/gha-yarn-cache@v1 - run: yarn install --frozen-lockfile @@ -53,22 +53,25 @@ jobs: - name: Lint run: yarn lint - # test: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v2 - # - uses: actions/setup-node@v1 - # with: - # node-version: 12.x - # - # - uses: c-hive/gha-yarn-cache@v1 - # - run: yarn install --frozen-lockfile - # - # - name: Generate translations - # run: yarn d2-app-scripts i18n generate - # - # - name: Test - # run: yarn test + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 14.x + + - uses: c-hive/gha-yarn-cache@v1 + - run: yarn install --frozen-lockfile + + # - name: Generate translations + # run: yarn d2-app-scripts i18n generate + + - name: Test + run: yarn test --coverage + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 release: runs-on: ubuntu-latest @@ -81,7 +84,7 @@ jobs: - uses: actions/setup-node@v1 with: - node-version: 12.x + node-version: 14.x - uses: actions/download-artifact@v2 with: diff --git a/.gitignore b/.gitignore index d4bde9b6..6dea16e3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,6 @@ npm-debug.log node_modules .d2 src/locales -build \ No newline at end of file +build + +coverage \ No newline at end of file diff --git a/README.md b/README.md index c8496cd2..d9e3b8a1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![codecov](https://codecov.io/gh/dhis2/app-management-app/graph/badge.svg?token=Z62Z57XE21)](https://codecov.io/gh/dhis2/maintenance-app-beta) + This project was bootstrapped with [DHIS2 Application Platform](https://github.com/dhis2/app-platform). ## Available Scripts diff --git a/jest-setup.js b/jest-setup.js new file mode 100644 index 00000000..c89d1c98 --- /dev/null +++ b/jest-setup.js @@ -0,0 +1,6 @@ +import { configure } from '@testing-library/react' +import '@testing-library/jest-dom' + +beforeEach(() => { + configure({ testIdAttribute: 'data-test' }) +}) diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 00000000..88e1888b --- /dev/null +++ b/jest.config.js @@ -0,0 +1,20 @@ +const config = { + setupFilesAfterEnv: ['/jest-setup.js'], + collectCoverageFrom: [ + 'src/**/*.{js,jsx,ts,tsx}', + '!/node_modules/', + ], + coverageThreshold: { + global: { + // TODO: The following should be 50 + branches: 0, + + // TODO: The following should be 75 + functions: 0, + lines: 0, + statements: 0, + }, + }, +} + +module.exports = config diff --git a/package.json b/package.json index d3ce8656..c77f9a1f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,12 @@ "homepage": "https://github.com/dhis2/app-management-app#readme", "devDependencies": { "@dhis2/cli-app-scripts": "^8.0.1", - "@dhis2/cli-style": "^10.4.1" + "@dhis2/cli-style": "^10.4.1", + "@testing-library/jest-dom": "^6.1.5", + "@testing-library/react": "^12", + "@types/jest": "^29.5.11", + "jest": "^29.7.0", + "react-dom": "^16" }, "dependencies": { "@dhis2/app-runtime": "^3.2.0", diff --git a/src/components/AppDetails/ManageInstalledVersion.js b/src/components/AppDetails/ManageInstalledVersion.js index de0d877f..2e697573 100644 --- a/src/components/AppDetails/ManageInstalledVersion.js +++ b/src/components/AppDetails/ManageInstalledVersion.js @@ -1,11 +1,12 @@ -import { useAlert } from '@dhis2/app-runtime' +import { useAlert, useConfig } from '@dhis2/app-runtime' import i18n from '@dhis2/d2-i18n' import { PropTypes } from '@dhis2/prop-types' import { Button } from '@dhis2/ui' import React from 'react' +import semver from 'semver' import { useApi } from '../../api.js' import { getLatestVersion } from '../../get-latest-version.js' -import { semverGt } from '../../semver-gt.js' +import { getCompatibleVersions, semverGt } from '../../semver-helpers.js' import styles from './AppDetails.module.css' import { channelToDisplayName } from './channel-to-display-name.js' @@ -22,6 +23,16 @@ export const ManageInstalledVersion = ({ const latestVersion = getLatestVersion(versions) const canInstall = latestVersion && latestVersion.version !== installedApp?.version + + const { serverVersion } = useConfig() + + const dhisVersion = semver.coerce( + `${serverVersion.major}.${serverVersion.minor}` + ) + + const compatibleVersions = getCompatibleVersions(versions, dhisVersion) + const hasCompatibleVersions = compatibleVersions.length > 0 + const canUninstall = installedApp && !isBundled const canUpdate = installedApp && @@ -72,7 +83,14 @@ export const ManageInstalledVersion = ({ return (
- {canInstall && ( + {!hasCompatibleVersions && ( + <> + + {i18n.t('There are no compatible versions available.')} + + + )} + {hasCompatibleVersions && canInstall && ( <>