-
Notifications
You must be signed in to change notification settings - Fork 301
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5359 from AhmetAhunbayAWS/feat-identity-providers…
…/main Feat identity providers/main
- Loading branch information
Showing
24 changed files
with
1,320 additions
and
229 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
--- | ||
"@aws-amplify/ui-react-liveness": patch | ||
--- | ||
|
||
chore(deps): Update client-rekognitionstreaming sdk and custom fetch handler |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
packages/react-core/src/hooks/__tests__/useDataState.spec.ts
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,63 @@ | ||
import { act, renderHook } from '@testing-library/react-hooks'; | ||
import useDataState from '../useDataState'; | ||
|
||
const asyncAction = jest.fn((_prev: string, next: string) => | ||
Promise.resolve(next) | ||
); | ||
const syncAction = jest.fn((_prev: string, next: string) => next); | ||
|
||
describe('useDataState', () => { | ||
it.each([ | ||
{ type: 'async', action: asyncAction }, | ||
{ type: 'sync', action: syncAction }, | ||
])( | ||
'handles a $type action as expected in the happy path', | ||
async ({ action }) => { | ||
const initData = 'initial-data'; | ||
const nextData = 'next-data'; | ||
|
||
const { result, waitForNextUpdate } = renderHook(() => | ||
useDataState(action, 'initial-data') | ||
); | ||
|
||
// first render | ||
const [initState, handleAction] = result.current; | ||
|
||
expect(action).not.toHaveBeenCalled(); | ||
|
||
expect(initState.data).toBe(initData); | ||
expect(initState.isLoading).toBe(false); | ||
expect(initState.message).toBeUndefined(); | ||
|
||
// call action | ||
act(() => { | ||
handleAction(nextData); | ||
}); | ||
|
||
// loading result | ||
const [loadingState] = result.current; | ||
|
||
expect(action).toHaveBeenCalledTimes(1); | ||
expect(action).toHaveBeenCalledWith(initData, nextData); | ||
|
||
expect(loadingState.data).toBe(initData); | ||
expect(loadingState.isLoading).toBe(true); | ||
expect(loadingState.message).toBeUndefined(); | ||
|
||
await waitForNextUpdate(); | ||
|
||
// action complete | ||
const [nextState] = result.current; | ||
|
||
expect(action).toHaveBeenCalledTimes(1); | ||
expect(action).toHaveBeenCalledWith(initData, nextData); | ||
|
||
expect(nextState.data).toBe(nextData); | ||
expect(nextState.isLoading).toBe(false); | ||
expect(nextState.message).toBeUndefined(); | ||
} | ||
); | ||
|
||
it.todo('only returns the values of the last call to handleAction'); | ||
it.todo('handles exceptions thrown from provided action'); | ||
}); |
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,42 @@ | ||
import React from 'react'; | ||
|
||
interface ActionState<T> { | ||
data: T; | ||
isLoading: boolean; | ||
message: string | undefined; | ||
} | ||
|
||
const getActionState = <T>(data: T): ActionState<T> => ({ | ||
data, | ||
isLoading: false, | ||
message: undefined, | ||
}); | ||
|
||
export default function useDataState<T, K>( | ||
action: (prevData: Awaited<T>, ...input: K[]) => T | Promise<T>, | ||
initialData: Awaited<T> | ||
): [state: ActionState<Awaited<T>>, handleAction: (...input: K[]) => void] { | ||
const [actionState, setActionState] = React.useState<ActionState<Awaited<T>>>( | ||
() => getActionState(initialData) | ||
); | ||
|
||
const prevData = React.useRef(initialData); | ||
|
||
const handleAction: (...input: K[]) => void = React.useCallback( | ||
(...input) => { | ||
setActionState((prev) => ({ ...prev, isLoading: true })); | ||
|
||
Promise.resolve(action(prevData.current, ...input)) | ||
.then((data) => { | ||
prevData.current = data; | ||
setActionState(getActionState(data)); | ||
}) | ||
.catch(({ message }: Error) => { | ||
setActionState((prev) => ({ ...prev, isLoading: false, message })); | ||
}); | ||
}, | ||
[action] | ||
); | ||
|
||
return [actionState, handleAction]; | ||
} |
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
Oops, something went wrong.