From da3932e3422e45bdb0dc27cf538b79c8bf872602 Mon Sep 17 00:00:00 2001
From: David Bejanyan <58771979+David-DB88@users.noreply.github.com>
Date: Thu, 27 Apr 2023 06:01:38 +0400
Subject: [PATCH] FE: Impl a possibility to opt out of version check (#3672)
---
.../src/components/Version/Version.tsx | 30 ++----
.../Version/__tests__/Version.spec.tsx | 97 +++++--------------
.../components/common/Icons/WarningIcon.tsx | 1 +
.../src/lib/fixtures/actuatorInfo.ts | 12 ---
.../src/lib/fixtures/latestVersion.ts | 17 +++-
.../hooks/api/__tests__/actuatorInfo.spec.ts | 17 ----
.../hooks/api/__tests__/latestVersion.spec.ts | 12 +--
.../src/lib/hooks/api/actuatorInfo.ts | 19 ----
.../src/lib/hooks/api/latestVersion.ts | 18 ++--
9 files changed, 62 insertions(+), 161 deletions(-)
delete mode 100644 kafka-ui-react-app/src/lib/fixtures/actuatorInfo.ts
delete mode 100644 kafka-ui-react-app/src/lib/hooks/api/__tests__/actuatorInfo.spec.ts
delete mode 100644 kafka-ui-react-app/src/lib/hooks/api/actuatorInfo.ts
diff --git a/kafka-ui-react-app/src/components/Version/Version.tsx b/kafka-ui-react-app/src/components/Version/Version.tsx
index 7a820b116a..6788605d92 100644
--- a/kafka-ui-react-app/src/components/Version/Version.tsx
+++ b/kafka-ui-react-app/src/components/Version/Version.tsx
@@ -1,52 +1,38 @@
import React from 'react';
import WarningIcon from 'components/common/Icons/WarningIcon';
import { gitCommitPath } from 'lib/paths';
-import { useActuatorInfo } from 'lib/hooks/api/actuatorInfo';
-import { BUILD_VERSION_PATTERN } from 'lib/constants';
import { useLatestVersion } from 'lib/hooks/api/latestVersion';
import { formatTimestamp } from 'lib/dateTimeHelpers';
import * as S from './Version.styled';
-import compareVersions from './compareVersions';
const Version: React.FC = () => {
- const { data: actuatorInfo = {} } = useActuatorInfo();
const { data: latestVersionInfo = {} } = useLatestVersion();
-
- const tag = actuatorInfo?.build?.version;
- const commit = actuatorInfo?.git?.commit.id;
- const { tag_name: latestTag } = latestVersionInfo;
-
- const outdated = compareVersions(tag, latestTag);
-
- const currentVersion = tag?.match(BUILD_VERSION_PATTERN)
- ? tag
- : formatTimestamp(actuatorInfo?.build?.time);
-
- if (!tag) return null;
+ const { buildTime, commitId, isLatestRelease } = latestVersionInfo.build;
+ const { versionTag } = latestVersionInfo?.latestRelease || '';
return (
- {!!outdated && (
+ {!isLatestRelease && (
)}
- {commit && (
+ {commitId && (
- {commit}
+ {commitId}
)}
- {currentVersion}
+ {formatTimestamp(buildTime)}
);
};
diff --git a/kafka-ui-react-app/src/components/Version/__tests__/Version.spec.tsx b/kafka-ui-react-app/src/components/Version/__tests__/Version.spec.tsx
index d407966058..2700dac894 100644
--- a/kafka-ui-react-app/src/components/Version/__tests__/Version.spec.tsx
+++ b/kafka-ui-react-app/src/components/Version/__tests__/Version.spec.tsx
@@ -2,87 +2,40 @@ import React from 'react';
import { screen } from '@testing-library/dom';
import Version from 'components/Version/Version';
import { render } from 'lib/testHelpers';
-import { formatTimestamp } from 'lib/dateTimeHelpers';
-import { useActuatorInfo } from 'lib/hooks/api/actuatorInfo';
import { useLatestVersion } from 'lib/hooks/api/latestVersion';
-import { actuatorInfoPayload } from 'lib/fixtures/actuatorInfo';
-import { latestVersionPayload } from 'lib/fixtures/latestVersion';
+import {
+ deprecatedVersionPayload,
+ latestVersionPayload,
+} from 'lib/fixtures/latestVersion';
-jest.mock('lib/hooks/api/actuatorInfo', () => ({
- useActuatorInfo: jest.fn(),
-}));
jest.mock('lib/hooks/api/latestVersion', () => ({
useLatestVersion: jest.fn(),
}));
-
describe('Version Component', () => {
- const versionTag = 'v0.5.0';
- const snapshotTag = 'test-SNAPSHOT';
- const commitTag = 'befd3b328e2c9c7df57b0c5746561b2f7fee8813';
+ const commitId = '96a577a';
- const actuatorVersionPayload = actuatorInfoPayload(versionTag);
- const formattedTimestamp = formatTimestamp(actuatorVersionPayload.build.time);
+ describe('render latest version', () => {
+ beforeEach(() => {
+ (useLatestVersion as jest.Mock).mockImplementation(() => ({
+ data: latestVersionPayload,
+ }));
+ });
+ it('renders latest release version as current version', async () => {
+ render();
+ expect(screen.getByText(commitId)).toBeInTheDocument();
+ });
- beforeEach(() => {
- (useActuatorInfo as jest.Mock).mockImplementation(() => ({
- data: actuatorVersionPayload,
- }));
+ it('should not show warning icon if it is last release', async () => {
+ render();
+ expect(screen.queryByRole('img')).not.toBeInTheDocument();
+ });
+ });
+
+ it('show warning icon if it is not last release', async () => {
(useLatestVersion as jest.Mock).mockImplementation(() => ({
- data: latestVersionPayload,
+ data: deprecatedVersionPayload,
}));
- });
-
- describe('tag does not exist', () => {
- it('does not render component', async () => {
- (useActuatorInfo as jest.Mock).mockImplementation(() => ({
- data: null,
- }));
- const { container } = render();
- expect(container.firstChild).toBeEmptyDOMElement();
- });
- });
-
- describe('renders current version', () => {
- it('renders release build version as current version', async () => {
- render();
- expect(screen.getByText(versionTag)).toBeInTheDocument();
- });
- it('renders formatted timestamp as current version when version is commit', async () => {
- (useActuatorInfo as jest.Mock).mockImplementation(() => ({
- data: actuatorInfoPayload(commitTag),
- }));
- render();
- expect(screen.getByText(formattedTimestamp)).toBeInTheDocument();
- });
- it('renders formatted timestamp as current version when version contains -SNAPSHOT', async () => {
- (useActuatorInfo as jest.Mock).mockImplementation(() => ({
- data: actuatorInfoPayload(snapshotTag),
- }));
- render();
- expect(screen.getByText(formattedTimestamp)).toBeInTheDocument();
- });
- });
-
- describe('outdated build version', () => {
- it('renders warning message', async () => {
- (useActuatorInfo as jest.Mock).mockImplementation(() => ({
- data: actuatorInfoPayload('v0.3.0'),
- }));
- render();
- expect(
- screen.getByTitle(
- `Your app version is outdated. Current latest version is ${latestVersionPayload.tag_name}`
- )
- ).toBeInTheDocument();
- });
- });
-
- describe('current commit id with link', () => {
- it('renders', async () => {
- render();
- expect(
- screen.getByText(actuatorVersionPayload.git.commit.id)
- ).toBeInTheDocument();
- });
+ render();
+ expect(screen.getByRole('img')).toBeInTheDocument();
});
});
diff --git a/kafka-ui-react-app/src/components/common/Icons/WarningIcon.tsx b/kafka-ui-react-app/src/components/common/Icons/WarningIcon.tsx
index ab2f8dee75..1bffe0db53 100644
--- a/kafka-ui-react-app/src/components/common/Icons/WarningIcon.tsx
+++ b/kafka-ui-react-app/src/components/common/Icons/WarningIcon.tsx
@@ -13,6 +13,7 @@ const WarningIcon: React.FC = () => {
return (