Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Leshe4ka committed May 17, 2024
1 parent 0b6286d commit dd93106
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ClusterColorKey } from 'theme/theme';

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

interface MenuColorPickerProps {
export interface MenuColorPickerProps {
setColorKey: (key: ClusterColorKey) => void;
}

Expand All @@ -32,6 +32,7 @@ const MenuColorPicker = ({ setColorKey }: MenuColorPickerProps) => {
<S.Container>
{COLOR_KEYS.map((key) => (
<S.ColorCircle
data-testid={`color-circle-${key}`}
onClick={handleCircleCLick(key)}
$colorKey={key}
key={key}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { fireEvent, screen } from '@testing-library/react';
import MenuColorPicker, {
MenuColorPickerProps,
} from 'components/Nav/Menu/MenuColorPicker/MenuColorPicker';
import React from 'react';
import { render } from 'lib/testHelpers';
import { ClusterColorKey } from 'theme/theme';

describe('MenuColorPicker component', () => {
const setupWrapper = (props?: Partial<MenuColorPickerProps>) => (
<MenuColorPicker setColorKey={jest.fn()} {...props} />
);

it('renders all color circles', () => {
render(setupWrapper());

const colorKeys: ClusterColorKey[] = [
'transparent',
'gray',
'red',
'orange',
'lettuce',
'green',
'turquoise',
'blue',
'violet',
'pink',
];

colorKeys.forEach((key) => {
expect(screen.getByTestId(`color-circle-${key}`)).toBeInTheDocument();
});
});

it('calls setColorKey with the correct color key when a color circle is clicked', () => {
const setColorKeyMock = jest.fn();
render(setupWrapper({ setColorKey: setColorKeyMock }));

const colorCircle = screen.getByTestId('color-circle-red');
fireEvent.click(colorCircle);

expect(setColorKeyMock).toHaveBeenCalledWith('red');
});

it('renders the Dropdown component', () => {
render(setupWrapper());
expect(screen.getByRole('button')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const toggleClusterMenuMock = jest.fn();
describe('MenuTab component', () => {
const setupWrapper = (props?: Partial<MenuTabProps>) => (
<MenuTab
setColorKey={() => {}}
status={ServerStatus.ONLINE}
isOpen
title={testClusterName}
Expand Down

0 comments on commit dd93106

Please sign in to comment.