From 031c05d6e6a76a211cfc39ad34c1636da607d8e1 Mon Sep 17 00:00:00 2001 From: Khushal Agarwal Date: Sun, 25 Apr 2021 23:27:31 +0530 Subject: [PATCH] Improved unit tests coverage in the package (#2974) * improved avatar unit tests coverage * improved switch unit tests * improved checkbox unit tests * improved themeprovider and fab unit tests * improved input tests * added more unit tests * improved withBadge unit tests * Added more tests for button and ListItem --- src/avatar/Avatar.tsx | 4 +- src/avatar/__tests__/Avatar.js | 21 + .../__tests__/__snapshots__/Avatar.js.snap | 68 ++ .../__tests__/__snapshots__/withBadge.js.snap | 26 + src/badge/__tests__/withBadge.js | 7 + src/buttons/__tests__/Button.js | 14 + src/buttons/__tests__/ButtonGroup.js | 1 + src/buttons/__tests__/FAB.js | 41 + src/buttons/__tests__/SpeedDial.js | 8 +- .../__tests__/__snapshots__/FAB.js.snap | 875 ++++++++++++++++++ .../__tests__/__snapshots__/SpeedDial.js.snap | 19 +- src/checkbox/__tests__/CheckBox.js | 31 + .../__tests__/__snapshots__/CheckBox.js.snap | 239 +++++ src/config/__tests__/ThemeProvider.js | 9 + .../__snapshots__/ThemeProvider.js.snap | 72 ++ src/input/__tests__/Input.js | 6 + .../__tests__/__snapshots__/Input.js.snap | 55 ++ .../__tests__/LinearProgress.js | 7 + src/list/__tests__/ListItem.js | 21 + .../__tests__/__snapshots__/ListItem.js.snap | 40 + src/searchbar/__tests__/SearchBar-android.js | 11 + src/switch/__tests__/Switch.js | 18 +- .../__tests__/__snapshots__/Switch.js.snap | 19 +- src/tab/__tests__/tab.js | 6 + 24 files changed, 1599 insertions(+), 19 deletions(-) diff --git a/src/avatar/Avatar.tsx b/src/avatar/Avatar.tsx index 14d4959568..330c82d7d2 100644 --- a/src/avatar/Avatar.tsx +++ b/src/avatar/Avatar.tsx @@ -74,8 +74,8 @@ const AvatarComponent: Avatar = ({ children, ...attributes }: React.PropsWithChildren) => { - const width = - typeof size === 'number' ? size : avatarSizes[size] || avatarSizes.small; + let width = avatarSizes.small; + width = typeof size === 'number' ? size : avatarSizes[size]; const height = width; const titleSize = width / 2; const iconSize = width / 2; diff --git a/src/avatar/__tests__/Avatar.js b/src/avatar/__tests__/Avatar.js index 7ec50a3849..ec38de87db 100644 --- a/src/avatar/__tests__/Avatar.js +++ b/src/avatar/__tests__/Avatar.js @@ -118,6 +118,14 @@ describe('Avatar Component', () => { expect(component.length).toBe(1); expect(toJson(component)).toMatchSnapshot(); }); + + it('default', () => { + const component = shallow( + + ); + expect(component.length).toBe(1); + expect(toJson(component)).toMatchSnapshot(); + }); }); describe('Placeholders', () => { @@ -170,6 +178,19 @@ describe('Avatar Component', () => { expect(toJson(component)).toMatchSnapshot(); }); + it('renders using image with imageProps', () => { + const component = shallow( + + ); + expect(toJson(component)).toMatchSnapshot(); + }); + it("shouldn't show placeholder if not using source", () => { const component = shallow( `; +exports[`Avatar Component Placeholders renders using image with imageProps 1`] = ` + + + +`; + exports[`Avatar Component Placeholders shouldn't show placeholder if not using source 1`] = ` `; +exports[`Avatar Component Sizes default 1`] = ` + + + +`; + exports[`Avatar Component allows custom imageProps 1`] = ` `; +exports[`withBadge HOC just value should render when no value 1`] = ` + + + + +`; + exports[`withBadge HOC just value should render with just a value 1`] = ` { expect(component.length).toBe(1); expect(toJson(component)).toMatchSnapshot(); }); + + it('should render when no value', () => { + const BadgedComponent = withBadge()(TouchableOpacity); + const component = shallow(); + expect(component.length).toBe(1); + expect(toJson(component)).toMatchSnapshot(); + }); }); describe('with options', () => { diff --git a/src/buttons/__tests__/Button.js b/src/buttons/__tests__/Button.js index 7dc6eb2447..13c438f01c 100644 --- a/src/buttons/__tests__/Button.js +++ b/src/buttons/__tests__/Button.js @@ -8,6 +8,20 @@ import { ThemeProvider } from '../../config'; import ThemedButton, { Button } from '../Button'; describe('Button Component', () => { + beforeEach(() => { + let useEffect = jest.spyOn(React, 'useEffect'); + useEffect.mockImplementation((f) => f()); + const app = shallow( +