Browse Source

[FE] Add a space to formatted sizes (#2848)

* Add space to formatted sizes + modification in the test components

* Bytes-format component to be treated as a single word

* fix TopicTests()

* Merge branch 'master' into issues/2676

Co-authored-by: Vlad Senyuta <66071557+VladSenyuta@users.noreply.github.com>
Co-authored-by: VladSenyuta <vlad.senyuta@gmail.com>
Mgrdich 2 years ago
parent
commit
b0782da7d1

+ 3 - 3
kafka-ui-e2e-checks/src/main/java/com/provectus/kafka/ui/pages/topic/TopicDetails.java

@@ -21,7 +21,7 @@ public class TopicDetails {
     protected SelenideElement clearMessagesBtn = $x(("//div[contains(text(), 'Clear messages')]"));
     protected SelenideElement clearMessagesBtn = $x(("//div[contains(text(), 'Clear messages')]"));
     protected SelenideElement overviewTab = $x("//a[contains(text(),'Overview')]");
     protected SelenideElement overviewTab = $x("//a[contains(text(),'Overview')]");
     protected SelenideElement messagesTab = $x("//a[contains(text(),'Messages')]");
     protected SelenideElement messagesTab = $x("//a[contains(text(),'Messages')]");
-    protected SelenideElement editSettingsTab = $x("//li[@role][contains(text(),'Edit settings')]");
+    protected SelenideElement editSettingsMenu = $x("//li[@role][contains(text(),'Edit settings')]");
     protected SelenideElement removeTopicBtn = $x("//ul[@role='menu']//div[contains(text(),'Remove Topic')]");
     protected SelenideElement removeTopicBtn = $x("//ul[@role='menu']//div[contains(text(),'Remove Topic')]");
     protected SelenideElement confirmBtn = $x("//div[@role='dialog']//button[contains(text(),'Confirm')]");
     protected SelenideElement confirmBtn = $x("//div[@role='dialog']//button[contains(text(),'Confirm')]");
     protected SelenideElement produceMessageBtn = $x("//div//button[text()='Produce Message']");
     protected SelenideElement produceMessageBtn = $x("//div//button[text()='Produce Message']");
@@ -39,7 +39,7 @@ public class TopicDetails {
     }
     }
 
 
     @Step
     @Step
-    public TopicDetails openTopicMenu(TopicMenu menu) {
+    public TopicDetails openDetailsTab(TopicMenu menu) {
         $(By.linkText(menu.getValue())).shouldBe(Condition.visible).click();
         $(By.linkText(menu.getValue())).shouldBe(Condition.visible).click();
         return this;
         return this;
     }
     }
@@ -52,7 +52,7 @@ public class TopicDetails {
 
 
     @Step
     @Step
     public TopicDetails clickEditSettingsMenu() {
     public TopicDetails clickEditSettingsMenu() {
-        editSettingsTab.shouldBe(Condition.visible).click();
+        editSettingsMenu.shouldBe(Condition.visible).click();
         return this;
         return this;
     }
     }
 
 

+ 3 - 3
kafka-ui-e2e-checks/src/test/java/com/provectus/kafka/ui/tests/TopicTests.java

@@ -175,7 +175,7 @@ public class TopicTests extends BaseTest {
                 .openTopic(TOPIC_FOR_MESSAGES.getName());
                 .openTopic(TOPIC_FOR_MESSAGES.getName());
         topicDetails
         topicDetails
                 .waitUntilScreenReady()
                 .waitUntilScreenReady()
-                .openTopicMenu(TopicDetails.TopicMenu.MESSAGES)
+                .openDetailsTab(TopicDetails.TopicMenu.MESSAGES)
                 .clickProduceMessageBtn();
                 .clickProduceMessageBtn();
         produceMessagePanel
         produceMessagePanel
                 .waitUntilScreenReady()
                 .waitUntilScreenReady()
@@ -204,7 +204,7 @@ public class TopicTests extends BaseTest {
                 .openTopic(TOPIC_FOR_MESSAGES.getName());
                 .openTopic(TOPIC_FOR_MESSAGES.getName());
         topicDetails
         topicDetails
                 .waitUntilScreenReady()
                 .waitUntilScreenReady()
-                .openTopicMenu(TopicDetails.TopicMenu.OVERVIEW)
+                .openDetailsTab(TopicDetails.TopicMenu.OVERVIEW)
                 .clickProduceMessageBtn();
                 .clickProduceMessageBtn();
         produceMessagePanel
         produceMessagePanel
                 .waitUntilScreenReady()
                 .waitUntilScreenReady()
@@ -238,7 +238,7 @@ public class TopicTests extends BaseTest {
                 .openTopic(topicName);
                 .openTopic(topicName);
         topicDetails
         topicDetails
                 .waitUntilScreenReady()
                 .waitUntilScreenReady()
-                .openTopicMenu(TopicDetails.TopicMenu.CONSUMERS)
+                .openDetailsTab(TopicDetails.TopicMenu.CONSUMERS)
                 .openConsumerGroup(consumerGroupId);
                 .openConsumerGroup(consumerGroupId);
         consumersDetails
         consumersDetails
                 .waitUntilScreenReady();
                 .waitUntilScreenReady();

+ 1 - 1
kafka-ui-react-app/src/components/Brokers/Broker/__test__/Broker.spec.tsx

@@ -66,7 +66,7 @@ describe('Broker Component', () => {
     expect(
     expect(
       screen.getByText(brokerDiskUsage?.segmentCount || '')
       screen.getByText(brokerDiskUsage?.segmentCount || '')
     ).toBeInTheDocument();
     ).toBeInTheDocument();
-    expect(screen.getByText('12MB')).toBeInTheDocument();
+    expect(screen.getByText('12 MB')).toBeInTheDocument();
 
 
     expect(screen.getByText('Segment Count')).toBeInTheDocument();
     expect(screen.getByText('Segment Count')).toBeInTheDocument();
     expect(
     expect(

+ 4 - 4
kafka-ui-react-app/src/components/Topics/List/__tests__/TopicTable.spec.tsx

@@ -92,13 +92,13 @@ describe('TopicTable Components', () => {
         screen.getByRole('link', { name: '__internal.topic' })
         screen.getByRole('link', { name: '__internal.topic' })
       ).toBeInTheDocument();
       ).toBeInTheDocument();
       expect(
       expect(
-        screen.getByRole('row', { name: '__internal.topic 1 0 1 0 0Bytes' })
+        screen.getByRole('row', { name: '__internal.topic 1 0 1 0 0 Bytes' })
       ).toBeInTheDocument();
       ).toBeInTheDocument();
       expect(
       expect(
         screen.getByRole('link', { name: 'external.topic' })
         screen.getByRole('link', { name: 'external.topic' })
       ).toBeInTheDocument();
       ).toBeInTheDocument();
       expect(
       expect(
-        screen.getByRole('row', { name: 'external.topic 1 0 1 0 1KB' })
+        screen.getByRole('row', { name: 'external.topic 1 0 1 0 1 KB' })
       ).toBeInTheDocument();
       ).toBeInTheDocument();
 
 
       expect(screen.getAllByRole('checkbox').length).toEqual(3);
       expect(screen.getAllByRole('checkbox').length).toEqual(3);
@@ -211,7 +211,7 @@ describe('TopicTable Components', () => {
         ).toEqual(2);
         ).toEqual(2);
         // Internal topic action buttons are disabled
         // Internal topic action buttons are disabled
         const internalTopicRow = screen.getByRole('row', {
         const internalTopicRow = screen.getByRole('row', {
-          name: '__internal.topic 1 0 1 0 0Bytes',
+          name: '__internal.topic 1 0 1 0 0 Bytes',
         });
         });
         expect(internalTopicRow).toBeInTheDocument();
         expect(internalTopicRow).toBeInTheDocument();
         expect(
         expect(
@@ -221,7 +221,7 @@ describe('TopicTable Components', () => {
         ).toBeDisabled();
         ).toBeDisabled();
         // External topic action buttons are enabled
         // External topic action buttons are enabled
         const externalTopicRow = screen.getByRole('row', {
         const externalTopicRow = screen.getByRole('row', {
-          name: 'external.topic 1 0 1 0 1KB',
+          name: 'external.topic 1 0 1 0 1 KB',
         });
         });
         expect(externalTopicRow).toBeInTheDocument();
         expect(externalTopicRow).toBeInTheDocument();
         const extBtn = within(externalTopicRow).getByRole('button', {
         const extBtn = within(externalTopicRow).getByRole('button', {

+ 5 - 0
kafka-ui-react-app/src/components/common/BytesFormatted/BytesFormatted.styled.ts

@@ -0,0 +1,5 @@
+import styled from 'styled-components';
+
+export const NoWrap = styled.span`
+  white-space: nowrap;
+`;

+ 8 - 6
kafka-ui-react-app/src/components/common/BytesFormatted/BytesFormatted.tsx

@@ -1,5 +1,7 @@
 import React from 'react';
 import React from 'react';
 
 
+import { NoWrap } from './BytesFormatted.styled';
+
 interface Props {
 interface Props {
   value: string | number | undefined;
   value: string | number | undefined;
   precision?: number;
   precision?: number;
@@ -8,22 +10,22 @@ interface Props {
 export const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
 export const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
 
 
 const BytesFormatted: React.FC<Props> = ({ value, precision = 0 }) => {
 const BytesFormatted: React.FC<Props> = ({ value, precision = 0 }) => {
-  const formatedValue = React.useMemo((): string => {
+  const formattedValue = React.useMemo((): string => {
     try {
     try {
       const bytes = typeof value === 'string' ? parseInt(value, 10) : value;
       const bytes = typeof value === 'string' ? parseInt(value, 10) : value;
       if (Number.isNaN(bytes) || (bytes && bytes < 0)) return `-Bytes`;
       if (Number.isNaN(bytes) || (bytes && bytes < 0)) return `-Bytes`;
-      if (!bytes || bytes < 1024) return `${Math.ceil(bytes || 0)}${sizes[0]}`;
+      if (!bytes || bytes < 1024) return `${Math.ceil(bytes || 0)} ${sizes[0]}`;
       const pow = Math.floor(Math.log2(bytes) / 10);
       const pow = Math.floor(Math.log2(bytes) / 10);
       const multiplier = 10 ** (precision < 0 ? 0 : precision);
       const multiplier = 10 ** (precision < 0 ? 0 : precision);
-      return (
-        Math.round((bytes * multiplier) / 1024 ** pow) / multiplier + sizes[pow]
-      );
+      return `${Math.round((bytes * multiplier) / 1024 ** pow) / multiplier} ${
+        sizes[pow]
+      }`;
     } catch (e) {
     } catch (e) {
       return `-Bytes`;
       return `-Bytes`;
     }
     }
   }, [precision, value]);
   }, [precision, value]);
 
 
-  return <span>{formatedValue}</span>;
+  return <NoWrap>{formattedValue}</NoWrap>;
 };
 };
 
 
 export default BytesFormatted;
 export default BytesFormatted;

+ 6 - 6
kafka-ui-react-app/src/components/common/BytesFormatted/__tests__/BytesFormatted.spec.tsx

@@ -7,29 +7,29 @@ import { render, screen } from '@testing-library/react';
 describe('BytesFormatted', () => {
 describe('BytesFormatted', () => {
   it('renders Bytes correctly', () => {
   it('renders Bytes correctly', () => {
     render(<BytesFormatted value={666} />);
     render(<BytesFormatted value={666} />);
-    expect(screen.getByText('666Bytes')).toBeInTheDocument();
+    expect(screen.getByText('666 Bytes')).toBeInTheDocument();
   });
   });
 
 
   it('renders correct units', () => {
   it('renders correct units', () => {
     let value = 1;
     let value = 1;
     sizes.forEach((unit) => {
     sizes.forEach((unit) => {
       render(<BytesFormatted value={value} />);
       render(<BytesFormatted value={value} />);
-      expect(screen.getByText(`1${unit}`)).toBeInTheDocument();
+      expect(screen.getByText(`1 ${unit}`)).toBeInTheDocument();
       value *= 1024;
       value *= 1024;
     });
     });
   });
   });
 
 
   it('renders correct precision', () => {
   it('renders correct precision', () => {
     render(<BytesFormatted value={2000} precision={100} />);
     render(<BytesFormatted value={2000} precision={100} />);
-    expect(screen.getByText(`1.953125${sizes[1]}`)).toBeInTheDocument();
+    expect(screen.getByText(`1.953125 ${sizes[1]}`)).toBeInTheDocument();
 
 
     render(<BytesFormatted value={10000} precision={5} />);
     render(<BytesFormatted value={10000} precision={5} />);
-    expect(screen.getByText(`9.76563${sizes[1]}`)).toBeInTheDocument();
+    expect(screen.getByText(`9.76563 ${sizes[1]}`)).toBeInTheDocument();
   });
   });
 
 
   it('correctly handles invalid props', () => {
   it('correctly handles invalid props', () => {
     render(<BytesFormatted value={10000} precision={-1} />);
     render(<BytesFormatted value={10000} precision={-1} />);
-    expect(screen.getByText(`10${sizes[1]}`)).toBeInTheDocument();
+    expect(screen.getByText(`10 ${sizes[1]}`)).toBeInTheDocument();
 
 
     render(<BytesFormatted value="some string" />);
     render(<BytesFormatted value="some string" />);
     expect(screen.getAllByText(`-${sizes[0]}`).length).toBeTruthy();
     expect(screen.getAllByText(`-${sizes[0]}`).length).toBeTruthy();
@@ -38,6 +38,6 @@ describe('BytesFormatted', () => {
     expect(screen.getAllByText(`-${sizes[0]}`).length).toBeTruthy();
     expect(screen.getAllByText(`-${sizes[0]}`).length).toBeTruthy();
 
 
     render(<BytesFormatted value={undefined} />);
     render(<BytesFormatted value={undefined} />);
-    expect(screen.getByText(`0${sizes[0]}`)).toBeInTheDocument();
+    expect(screen.getByText(`0 ${sizes[0]}`)).toBeInTheDocument();
   });
   });
 });
 });

+ 4 - 4
kafka-ui-react-app/src/components/common/NewTable/__test__/Table.spec.tsx

@@ -125,10 +125,10 @@ describe('Table', () => {
 
 
   it('renders SizeCell', () => {
   it('renders SizeCell', () => {
     renderComponent();
     renderComponent();
-    expect(screen.getByText('1KB')).toBeInTheDocument();
-    expect(screen.getByText('3Bytes')).toBeInTheDocument();
-    expect(screen.getByText('49KB')).toBeInTheDocument();
-    expect(screen.getByText('1MB')).toBeInTheDocument();
+    expect(screen.getByText('1 KB')).toBeInTheDocument();
+    expect(screen.getByText('3 Bytes')).toBeInTheDocument();
+    expect(screen.getByText('49 KB')).toBeInTheDocument();
+    expect(screen.getByText('1 MB')).toBeInTheDocument();
   });
   });
 
 
   it('renders TimestampCell', () => {
   it('renders TimestampCell', () => {