Merge branch 'master' into issues/2752

This commit is contained in:
Roman Zabaluev 2023-04-27 10:00:29 +08:00 committed by GitHub
commit 97f75a1bf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 73 deletions

View file

@ -142,6 +142,8 @@ const Message: React.FC<Props> = ({
timestampType={timestampType} timestampType={timestampType}
keySize={keySize} keySize={keySize}
contentSize={valueSize} contentSize={valueSize}
keySerde={keySerde}
valueSerde={valueSerde}
/> />
)} )}
</> </>

View file

@ -3,7 +3,6 @@ import EditorViewer from 'components/common/EditorViewer/EditorViewer';
import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted'; import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
import { SchemaType, TopicMessageTimestampTypeEnum } from 'generated-sources'; import { SchemaType, TopicMessageTimestampTypeEnum } from 'generated-sources';
import { formatTimestamp } from 'lib/dateTimeHelpers'; import { formatTimestamp } from 'lib/dateTimeHelpers';
import { useSearchParams } from 'react-router-dom';
import * as S from './MessageContent.styled'; import * as S from './MessageContent.styled';
@ -17,6 +16,8 @@ export interface MessageContentProps {
timestampType?: TopicMessageTimestampTypeEnum; timestampType?: TopicMessageTimestampTypeEnum;
keySize?: number; keySize?: number;
contentSize?: number; contentSize?: number;
keySerde?: string;
valueSerde?: string;
} }
const MessageContent: React.FC<MessageContentProps> = ({ const MessageContent: React.FC<MessageContentProps> = ({
@ -27,12 +28,10 @@ const MessageContent: React.FC<MessageContentProps> = ({
timestampType, timestampType,
keySize, keySize,
contentSize, contentSize,
keySerde,
valueSerde,
}) => { }) => {
const [activeTab, setActiveTab] = React.useState<Tab>('content'); const [activeTab, setActiveTab] = React.useState<Tab>('content');
const [searchParams] = useSearchParams();
const keyFormat = searchParams.get('keySerde') || '';
const valueFormat = searchParams.get('valueSerde') || '';
const activeTabContent = () => { const activeTabContent = () => {
switch (activeTab) { switch (activeTab) {
case 'content': case 'content':
@ -110,7 +109,7 @@ const MessageContent: React.FC<MessageContentProps> = ({
<S.Metadata> <S.Metadata>
<S.MetadataLabel>Key Serde</S.MetadataLabel> <S.MetadataLabel>Key Serde</S.MetadataLabel>
<span> <span>
<S.MetadataValue>{keyFormat}</S.MetadataValue> <S.MetadataValue>{keySerde}</S.MetadataValue>
<S.MetadataMeta> <S.MetadataMeta>
Size: <BytesFormatted value={keySize} /> Size: <BytesFormatted value={keySize} />
</S.MetadataMeta> </S.MetadataMeta>
@ -120,7 +119,7 @@ const MessageContent: React.FC<MessageContentProps> = ({
<S.Metadata> <S.Metadata>
<S.MetadataLabel>Value Serde</S.MetadataLabel> <S.MetadataLabel>Value Serde</S.MetadataLabel>
<span> <span>
<S.MetadataValue>{valueFormat}</S.MetadataValue> <S.MetadataValue>{valueSerde}</S.MetadataValue>
<S.MetadataMeta> <S.MetadataMeta>
Size: <BytesFormatted value={contentSize} /> Size: <BytesFormatted value={contentSize} />
</S.MetadataMeta> </S.MetadataMeta>

View file

@ -20,6 +20,8 @@ const setupWrapper = (props?: Partial<MessageContentProps>) => {
headers={{ header: 'test' }} headers={{ header: 'test' }}
timestamp={new Date(0)} timestamp={new Date(0)}
timestampType={TopicMessageTimestampTypeEnum.CREATE_TIME} timestampType={TopicMessageTimestampTypeEnum.CREATE_TIME}
keySerde="SchemaRegistry"
valueSerde="Avro"
{...props} {...props}
/> />
</tbody> </tbody>
@ -27,42 +29,20 @@ const setupWrapper = (props?: Partial<MessageContentProps>) => {
); );
}; };
const proto =
'syntax = "proto3";\npackage com.provectus;\n\nmessage TestProtoRecord {\n string f1 = 1;\n int32 f2 = 2;\n}\n';
global.TextEncoder = TextEncoder; global.TextEncoder = TextEncoder;
const searchParamsContentAVRO = new URLSearchParams({
keySerde: 'SchemaRegistry',
valueSerde: 'AVRO',
limit: '100',
});
const searchParamsContentJSON = new URLSearchParams({
keySerde: 'SchemaRegistry',
valueSerde: 'JSON',
limit: '100',
});
const searchParamsContentPROTOBUF = new URLSearchParams({
keySerde: 'SchemaRegistry',
valueSerde: 'PROTOBUF',
limit: '100',
});
describe('MessageContent screen', () => { describe('MessageContent screen', () => {
beforeEach(() => { beforeEach(() => {
render(setupWrapper(), { render(setupWrapper());
initialEntries: [`/messages?${searchParamsContentAVRO}`],
});
}); });
describe('renders', () => { describe('Checking keySerde and valueSerde', () => {
it('key format in document', () => { it('keySerde in document', () => {
expect(screen.getByText('SchemaRegistry')).toBeInTheDocument(); expect(screen.getByText('SchemaRegistry')).toBeInTheDocument();
}); });
it('content format in document', () => { it('valueSerde in document', () => {
expect(screen.getByText('AVRO')).toBeInTheDocument(); expect(screen.getByText('Avro')).toBeInTheDocument();
}); });
}); });
@ -98,42 +78,3 @@ describe('MessageContent screen', () => {
}); });
}); });
}); });
describe('checking content type depend on message type', () => {
it('renders component with message having JSON type', () => {
render(
setupWrapper({
messageContent: '{"data": "test"}',
}),
{ initialEntries: [`/messages?${searchParamsContentJSON}`] }
);
expect(screen.getByText('JSON')).toBeInTheDocument();
});
it('renders component with message having AVRO type', () => {
render(
setupWrapper({
messageContent: '{"data": "test"}',
}),
{ initialEntries: [`/messages?${searchParamsContentAVRO}`] }
);
expect(screen.getByText('AVRO')).toBeInTheDocument();
});
it('renders component with message having PROTOBUF type', () => {
render(
setupWrapper({
messageContent: proto,
}),
{ initialEntries: [`/messages?${searchParamsContentPROTOBUF}`] }
);
expect(screen.getByText('PROTOBUF')).toBeInTheDocument();
});
it('renders component with message having no type which is equal to having PROTOBUF type', () => {
render(
setupWrapper({
messageContent: '',
}),
{ initialEntries: [`/messages?${searchParamsContentPROTOBUF}`] }
);
expect(screen.getByText('PROTOBUF')).toBeInTheDocument();
});
});