-
-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core,experience,schemas): support identifier page related params…
… for sign-in url
- Loading branch information
Showing
6 changed files
with
121 additions
and
9 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
55 changes: 55 additions & 0 deletions
55
packages/experience/src/hooks/use-identifier-params.test.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,55 @@ | ||
import { ExtraParamsKey, SignInIdentifier } from '@logto/schemas'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import * as reactRouterDom from 'react-router-dom'; | ||
|
||
import useIdentifierParams from './use-identifier-params'; | ||
|
||
// Mock the react-router-dom module | ||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useSearchParams: jest.fn(), | ||
})); | ||
|
||
// Helper function to mock search params | ||
const mockSearchParams = (params: Record<string, string>) => { | ||
const searchParams = new URLSearchParams(params); | ||
(reactRouterDom.useSearchParams as jest.Mock).mockReturnValue([searchParams]); | ||
}; | ||
|
||
describe('useIdentifierParams', () => { | ||
it('should return an empty array when no identifiers are provided', () => { | ||
mockSearchParams({}); | ||
const { result } = renderHook(() => useIdentifierParams()); | ||
expect(result.current.identifiers).toEqual([]); | ||
}); | ||
|
||
it('should parse and validate a single identifier', () => { | ||
mockSearchParams({ [ExtraParamsKey.Identifier]: 'email' }); | ||
const { result } = renderHook(() => useIdentifierParams()); | ||
expect(result.current.identifiers).toEqual([SignInIdentifier.Email]); | ||
}); | ||
|
||
it('should parse and validate multiple identifiers', () => { | ||
mockSearchParams({ [ExtraParamsKey.Identifier]: 'email phone' }); | ||
const { result } = renderHook(() => useIdentifierParams()); | ||
expect(result.current.identifiers).toEqual([SignInIdentifier.Email, SignInIdentifier.Phone]); | ||
}); | ||
|
||
it('should filter out invalid identifiers', () => { | ||
mockSearchParams({ [ExtraParamsKey.Identifier]: 'email invalid phone' }); | ||
const { result } = renderHook(() => useIdentifierParams()); | ||
expect(result.current.identifiers).toEqual([SignInIdentifier.Email, SignInIdentifier.Phone]); | ||
}); | ||
|
||
it('should handle empty string input', () => { | ||
mockSearchParams({ [ExtraParamsKey.Identifier]: '' }); | ||
const { result } = renderHook(() => useIdentifierParams()); | ||
expect(result.current.identifiers).toEqual([]); | ||
}); | ||
|
||
it('should handle identifiers with extra spaces', () => { | ||
mockSearchParams({ [ExtraParamsKey.Identifier]: ' email phone ' }); | ||
const { result } = renderHook(() => useIdentifierParams()); | ||
expect(result.current.identifiers).toEqual([SignInIdentifier.Email, SignInIdentifier.Phone]); | ||
}); | ||
}); |
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