-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stepper: Apply extended props to
calypso_signup_start
. Update `tail…
…ored-ecommerce` flow (#93941)
- Loading branch information
1 parent
51df53d
commit d521b18
Showing
7 changed files
with
91 additions
and
19 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
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,51 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { renderHook } from '@testing-library/react'; | ||
import useSnakeCasedKeys from '../use-snake-cased-keys'; | ||
|
||
describe( 'useSnakeCasedKeys', () => { | ||
test( 'ensures reference equality given same input', () => { | ||
const input = { fooBar: 'fooBar' }; | ||
const { result, rerender } = renderHook( ( params ) => useSnakeCasedKeys( params ), { | ||
initialProps: { input }, | ||
} ); | ||
const previous = result.current; | ||
|
||
rerender( { input } ); | ||
expect( result.current ).toBe( previous ); | ||
} ); | ||
|
||
test( 'given fooBar it will convert correctly', () => { | ||
const input = { fooBar: 'fooBar' }; | ||
const expectedOutput = { foo_bar: 'fooBar' }; | ||
|
||
const { result } = renderHook( ( params ) => useSnakeCasedKeys( params ), { | ||
initialProps: { input }, | ||
} ); | ||
|
||
expect( result.current ).toEqual( expectedOutput ); | ||
} ); | ||
|
||
test( 'given foo_bar it will convert correctly', () => { | ||
const input = { foo_bar: 'fooBar' }; | ||
const expectedOutput = { foo_bar: 'fooBar' }; | ||
|
||
const { result } = renderHook( ( params ) => useSnakeCasedKeys( params ), { | ||
initialProps: { input }, | ||
} ); | ||
|
||
expect( result.current ).toEqual( expectedOutput ); | ||
} ); | ||
|
||
test( 'given foo123 it will convert correctly', () => { | ||
const input = { foo123bar: 'fooBar' }; | ||
const expectedOutput = { foo_123_bar: 'fooBar' }; | ||
|
||
const { result } = renderHook( ( params ) => useSnakeCasedKeys( params ), { | ||
initialProps: { input }, | ||
} ); | ||
|
||
expect( result.current ).toEqual( expectedOutput ); | ||
} ); | ||
} ); |
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,12 @@ | ||
import { useMemo } from '@wordpress/element'; | ||
import { convertToSnakeCase } from 'calypso/state/data-layer/utils'; | ||
|
||
interface Params { | ||
input?: Record< string, unknown >; | ||
} | ||
|
||
const useSnakeCasedKeys = ( { input }: Params ) => { | ||
return useMemo( () => input && ( convertToSnakeCase( input ) as Params[ 'input' ] ), [ input ] ); | ||
}; | ||
|
||
export default useSnakeCasedKeys; |