Skip to content

Commit

Permalink
test: 🧪 refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
heorhi-deriv committed Oct 2, 2023
1 parent c878a73 commit 2c84aea
Showing 1 changed file with 13 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@ import BalanceText from '../balance-text';
import { render, screen } from '@testing-library/react';
import { StoreProvider, mockStore } from '@deriv/stores';

const createWrapper = (mock: ReturnType<typeof mockStore>) => {
const wrapper = ({ children }: { children: JSX.Element }) => <StoreProvider store={mock}>{children}</StoreProvider>;

return wrapper;
};

describe('BalanceText', () => {
it('should render the component', () => {
const mock = mockStore({});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

const { container } = render(<BalanceText balance={1000} currency='USD' size='m' underline_style='none' />, {
wrapper,
wrapper: createWrapper(mock),
});
expect(container).toBeInTheDocument();
});

it('should render the correct balance and currency', () => {
const mock = mockStore({});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

const { container } = render(<BalanceText balance={1000} currency='USD' size='m' underline_style='none' />, {
wrapper,
wrapper: createWrapper(mock),
});
expect(container).toBeInTheDocument();
expect(screen.getByText('1,000.00')).toBeInTheDocument();
Expand All @@ -35,12 +33,8 @@ describe('BalanceText', () => {
it('should render the correct div class for dotted underline_style', () => {
const mock = mockStore({});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

const { container } = render(<BalanceText balance={1000} currency='USD' size='m' underline_style='dotted' />, {
wrapper,
wrapper: createWrapper(mock),
});
expect(container).toBeInTheDocument();
expect(screen.getByTestId('dt_balance_text_container')).toHaveClass('balance-text--dotted');
Expand All @@ -56,12 +50,8 @@ describe('BalanceText', () => {
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

const { container } = render(<BalanceText balance={1000} currency='USD' size='m' underline_style='none' />, {
wrapper,
wrapper: createWrapper(mock),
});
expect(container).toBeInTheDocument();
expect(screen.getByText('1,000.00')).toHaveClass('balance-text__text--demo');
Expand All @@ -77,12 +67,8 @@ describe('BalanceText', () => {
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

const { container } = render(<BalanceText balance={1000} currency='USD' size='m' underline_style='none' />, {
wrapper,
wrapper: createWrapper(mock),
});
expect(container).toBeInTheDocument();
expect(screen.getByText('1,000.00')).toHaveClass('balance-text__text--real');
Expand All @@ -95,12 +81,8 @@ describe('BalanceText', () => {
},
});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

const { container } = render(<BalanceText balance={1000} currency='USD' size='m' underline_style='none' />, {
wrapper,
wrapper: createWrapper(mock),
});
expect(container).toBeInTheDocument();
expect(screen.getByText('1,000.00')).not.toHaveClass('balance-text__text--real');
Expand All @@ -110,12 +92,8 @@ describe('BalanceText', () => {
it('should have classname as container if underline_style is none', () => {
const mock = mockStore({});

const wrapper = ({ children }: { children: JSX.Element }) => (
<StoreProvider store={mock}>{children}</StoreProvider>
);

const { container } = render(<BalanceText balance={1000} currency='USD' size='m' underline_style='none' />, {
wrapper,
wrapper: createWrapper(mock),
});
expect(container).toBeInTheDocument();
expect(screen.getByTestId('dt_balance_text_container')).toHaveClass('balance-text__container');
Expand Down

0 comments on commit 2c84aea

Please sign in to comment.