Skip to content

Commit

Permalink
Merge pull request #1 from cesarhenrq/qa
Browse files Browse the repository at this point in the history
4567 - Text component
  • Loading branch information
cesarhenrq authored Sep 26, 2023
2 parents f7b797b + 65dde14 commit 254ab2e
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/components/Text/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { render, screen } from '@testing-library/react';
import { expect } from '@jest/globals';
import '@testing-library/jest-dom/extend-expect';

import { fontSizes, fontColors } from './test-helpers';

import Text from './';

describe('<Text />', () => {
it('should be defined', () => {
render(<Text label="test" />);

const element = screen.getByText('test');

expect(element).toBeDefined();
});

fontSizes.forEach(fontSize => {
it(`should render with font-size: ${fontSize.value}`, () => {
render(<Text label="test" fontSize={fontSize.label} />);

const element = screen.getByText('test');

(expect as any)(element).toHaveStyle(`font-size: + ${fontSize.value}`);
});
});

fontColors.forEach(fontColor => {
it(`should render with color: ${fontColor.value}`, () => {
render(<Text label="test" fontColor={fontColor.label} />);

const element = screen.getByText('test');

(expect as any)(element).toHaveStyle(`color: + ${fontColor.value}`);
});
});

it('should render with font-size: 16px as default', () => {
render(<Text label="test" />);

const element = screen.getByText('test');

(expect as any)(element).toHaveStyle('font-size: + 16px');
});

it('should render with color: #1A1033 as default', () => {
render(<Text label="test" />);

const element = screen.getByText('test');

(expect as any)(element).toHaveStyle('color: + #1A1033');
});
});
7 changes: 7 additions & 0 deletions src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as S from './styles';

const Text = (props: TextProps) => {
return <S.Text {...props}>{props.label}</S.Text>;
};

export default Text;
13 changes: 13 additions & 0 deletions src/components/Text/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import styled from 'styled-components';

export const Text = styled.p<TextProps>`
color: ${({ fontColor }) =>
fontColor ? `var(--${fontColor})` : 'var(--purple-dark)'};
font-size: ${({ fontSize }) =>
fontSize ? `var(--font-size-${fontSize})` : 'var(--font-size-normal)'};
font-weight: ${({ fontWeight }) => (fontWeight ? `${fontWeight}` : 'normal')};
font-style: ${({ fontStyle }) => (fontStyle ? `${fontStyle}` : 'normal')};
display: flex;
justify-content: center;
align-items: center;
`;
18 changes: 18 additions & 0 deletions src/components/Text/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const fontSizes: FontSizes[] = [
{ label: 'xsmall', value: '12px' },
{ label: 'small', value: '14px' },
{ label: 'normal', value: '16px' },
{ label: 'medium', value: '18px' },
{ label: 'large', value: '32px' },
{ label: 'xlarge', value: '48px' },
];

export const fontColors: FontColors[] = [
{ label: 'purple', value: '#5D5FEF' },
{ label: 'purple-light', value: '#B2A1D9' },
{ label: 'purple-dark', value: '#1A1033' },
{ label: 'white', value: '#FFFFFF' },
{ label: 'gray', value: '#A6A8AB' },
{ label: 'gray-light', value: '#D1D1D1' },
{ label: 'yellow', value: '#FBB04D' },
];
8 changes: 8 additions & 0 deletions src/types/FontColor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type FontColor =
| 'purple'
| 'purple-light'
| 'purple-dark'
| 'white'
| 'gray'
| 'gray-light'
| 'yellow';
4 changes: 4 additions & 0 deletions src/types/FontColors.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type FontColors = {
label: FontColor;
value: string;
};
1 change: 1 addition & 0 deletions src/types/FontSize.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type FontSize = 'normal' | 'small' | 'xsmall' | 'medium' | 'large' | 'xlarge';
4 changes: 4 additions & 0 deletions src/types/FontSizes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type FontSizes = {
label: FontSize;
value: string;
};
1 change: 1 addition & 0 deletions src/types/FontStyle.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type FontStyle = 'normal' | 'italic';
1 change: 1 addition & 0 deletions src/types/FontWeight.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type FontWeight = 'normal' | 'bold' | 'lighter';
7 changes: 7 additions & 0 deletions src/types/TextProps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type TextProps = {
fontSize?: FontSize;
fontWeight?: FontWeight;
fontColor?: FontColor;
label: string;
fontStyle?: FontStyle;
};

0 comments on commit 254ab2e

Please sign in to comment.