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

Kate / Test coverage + TS migration: Components/Elements/Media files in Trader package #8457

Merged
merged 18 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
@@ -0,0 +1,15 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { MediaDescription } from 'App/Components/Elements/Media';

const test_children = 'Test Children';

describe('MediaDescription', () => {
it('should render children inside of proper MediaDescription div container with className', () => {
render(<MediaDescription>{test_children}</MediaDescription>);
const test_props_children = screen.getByText(test_children);

expect(test_props_children).toBeInTheDocument();
expect(test_props_children).toHaveClass('media__description');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { MediaHeading } from 'App/Components/Elements/Media';

const test_children = 'Test Children';

describe('MediaHeading', () => {
it('should render children inside of proper MediaHeading div container with className', () => {
render(<MediaHeading>{test_children}</MediaHeading>);
const test_props_children = screen.getByText(test_children);

expect(test_props_children).toBeInTheDocument();
expect(test_props_children).toHaveClass('media__heading');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { MediaIcon } from 'App/Components/Elements/Media';

const test_disabled = 'Interval Duration Disabled Light Icon';
const test_enabled = 'Interval Duration Enabled Light Icon';
const mock_props = {
disabled: jest.fn(() => <div>{test_disabled}</div>),
enabled: jest.fn(() => <div>{test_enabled}</div>),
id: 'test_id',
is_enabled: true,
};

describe('MediaIcon', () => {
it('should render MediaIcon component with enabled SVG if is_enabled === true', () => {
render(<MediaIcon {...mock_props} />);

expect(screen.getByText(test_enabled)).toBeInTheDocument();
});
it('should render MediaIcon component with disabled SVG if is_enabled === false', () => {
render(<MediaIcon {...mock_props} is_enabled={false} />);

expect(screen.getByText(test_disabled)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import MediaItem from '../media-item';

const test_children = 'Test Children';

describe('MediaItem', () => {
it('should render children inside of proper MediaItem div container with className', () => {
render(<MediaItem>{test_children}</MediaItem>);
const test_props_children = screen.getByText(test_children);

expect(test_props_children).toBeInTheDocument();
expect(test_props_children).toHaveClass('media');
});
});
8 changes: 4 additions & 4 deletions packages/trader/src/App/Components/Elements/Media/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import MediaItem from './media-item.jsx';
import MediaItem from './media-item';

export * from './media-description.jsx';
export * from './media-heading.jsx';
export * from './media-icon.jsx';
export * from './media-description';
export * from './media-heading';
export * from './media-icon';
export default MediaItem;

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const MediaDescription: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => (
kate-deriv marked this conversation as resolved.
Show resolved Hide resolved
<div className='media__description'>{children}</div>
);

export { MediaDescription };

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react';

const MediaHeading: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => (
kate-deriv marked this conversation as resolved.
Show resolved Hide resolved
<div className='media__heading'>{children}</div>
);

export { MediaHeading };

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

type TMediaIcon = {
disabled: React.FC<React.SVGAttributes<SVGElement>>;
enabled: React.FC<React.SVGAttributes<SVGElement>>;
kate-deriv marked this conversation as resolved.
Show resolved Hide resolved
id: string;
is_enabled: boolean;
};
const MediaIcon = ({ id, is_enabled, enabled, disabled }: TMediaIcon) => {
const Icon = is_enabled ? enabled : disabled;
return <Icon id={id} className='media__icon' />;
};

export { MediaIcon };

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const MediaItem: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => <div className='media'>{children}</div>;
kate-deriv marked this conversation as resolved.
Show resolved Hide resolved

export default MediaItem;
2 changes: 1 addition & 1 deletion types/svg.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module '*.svg' {
const content: React.SVGAttributes<SVGElement>;
const content: React.FC<React.SVGAttributes<SVGElement>>;
kate-deriv marked this conversation as resolved.
Show resolved Hide resolved
export default content;
}