This repository has been archived by the owner on Jan 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(toolbar): add tests for button toolbar
- Loading branch information
1 parent
af22ce0
commit 0e56e3c
Showing
9 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import '../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import { renderHook } from '@testing-library/react-hooks' | ||
import { | ||
ButtonBarProvider, | ||
useButtons, | ||
useButtonToolbarSetter, | ||
} from 'page-header/ButtonBarProvider' | ||
import { Button } from '@hospitalrun/components' | ||
|
||
describe('Button Bar Provider', () => { | ||
it('should update and fetch data from the button bar provider', () => { | ||
const expectedButtons = [<Button>test 1</Button>] | ||
const wrapper = ({ children }: any) => <ButtonBarProvider>{children}</ButtonBarProvider> | ||
|
||
const { result } = renderHook( | ||
() => { | ||
const update = useButtonToolbarSetter() | ||
update(expectedButtons) | ||
return useButtons() | ||
}, | ||
{ wrapper }, | ||
) | ||
|
||
expect(result.current).toEqual(expectedButtons) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import '../../__mocks__/matchMediaMock' | ||
import React from 'react' | ||
import { Button } from '@hospitalrun/components' | ||
import { mocked } from 'ts-jest/utils' | ||
import { mount } from 'enzyme' | ||
import * as ButtonBarProvider from '../../page-header/ButtonBarProvider' | ||
import ButtonToolBar from '../../page-header/ButtonToolBar' | ||
|
||
describe('Button Tool Bar', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
it('should render the buttons in the provider', () => { | ||
const buttons: React.ReactNode[] = [<Button>Test 1</Button>, <Button>Test</Button>] | ||
jest.spyOn(ButtonBarProvider, 'useButtons') | ||
mocked(ButtonBarProvider).useButtons.mockReturnValue(buttons) | ||
|
||
const wrapper = mount(<ButtonToolBar />) | ||
|
||
expect(wrapper.childAt(0).getElement()).toEqual(buttons[0]) | ||
expect(wrapper.childAt(1).getElement()).toEqual(buttons[1]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters