Skip to content

Commit

Permalink
Merge pull request #683 from glific/increase-test-coverage
Browse files Browse the repository at this point in the history
Increase test coverage
  • Loading branch information
kurund authored Nov 6, 2020
2 parents db6164d + fb45b46 commit 5b943ad
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
18 changes: 18 additions & 0 deletions src/components/UI/DropdownDialog/DropdownDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react';
import { mount } from 'enzyme';
import { DropdownDialog } from './DropdownDialog';
import { DialogBox } from '../DialogBox/DialogBox';
import { Dropdown } from '../Form/Dropdown/Dropdown';
import { Select } from '@material-ui/core';
import { act } from 'react-dom/test-utils';

const mockCallbackCancel = jest.fn();
const mockCallbackOK = jest.fn();
Expand All @@ -23,3 +27,17 @@ test('it should have a description as per default value', () => {
const wrapper = mount(dialogBox);
expect(wrapper.find('[data-testid="description"]').text()).toBe('This is default dialog');
});

test('handleOk and onChange function', () => {
const wrapper = mount(dialogBox);
wrapper.find(DialogBox).prop('handleOk')();
expect(mockCallbackOK).toBeCalled();

act(() => {
wrapper
.find(Select)
.at(0)
.props()
.onChange({ target: { value: 1 } });
});
});
12 changes: 12 additions & 0 deletions src/components/UI/Layout/Navigation/SideDrawer/SideDrawer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ describe('side drawer testing', () => {
expect(menuItems.at(i).text()).toEqual(sideDrawerMenus[i].title);
}
});

test('check closing and opening of side drawer', () => {
const wrapper = mount(component);
wrapper.find('button[data-testid="drawer-button"]').first().simulate('click');
wrapper.find('button[data-testid="drawer-button-closed"]').first().simulate('click');
});

it('should open bottom menus', () => {
const wrapper = mount(component);
wrapper.find('div[data-testid="bottom-menu"]').first().simulate('click');
expect(wrapper.find('a[data-testid="MenuItem"]').first().text()).toBe('My Profile');
});
});
13 changes: 6 additions & 7 deletions src/components/UI/Layout/Navigation/SideDrawer/SideDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const SideDrawer: React.SFC<SideDrawerProps> = (props) => {
<IconButton
color="inherit"
aria-label="open drawer"
data-testid="drawer-button-closed"
style={{ margin: 'auto' }}
onClick={() => setFullOpen(true)}
>
Expand All @@ -162,10 +163,6 @@ export const SideDrawer: React.SFC<SideDrawerProps> = (props) => {

const container = window !== undefined ? () => window.document.body : undefined;

const handleClick = () => {
setActive(!active);
};

// check access for settings on page reload
if (!settingMenu) {
getRoleBasedAccess();
Expand All @@ -174,7 +171,7 @@ export const SideDrawer: React.SFC<SideDrawerProps> = (props) => {
const settingMenus = settingMenu ? (
<div>
<Tooltip title="Settings" placement="top">
<Link to={'/settings'} onClick={handleClick}>
<Link to={'/settings'}>
<IconButton data-testid="settingsMenu">
<img
src={location.pathname === '/settings' ? ActiveIcon : InactiveIcon}
Expand Down Expand Up @@ -207,7 +204,9 @@ export const SideDrawer: React.SFC<SideDrawerProps> = (props) => {
variant="temporary"
anchor={theme.direction === 'rtl' ? 'right' : 'left'}
open={mobileOpen}
onClose={() => setMobileOpen(!mobileOpen)}
onClose={() => {
setMobileOpen(!mobileOpen);
}}
classes={{
paper: classes.drawerPaper,
}}
Expand All @@ -234,7 +233,7 @@ export const SideDrawer: React.SFC<SideDrawerProps> = (props) => {
>
<div className={bottonMenuClasses.join(' ')}>
{settingMenus}
<div onClick={() => getMenus()}>
<div data-testid="bottom-menu" onClick={() => getMenus()}>
<Menu menus={staffManagementMenus}>
<Tooltip title="Staff Management" placement="top">
<IconButton data-testid="staffManagementMenu">
Expand Down
21 changes: 21 additions & 0 deletions src/components/UI/Layout/Navigation/SideMenus/SideMenus.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { mount } from 'enzyme';
import { wait } from '@testing-library/react';
import SideMenus from './SideMenus';
import { getCurrentUserQuery } from '../../../../../mocks/User';

const mocks = [getCurrentUserQuery];
describe('side menu testing', () => {
const component = (
<MemoryRouter>
<SideMenus opened={false} />
</MemoryRouter>
);

it('it should be initialized properly', async () => {
const wrapper = mount(component);
await wait();
expect(wrapper).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SideMenus: React.SFC<SideMenusProps> = (props) => {
{props.opened ? (
<ListItemText
disableTypography
data-testid="list-item"
className={clsx(styles.Text, {
[styles.SelectedText]: isSelected,
[styles.UnselectedText]: !isSelected,
Expand Down

0 comments on commit 5b943ad

Please sign in to comment.