From 304c8d22aad85bb4b9a3875f55ba541c23cafc1f Mon Sep 17 00:00:00 2001 From: Victor Okpon Date: Thu, 22 Sep 2022 04:25:12 +0100 Subject: [PATCH] more tests on Button --- CommonUI/src/Tests/Button.test.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CommonUI/src/Tests/Button.test.tsx b/CommonUI/src/Tests/Button.test.tsx index 3a902163bc..63dede1578 100644 --- a/CommonUI/src/Tests/Button.test.tsx +++ b/CommonUI/src/Tests/Button.test.tsx @@ -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;