Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated topic URP status color. #1336

Merged
merged 6 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ exports[`Overview view matches snapshot 1`] = `

<svg
className="c6"
role="svg"
viewBox="0 0 4 4"
xmlns="http://www.w3.org/2000/svg"
>
Expand All @@ -219,6 +220,7 @@ exports[`Overview view matches snapshot 1`] = `
cx={2}
cy={2}
r={2}
role="circle"
/>
</svg>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import VerticalElipsisIcon from 'components/common/Icons/VerticalElipsisIcon';
import * as Metrics from 'components/common/Metrics';
import TagStyled from 'components/common/Tag/Tag.styled';

interface Props extends Topic, TopicDetails {
export interface Props extends Topic, TopicDetails {
clusterName: ClusterName;
topicName: TopicName;
clearTopicMessages(
Expand Down Expand Up @@ -52,6 +52,7 @@ const Overview: React.FC<Props> = ({
label="URP"
title="Under replicated partitions"
isAlert
alertType={underReplicatedPartitions === 0 ? 'error' : 'success'}
NelyDavtyan marked this conversation as resolved.
Show resolved Hide resolved
>
<Metrics.RedText>{underReplicatedPartitions}</Metrics.RedText>
</Metrics.Indicator>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import { shallow } from 'enzyme';
import { screen } from '@testing-library/react';
import { render } from 'lib/testHelpers';
import Overview from 'components/Topics/Topic/Details/Overview/Overview';
import theme from 'theme/theme';

describe('Overview', () => {
const mockInternal = false;
const mockClusterName = 'local';
const mockTopicName = 'topic';
const mockClearTopicMessages = jest.fn();
Expand All @@ -23,13 +25,32 @@ describe('Overview', () => {
},
];

const renderComponent = ({
underReplicatedPartitions = 1,
inSyncReplicas = 1,
replicas = 1,
} = {}) =>
render(
<Overview
name={mockTopicName}
partitions={mockPartitions}
internal={undefined}
clusterName={mockClusterName}
topicName={mockTopicName}
clearTopicMessages={mockClearTopicMessages}
underReplicatedPartitions={underReplicatedPartitions}
inSyncReplicas={inSyncReplicas}
replicas={replicas}
/>
);

describe('when it has internal flag', () => {
it('does not render the Action button a Topic', () => {
const component = shallow(
Hurenka marked this conversation as resolved.
Show resolved Hide resolved
<Overview
name={mockTopicName}
partitions={mockPartitions}
internal={mockInternal}
internal={false}
clusterName={mockClusterName}
topicName={mockTopicName}
clearTopicMessages={mockClearTopicMessages}
Expand All @@ -44,7 +65,7 @@ describe('Overview', () => {
<Overview
name={mockTopicName}
partitions={[]}
internal={mockInternal}
internal
clusterName={mockClusterName}
topicName={mockTopicName}
clearTopicMessages={mockClearTopicMessages}
Expand All @@ -54,4 +75,27 @@ describe('Overview', () => {
expect(componentEmpty.find('td').text()).toEqual('No Partitions found');
});
});

describe('should render circular alert', () => {
it('should be in document', () => {
renderComponent();
const circles = screen.getAllByRole('circle');
expect(circles.length).toEqual(2);
});

it('should be the appropriate color', () => {
renderComponent({
underReplicatedPartitions: 0,
inSyncReplicas: 1,
replicas: 2,
});
const circles = screen.getAllByRole('circle');
expect(circles[0]).toHaveStyle(
`fill: ${theme.circularAlert.color.error}`
);
expect(circles[1]).toHaveStyle(
`fill: ${theme.circularAlert.color.error}`
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AlertType } from 'redux/interfaces';

import * as S from './Metrics.styled';

interface Props {
export interface Props {
fetching?: boolean;
isAlert?: boolean;
label: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const RedText = styled.span`
`;

export const CircularAlertWrapper = styled.svg.attrs({
role: 'svg',
viewBox: '0 0 4 4',
xmlns: 'http://www.w3.org/2000/svg',
})`
Expand All @@ -87,7 +88,12 @@ export const CircularAlertWrapper = styled.svg.attrs({
height: 4px;
`;

export const CircularAlert = styled.circle.attrs({ cx: 2, cy: 2, r: 2 })<{
export const CircularAlert = styled.circle.attrs({
role: 'circle',
cx: 2,
cy: 2,
r: 2,
})<{
$type: AlertType;
}>(
({ theme, $type }) => css`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,61 @@ import React from 'react';
import { Indicator } from 'components/common/Metrics';
import { screen } from '@testing-library/react';
import { render } from 'lib/testHelpers';
import { Props } from 'components/common/Metrics/Indicator';
import theme from 'theme/theme';

const title = 'Test Title';
const label = 'Test Label';
const child = 'Child';

describe('Indicator', () => {
it('matches the snapshot', () => {
const setupComponent = (props: Partial<Props> = {}) =>
render(
<Indicator title={title} label="Test Label">
<Indicator title={props.title} label={props.label} {...props}>
{child}
</Indicator>
);

it('renders indicator', () => {
setupComponent({ title, label });
expect(screen.getByTitle(title)).toBeInTheDocument();
expect(screen.getByText(label)).toBeInTheDocument();
expect(screen.getByText(child)).toBeInTheDocument();
});

describe('should render circular alert', () => {
it('should be in document', () => {
setupComponent({ title, label, isAlert: true });
expect(screen.getByRole('svg')).toBeInTheDocument();
expect(screen.getByRole('circle')).toBeInTheDocument();
});

it('success alert', () => {
setupComponent({ title, label, isAlert: true, alertType: 'success' });
expect(screen.getByRole('circle')).toHaveStyle(
`fill: ${theme.circularAlert.color.success}`
);
});

it('error alert', () => {
setupComponent({ title, label, isAlert: true, alertType: 'error' });
expect(screen.getByRole('circle')).toHaveStyle(
`fill: ${theme.circularAlert.color.error}`
);
});

it('warning alert', () => {
setupComponent({ title, label, isAlert: true, alertType: 'warning' });
expect(screen.getByRole('circle')).toHaveStyle(
`fill: ${theme.circularAlert.color.warning}`
);
});

it('info alert', () => {
setupComponent({ title, label, isAlert: true, alertType: 'info' });
expect(screen.getByRole('circle')).toHaveStyle(
`fill: ${theme.circularAlert.color.info}`
);
});
});
});