Skip to content

Commit

Permalink
fix: apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sdrejkarz committed May 9, 2024
1 parent 58e9f3c commit 1034410
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ import { render } from '../../../../tests/utils/rendering';
import { DangerZoneItem, DangerZoneItemProps } from '../dangerZoneItem.component';

const subtitle = 'subtitle';
const buttonText = 'buttonText';

const defaultProps: DangerZoneItemProps = {
title: 'title',
onClick: jest.fn(),
buttonText: 'buttonText',
buttonText,
subtitle,
};

describe('DangerZoneItem: Component', () => {
const Component = (args: Partial<Omit<DangerZoneItemProps, 'children'>>) => (
<DangerZoneItem {...defaultProps} {...args} />
);
const Component = (args: Partial<DangerZoneItemProps>) => <DangerZoneItem {...defaultProps} {...args} />;

it('should render all items', async () => {
render(<Component />);

expect(await screen.findByText(defaultProps.title)).toBeInTheDocument();
expect(screen.getByText(defaultProps.buttonText)).toBeInTheDocument();
expect(screen.getByText(buttonText)).toBeInTheDocument();
expect(screen.getByText(subtitle)).toBeInTheDocument();
});

Expand All @@ -35,13 +34,13 @@ describe('DangerZoneItem: Component', () => {
it('should render custom Button', async () => {
const text = 'text';
render(
<DangerZoneItem title={defaultProps.title}>
<Component title={defaultProps.title}>
<div>{text}</div>
</DangerZoneItem>
</Component>
);

expect(await screen.findByText(text)).toBeInTheDocument();
expect(screen.queryByText(defaultProps.buttonText)).not.toBeInTheDocument();
expect(screen.queryByText(buttonText)).not.toBeInTheDocument();
});

it('should call onClick', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@ import { Button } from '@sb/webapp-core/components/buttons';
import { Paragraph } from '@sb/webapp-core/components/typography';
import { ReactElement } from 'react';

type ButtonProps = {
onClick: () => void;
buttonText: string;
children?: never;
};

type CustomButton = {
children: ReactElement;
onClick?: never;
buttonText?: never;
};

type RestProps = ButtonProps | CustomButton;

export type DangerZoneItemProps = {
title: string;
subtitle?: string;
disabled?: boolean;
} & RestProps;
onClick?: () => void;
buttonText?: string;
children?: ReactElement;
};

export const DangerZoneItem = ({
title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import alertCircle from '@iconify-icons/ion/alert-circle-outline';
import dangerIcon from '@iconify-icons/ion/alert-circle-outline';
import { TenantUserRole } from '@sb/webapp-api-client';
import { Icon } from '@sb/webapp-core/components/icons';
import { H3 } from '@sb/webapp-core/components/typography';
Expand All @@ -20,7 +20,7 @@ export const TenantDangerZone = () => {
return (
<div className="space-y-6 pt-4 mt-2">
<div className="flex gap-2 items-center">
<Icon className="text-red-500" icon={alertCircle} />
<Icon className="text-red-500" icon={dangerIcon} />
<H3 className="text-lg font-medium text-red-500">
<FormattedMessage defaultMessage="Danger Zone" id="Tenant General Settings / Danger Zone / Header" />
</H3>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useMutation } from '@apollo/client';
import { TenantType } from '@sb/webapp-api-client/constants';
import { useCommonQuery } from '@sb/webapp-api-client/providers';
import { PageHeadline } from '@sb/webapp-core/components/pageHeadline';
import { trackEvent } from '@sb/webapp-core/services/analytics';
Expand Down Expand Up @@ -27,7 +28,7 @@ export const TenantGeneralSettings = () => {
defaultMessage: 'Unable to change the tenant data.',
});

const isOrganizationType = currentTenant?.type === 'organization';
const isOrganizationType = currentTenant?.type === TenantType.ORGANIZATION;

const [commitUpdateMutation, { loading, error }] = useMutation(updateTenantMutation, {
onCompleted: (data) => {
Expand Down

0 comments on commit 1034410

Please sign in to comment.