mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
c92d7380df
* Converted file extension from .js to .tsx * Updated README docs to match the enums. Resolved type errors * Updated AvatarBaseSizes enum values to string literals * Added TEXT_TRANSFORM.UPPERCASE as default value of textTransform in base file * lint fix * Solved liniting errors in avatar-base * Made enum more consistent, added desc for AvatarBaseProps * Updated snapshots of AvatarBase and exported AvatarBaseProps in index.ts * Made textTransform property accept right values in avatar-base.tsx * Adding temporary changed extensions * Reverted files back to tsx and resolved conflicts * Solved linting errors * AvatarBaseProps now extends TextProps * Changing extension to resolve conflict * Reverted extensions back to tsx after resolving conflicts * Added forwardRef in AvatarBase * Updated import name of AvatarBaseSize in README.mdx. Removed empty children attribute from AvatarBase storybook file --------- Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com> Co-authored-by: Brad Decker <bhdecker84@gmail.com>
137 lines
4.3 KiB
TypeScript
137 lines
4.3 KiB
TypeScript
/* eslint-disable jest/require-top-level-describe */
|
|
import { render, screen } from '@testing-library/react';
|
|
import React from 'react';
|
|
|
|
import {
|
|
BackgroundColor,
|
|
BorderColor,
|
|
Color,
|
|
TextColor,
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import { AvatarBase } from './avatar-base';
|
|
import { AvatarBaseSize } from './avatar-base.types';
|
|
|
|
describe('AvatarBase', () => {
|
|
it('should render correctly', () => {
|
|
const { getByTestId, container } = render(
|
|
<AvatarBase data-testid="avatar-base" />,
|
|
);
|
|
expect(getByTestId('avatar-base')).toBeDefined();
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
it('should render with different size classes', () => {
|
|
const { getByTestId } = render(
|
|
<>
|
|
<AvatarBase size={AvatarBaseSize.Xs} data-testid="avatar-base-xs" />
|
|
<AvatarBase size={AvatarBaseSize.Sm} data-testid="avatar-base-sm" />
|
|
<AvatarBase size={AvatarBaseSize.Md} data-testid="avatar-base-md" />
|
|
<AvatarBase size={AvatarBaseSize.Lg} data-testid="avatar-base-lg" />
|
|
<AvatarBase size={AvatarBaseSize.Xl} data-testid="avatar-base-xl" />
|
|
</>,
|
|
);
|
|
expect(getByTestId('avatar-base-xs')).toHaveClass(
|
|
'mm-avatar-base--size-xs mm-text--body-xs',
|
|
);
|
|
expect(getByTestId('avatar-base-sm')).toHaveClass(
|
|
'mm-avatar-base--size-sm mm-text--body-sm',
|
|
);
|
|
expect(getByTestId('avatar-base-md')).toHaveClass(
|
|
'mm-avatar-base--size-md mm-text--body-sm',
|
|
);
|
|
expect(getByTestId('avatar-base-lg')).toHaveClass(
|
|
'mm-avatar-base--size-lg mm-text--body-lg-medium',
|
|
);
|
|
expect(getByTestId('avatar-base-xl')).toHaveClass(
|
|
'mm-avatar-base--size-xl mm-text--body-lg-medium',
|
|
);
|
|
});
|
|
// className
|
|
it('should render with custom className', () => {
|
|
const { getByTestId } = render(
|
|
<AvatarBase data-testid="avatar-base" className="test-class" />,
|
|
);
|
|
expect(getByTestId('avatar-base')).toHaveClass('test-class');
|
|
});
|
|
// children
|
|
it('should render children', () => {
|
|
render(
|
|
<AvatarBase data-testid="avatar-base">
|
|
<img width="100%" src="./images/arbitrum.svg" />
|
|
</AvatarBase>,
|
|
);
|
|
const image = screen.getByRole('img');
|
|
expect(image).toBeDefined();
|
|
expect(image).toHaveAttribute('src', './images/arbitrum.svg');
|
|
});
|
|
// color
|
|
it('should render with different colors', () => {
|
|
const { getByTestId } = render(
|
|
<>
|
|
<AvatarBase
|
|
color={TextColor.successDefault}
|
|
data-testid={TextColor.successDefault}
|
|
/>
|
|
<AvatarBase
|
|
color={TextColor.errorDefault}
|
|
data-testid={TextColor.errorDefault}
|
|
/>
|
|
</>,
|
|
);
|
|
expect(getByTestId(TextColor.successDefault)).toHaveClass(
|
|
`box--color-${TextColor.successDefault}`,
|
|
);
|
|
expect(getByTestId(TextColor.errorDefault)).toHaveClass(
|
|
`box--color-${TextColor.errorDefault}`,
|
|
);
|
|
});
|
|
// background color
|
|
it('should render with different background colors', () => {
|
|
const { getByTestId } = render(
|
|
<>
|
|
<AvatarBase
|
|
backgroundColor={BackgroundColor.successDefault}
|
|
data-testid={Color.successDefault}
|
|
/>
|
|
<AvatarBase
|
|
backgroundColor={BackgroundColor.errorDefault}
|
|
data-testid={Color.errorDefault}
|
|
/>
|
|
</>,
|
|
);
|
|
expect(getByTestId(Color.successDefault)).toHaveClass(
|
|
`box--background-color-${Color.successDefault}`,
|
|
);
|
|
expect(getByTestId(Color.errorDefault)).toHaveClass(
|
|
`box--background-color-${Color.errorDefault}`,
|
|
);
|
|
});
|
|
// border color
|
|
it('should render with different border colors', () => {
|
|
const { getByTestId } = render(
|
|
<>
|
|
<AvatarBase
|
|
borderColor={BorderColor.successDefault}
|
|
data-testid={Color.successDefault}
|
|
/>
|
|
<AvatarBase
|
|
borderColor={BorderColor.errorDefault}
|
|
data-testid={Color.errorDefault}
|
|
/>
|
|
</>,
|
|
);
|
|
expect(getByTestId(Color.successDefault)).toHaveClass(
|
|
`box--border-color-${Color.successDefault}`,
|
|
);
|
|
expect(getByTestId(Color.errorDefault)).toHaveClass(
|
|
`box--border-color-${Color.errorDefault}`,
|
|
);
|
|
});
|
|
it('should forward a ref to the root html element', () => {
|
|
const ref = React.createRef();
|
|
render(<AvatarBase ref={ref}>A</AvatarBase>);
|
|
expect(ref.current).not.toBeNull();
|
|
expect(ref.current.nodeName).toBe('DIV');
|
|
});
|
|
});
|