-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(core): update intent link for releases tool #7468
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,5 +1,5 @@ | ||
import {type RouterState} from 'sanity/router' | ||
|
||
export interface ReleasesRouterState extends RouterState { | ||
bundleId?: string | ||
releaseId?: string | ||
} |
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,7 +1,8 @@ | ||
import {beforeEach, describe, expect, it, jest} from '@jest/globals' | ||
import {fireEvent, render, screen} from '@testing-library/react' | ||
import {render, screen} from '@testing-library/react' | ||
import {type HTMLProps} from 'react' | ||
import {type BundleDocument, usePerspective} from 'sanity' | ||
import {useRouter} from 'sanity/router' | ||
import {type IntentLinkProps} from 'sanity/router' | ||
|
||
import {createTestProvider} from '../../../../../../../../test/testUtils/TestProvider' | ||
import {type DocumentPaneContextValue} from '../../../../DocumentPaneContext' | ||
|
@@ -22,24 +23,34 @@ jest.mock('sanity', () => { | |
} | ||
}) | ||
|
||
jest.mock('sanity/router', () => ({ | ||
useRouter: jest.fn().mockReturnValue({ | ||
navigateIntent: jest.fn(), | ||
stickyParams: {}, | ||
}), | ||
route: { | ||
create: jest.fn(), | ||
}, | ||
IntentLink: jest.fn(), | ||
})) | ||
const IntentLinkMock = (props: IntentLinkProps & HTMLProps<HTMLAnchorElement>) => { | ||
const {params = {}, intent, ...rest} = props | ||
const stringParams = params | ||
? Object.entries(params) | ||
.map(([key, value]) => `${key}=${value}`) | ||
.join('&') | ||
: '' | ||
|
||
return <a {...rest} href={`/intent/${intent}/${stringParams}`} /> | ||
} | ||
|
||
jest.mock('sanity/router', () => { | ||
return { | ||
useRouter: jest.fn().mockReturnValue({ | ||
stickyParams: {}, | ||
}), | ||
route: { | ||
create: jest.fn(), | ||
}, | ||
IntentLink: IntentLinkMock, | ||
} | ||
}) | ||
|
||
jest.mock('../../../../useDocumentPane') | ||
|
||
const mockUseDocumentPane = useDocumentPane as jest.MockedFunction< | ||
() => Partial<DocumentPaneContextValue> | ||
> | ||
const mockUseRouter = useRouter as jest.MockedFunction<typeof useRouter> | ||
const navigateIntent = mockUseRouter().navigateIntent as jest.Mock | ||
|
||
const mockUsePerspective = usePerspective as jest.Mock | ||
|
||
|
@@ -90,45 +101,33 @@ describe('DocumentPerspectiveMenu', () => { | |
const wrapper = await createTestProvider() | ||
render(<DocumentPerspectiveMenu />, {wrapper}) | ||
|
||
expect(screen.getByTestId('button-document-release')).toBeInTheDocument() | ||
const linkButton = screen.getByRole('link', {name: 'Spring Drop'}) | ||
expect(linkButton).toBeInTheDocument() | ||
expect(linkButton).toHaveAttribute('href', '/intent/release/id=spring-drop') | ||
expect(linkButton).toHaveTextContent('Spring Drop') | ||
}) | ||
|
||
it('should not render the bundle badge if the document does not exist in the bundle', async () => { | ||
mockUseDocumentPane.mockReturnValue({ | ||
existsInBundle: false, | ||
}) | ||
|
||
const wrapper = await createTestProvider() | ||
render(<DocumentPerspectiveMenu />, {wrapper}) | ||
|
||
expect(screen.queryByTestId('button-document-release')).toBeNull() | ||
}) | ||
|
||
it('should navigate to the release intent when the bundle badge is clicked', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test doesn't apply anymore, because we are not rendering a button, we are now rendering a |
||
mockUseDocumentPane.mockReturnValue({ | ||
documentVersions: [ | ||
{ | ||
_id: 'spring-drop', | ||
title: 'Spring Drop', | ||
hue: 'magenta', | ||
icon: 'heart-filled', | ||
_type: 'release', | ||
authorId: '', | ||
_id: 'spring-drop', | ||
_createdAt: '', | ||
_updatedAt: '', | ||
_rev: '', | ||
}, | ||
], | ||
existsInBundle: true, | ||
existsInBundle: false, | ||
}) | ||
|
||
const wrapper = await createTestProvider() | ||
render(<DocumentPerspectiveMenu />, {wrapper}) | ||
|
||
expect(screen.queryByTestId('button-document-release')).toBeInTheDocument() | ||
fireEvent.click(screen.getByTestId('button-document-release')) | ||
|
||
expect(navigateIntent).toHaveBeenCalledTimes(1) | ||
expect(navigateIntent).toHaveBeenCalledWith('release', {id: 'spring-drop'}) | ||
expect(screen.queryByRole('link', {name: 'Spring Drop'})).toBeNull() | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of not resolving the intent if the params are missing, resolve to the tool at root level.