Skip to content

Commit

Permalink
refactor(common): fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vetalcore committed Nov 26, 2024
1 parent 51a0f58 commit 19253b5
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('Testing getTxInputsValueAndAddress function', () => {
]);

const result = getTxInputsValueAndAddress(
Array.from({ length: 30 }).map((_, index) => ({ index, txId: 'txId1' }) as unknown as Cardano.TxIn),
Array.from({ length: 30 }).map((_, index) => ({ index, txId: 'txId1' } as unknown as Cardano.TxIn)),
{
transactionsByHashes
} as unknown as ChainHistoryProvider,
Expand Down Expand Up @@ -285,7 +285,7 @@ describe('Testing getTxInputsValueAndAddress function', () => {
);

const result = getTxInputsValueAndAddress(
Array.from({ length: 30 }).map((_, index) => ({ index: 0, txId: `txId${index}` }) as Cardano.TxIn),
Array.from({ length: 30 }).map((_, index) => ({ index: 0, txId: `txId${index}` } as Cardano.TxIn)),
{
transactionsByHashes
} as unknown as ChainHistoryProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('CollapsablePanel', () => {
);
const clickable = queryByRole('button');
act(() => {
fireEvent.click(clickable);
clickable && fireEvent.click(clickable);
});
expect(queryByTestId('test-content')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ describe('DrawerNavigation', () => {
const { queryByTestId } = render(<DrawerNavigation onArrowIconClick={onClick} />);
const backButton = queryByTestId('navigation-button-arrow');
expect(backButton).toBeInTheDocument();
fireEvent.click(backButton);
backButton && fireEvent.click(backButton);
expect(onClick).toHaveBeenCalled();
});
test('shows close button if on click function is defined', () => {
const onClick = jest.fn();
const { queryByTestId } = render(<DrawerNavigation onCloseIconClick={onClick} />);
const closeButton = queryByTestId('navigation-button-cross');
expect(closeButton).toBeInTheDocument();
fireEvent.click(closeButton);
closeButton && fireEvent.click(closeButton);
expect(onClick).toHaveBeenCalled();
});
test('shows left actions if passed as props instead of back arrow', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Input', () => {
const input = queryByTestId('input-test');
expect(input).toHaveValue('');
act(() => {
fireEvent.change(input, { target: { value: 'new value' } });
input && fireEvent.change(input, { target: { value: 'new value' } });
});
expect(input).toHaveValue('new value');
expect(onChange).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('TextArea', () => {
const area = queryByTestId('text-area-test');
expect(area).toHaveValue('');
act(() => {
fireEvent.change(area, { target: { value: 'new value' } });
area && fireEvent.change(area, { target: { value: 'new value' } });
});
expect(area).toHaveValue('new value');
expect(onChange).toHaveBeenCalled();
Expand All @@ -24,7 +24,8 @@ describe('TextArea', () => {
const onBlur = jest.fn();
const { queryByTestId } = render(<TextArea dataTestId="text-area-test" onBlur={onBlur} />);
await waitFor(() => {
fireEvent.blur(queryByTestId('text-area-test'));
const area = queryByTestId('text-area-test');
area && fireEvent.blur(area);
});
expect(onBlur).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ describe('Search', () => {
const onInputBlur = jest.fn();
const { queryByTestId } = render(<Search onInputBlur={onInputBlur} />);
act(() => {
fireEvent.blur(queryByTestId('search-input'));
const input = queryByTestId('search-input');
input && fireEvent.blur(input);
});
expect(onInputBlur).toHaveBeenCalled();
});
test('call onInputFocus function prop on search input focus', () => {
const onInputFocus = jest.fn();
const { queryByTestId } = render(<Search onInputFocus={onInputFocus} />);
act(() => {
fireEvent.focus(queryByTestId('search-input'));
const input = queryByTestId('search-input');
input && fireEvent.focus(input);
});
expect(onInputFocus).toHaveBeenCalled();
});
Expand All @@ -32,7 +34,7 @@ describe('Search', () => {
const clearButton = queryByTestId('search-clear-button');
expect(clearButton).toBeInTheDocument();
act(() => {
fireEvent.click(clearButton);
clearButton && fireEvent.click(clearButton);
});
expect(onClearButtonClick).toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ const ToastContainer = ({ text, duration, withProgressBar }: ToastProps) => {
};

describe('Testing TextContent component', () => {
const duration = 10;
const props: ToastProps = {
text: 'test text',
duration: 10,
duration,
withProgressBar: true
};

Expand Down Expand Up @@ -82,6 +83,6 @@ describe('Testing TextContent component', () => {

setTimeout(() => {
expect(screen.queryAllByText(props.text)).toHaveLength(0);
}, props.duration + 1);
}, duration + 1);
});
});

0 comments on commit 19253b5

Please sign in to comment.