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.
Merge branch 'master' into edit-appointment
- Loading branch information
Showing
13 changed files
with
277 additions
and
107 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
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,27 @@ | ||
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 key="test1">Test 1</Button>, | ||
<Button key="test2">Test 2</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useState } from 'react' | ||
|
||
type Props = { | ||
children?: React.ReactNode | ||
} | ||
|
||
type ButtonUpdater = (buttons: React.ReactNode[]) => void | ||
|
||
const ButtonBarStateContext = React.createContext<React.ReactNode[]>([]) | ||
const ButtonBarUpdateContext = React.createContext<ButtonUpdater>(() => { | ||
// empty initial state | ||
}) | ||
|
||
function ButtonBarProvider(props: Props) { | ||
const { children } = props | ||
const [state, setState] = useState<React.ReactNode[]>([]) | ||
return ( | ||
<ButtonBarStateContext.Provider value={state}> | ||
<ButtonBarUpdateContext.Provider value={setState}>{children}</ButtonBarUpdateContext.Provider> | ||
</ButtonBarStateContext.Provider> | ||
) | ||
} | ||
function useButtons() { | ||
const context = React.useContext(ButtonBarStateContext) | ||
if (context === undefined) { | ||
throw new Error('useButtons must be used within a Button Bar Context') | ||
} | ||
return context | ||
} | ||
function useButtonToolbarSetter() { | ||
const context = React.useContext(ButtonBarUpdateContext) | ||
if (context === undefined) { | ||
throw new Error('useButtonToolBarSetter must be used within a Button Bar Context') | ||
} | ||
return context | ||
} | ||
|
||
export { ButtonBarProvider, useButtons, useButtonToolbarSetter } |
Oops, something went wrong.