-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(router): update router to support query params in intent links (#…
…7095) * feat(router): update router to support query params in intent links * fix(core): update RouterStateEvent interface * chore(core): add tests for query param intents
- Loading branch information
1 parent
04c374a
commit 793b2b0
Showing
8 changed files
with
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {describe, it} from '@jest/globals' | ||
import {expect} from '@playwright/experimental-ct-react' | ||
import {type Tool} from 'sanity' | ||
import {type RouterState} from 'sanity/router' | ||
|
||
import {resolveIntentState} from './helpers' | ||
|
||
describe('resolveIntentState', () => { | ||
const testTool: Tool = { | ||
name: 'test', | ||
title: 'Test tool', | ||
component: () => null, | ||
canHandleIntent: () => true, | ||
getIntentState: () => ({}), | ||
} | ||
|
||
it('should resolve intent state with query params', () => { | ||
const state: RouterState = { | ||
intent: 'edit', | ||
params: { | ||
id: 'p-bay-area-san-francisco-2022-08-17-2022-08-17', | ||
type: 'playlist', | ||
}, | ||
_searchParams: [['perspective', 'bundle.pedro-summer']], | ||
} | ||
|
||
const resolved = resolveIntentState([testTool], null, state) | ||
expect(resolved).toEqual({ | ||
type: 'state', | ||
isNotFound: false, | ||
state: { | ||
// searchParams are persisted in the router state | ||
_searchParams: [['perspective', 'bundle.pedro-summer']], | ||
tool: 'test', | ||
test: {}, | ||
}, | ||
}) | ||
}) | ||
}) |
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,33 @@ | ||
import {describe, expect, it} from '@jest/globals' | ||
import {render} from '@testing-library/react' | ||
|
||
import {IntentLink} from './IntentLink' | ||
import {route} from './route' | ||
import {RouterProvider} from './RouterProvider' | ||
|
||
describe('IntentLink', () => { | ||
it('should resolve intent link with query params', () => { | ||
const router = route.create('/test', [route.intents('/intent')]) | ||
const component = render( | ||
<IntentLink | ||
intent="edit" | ||
params={{ | ||
id: 'document-id-123', | ||
type: 'document-type', | ||
}} | ||
searchParams={[['perspective', `bundle.summer-drop`]]} | ||
/>, | ||
{ | ||
wrapper: ({children}) => ( | ||
<RouterProvider onNavigate={() => null} router={router} state={{}}> | ||
{children} | ||
</RouterProvider> | ||
), | ||
}, | ||
) | ||
// Component should render the query param in the href | ||
expect(component.container.querySelector('a')?.href).toContain( | ||
'/test/intent/edit/id=document-id-123;type=document-type/?perspective=bundle.summer-drop', | ||
) | ||
}) | ||
}) |
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