more tests on Button

This commit is contained in:
Victor Okpon 2022-09-22 04:25:12 +01:00
parent b661f619f1
commit 304c8d22aa

View File

@ -2,6 +2,9 @@ import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import Button from '../Components/Button/Button';
import ButtonType from '../Components/Button/ButtonTypes';
import ShortcutKey from '../Components/ShortcutKey/ShortcutKey';
import Icon from '../Components/Icon/Icon';
describe('Button test', () => {
const handleClick: undefined | (() => void) = jest.fn();
@ -11,6 +14,9 @@ describe('Button test', () => {
title="sample title"
disabled={true}
onClick={handleClick}
shortcutKey={ShortcutKey.Settings}
type={ButtonType.Button}
showIconOnRight={false}
/>
);
const title: HTMLElement = screen.getByText('sample title');
@ -20,6 +26,14 @@ describe('Button test', () => {
expect(testId).toBeInTheDocument;
});
test('it should have type button', () => {
expect(testId).toHaveAttribute('type', 'button');
});
test('it should have key shortcut', () => {
expect(testId).toHaveTextContent(ShortcutKey.Settings);
});
test('it should have a title', () => {
expect(title).toBeInTheDocument;
});
@ -28,6 +42,14 @@ describe('Button test', () => {
expect(testId).toHaveAttribute('disabled');
});
test('it should have class btn', () => {
expect(testId).toHaveClass('btn');
});
test('it should have icon', () => {
expect(Icon).toBeInTheDocument;
});
test('it should handle onClick event', () => {
fireEvent.click(testId);
expect(handleClick).toBeCalled;