Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
426 additions
and
176 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as renderWithReduxContext } from './renderWithReduxContext'; | ||
export { default as renderWithRouterContext } from './renderWithRouterContext'; | ||
export * from './renderWithRouterContext'; | ||
|
||
export * from './suppressReactDevErrors'; |
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,14 @@ | ||
import React, { ReactElement, ComponentType } from 'react'; | ||
import { isElement } from 'react-is'; | ||
import { Store } from 'redux'; | ||
import { Provider } from 'react-redux'; | ||
import { render } from '@testing-library/react'; | ||
|
||
const renderWithReduxContext = ( | ||
AppRoot: ReactElement | ComponentType, | ||
store: Store, | ||
): ReturnType<typeof render> => { | ||
return render(<Provider store={store}>{isElement(AppRoot) ? AppRoot : <AppRoot />}</Provider>); | ||
}; | ||
|
||
export default renderWithReduxContext; |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
export { default as reduxDecorator } from './reduxDecorator'; | ||
export * from './reduxDecorator'; | ||
|
||
export { default as useCountSelector } from './useCountSelector'; | ||
export * from './useCountSelector'; | ||
export { default as useStateSelector } from './useStateSelector'; | ||
|
||
export * from './store'; |
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,11 @@ | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { DevHelperState } from './store'; | ||
|
||
const stateSelector = (state: DevHelperState) => state; | ||
|
||
const useStateSelector = (): DevHelperState => { | ||
return useSelector(stateSelector); | ||
}; | ||
|
||
export default useStateSelector; |
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
38 changes: 38 additions & 0 deletions
38
packages/react-pauseable-containers/src/PauseableComponentContainer.test.tsx
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 @@ | ||
/* eslint-env jest */ | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import * as React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { PauseableComponentContainer } from '.'; | ||
|
||
describe('PauseableComponentContainer', () => { | ||
it('allows updates', () => { | ||
const { rerender } = render( | ||
<PauseableComponentContainer shouldUpdate={true}>First render</PauseableComponentContainer>, | ||
); | ||
|
||
expect(screen.queryByText('First render')).toBeInTheDocument(); | ||
|
||
rerender( | ||
<PauseableComponentContainer shouldUpdate={true}>Second render</PauseableComponentContainer>, | ||
); | ||
|
||
expect(screen.queryByText('First render')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('Second render')).toBeInTheDocument(); | ||
}); | ||
|
||
it('prevents updates', () => { | ||
const { rerender } = render( | ||
<PauseableComponentContainer shouldUpdate={false}>First render</PauseableComponentContainer>, | ||
); | ||
|
||
expect(screen.queryByText('First render')).toBeInTheDocument(); | ||
|
||
rerender( | ||
<PauseableComponentContainer shouldUpdate={false}>Second render</PauseableComponentContainer>, | ||
); | ||
|
||
expect(screen.queryByText('First render')).toBeInTheDocument(); | ||
expect(screen.queryByText('Second render')).not.toBeInTheDocument(); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
packages/react-pauseable-containers/src/PauseableReduxContainer.test.tsx
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,59 @@ | ||
/* eslint-env jest */ | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import * as React from 'react'; | ||
import { screen } from '@testing-library/react'; | ||
|
||
import { | ||
createDevHelperStore, | ||
incrementAction, | ||
renderWithReduxContext, | ||
useCountSelector, | ||
} from 'react-hibernate-dev-helpers'; | ||
|
||
import { PauseableReduxContainer } from '.'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
const CountDisplay: React.FC = () => { | ||
const count = useCountSelector(); | ||
return <div>count = {count}</div>; | ||
}; | ||
|
||
describe('PauseableReduxContainer', () => { | ||
it('allows updates', () => { | ||
const myStore = createDevHelperStore(); | ||
|
||
renderWithReduxContext( | ||
<PauseableReduxContainer shouldUpdate={true}> | ||
<CountDisplay /> | ||
</PauseableReduxContainer>, | ||
myStore, | ||
); | ||
|
||
expect(screen.queryByText('count = 0')).toBeInTheDocument(); | ||
|
||
act(() => { | ||
myStore.dispatch(incrementAction()); | ||
}); | ||
|
||
expect(screen.queryByText('count = 1')).toBeInTheDocument(); | ||
}); | ||
|
||
it('prevents updates', () => { | ||
const myStore = createDevHelperStore(); | ||
|
||
renderWithReduxContext( | ||
<PauseableReduxContainer shouldUpdate={false}> | ||
<CountDisplay /> | ||
</PauseableReduxContainer>, | ||
myStore, | ||
); | ||
|
||
expect(screen.queryByText('count = 0')).toBeInTheDocument(); | ||
|
||
act(() => { | ||
myStore.dispatch(incrementAction()); | ||
}); | ||
|
||
expect(screen.queryByText('count = 0')).toBeInTheDocument(); | ||
}); | ||
}); |
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
50 changes: 0 additions & 50 deletions
50
packages/react-pauseable-containers/stories/PauseableComponentItem.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.