Skip to content

Commit

Permalink
chore: fix lint and test
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Oct 18, 2024
1 parent 3abc9d8 commit 53e9c38
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/presentation/src/preview/SharePreviewMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ export const SharePreviewMenu = memo(function SharePreviewMenuComponent(
</>
) : (
<Card padding={2} tone="caution" radius={3}>
<Text style={{textWrap: 'pretty'}}>You don't have permission to share previews.</Text>
<Text style={{textWrap: 'pretty'}}>
You don&apos;t have permission to share previews.
</Text>
</Card>
)}
</Menu>
Expand Down
1 change: 1 addition & 0 deletions packages/presentation/src/useDocumentsOnPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export function useDocumentsOnPage(
(key: string, perspective: ClientPerspective, sourceDocuments: DocumentOnPage[] = []) => {
const documents = sourceDocuments.filter((sourceDocument) => {
if ('_projectId' in sourceDocument && sourceDocument._projectId) {
// eslint-disable-next-line no-warning-comments
// @TODO Handle cross dataset references
if (!warnedAboutCrossDatasetReference) {
// eslint-disable-next-line no-console
Expand Down
26 changes: 17 additions & 9 deletions packages/presentation/test/usePreviewUrl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ beforeEach(() => {
})

function TestPrinter(props: {previewUrl: PreviewUrlOption; previewSearchParam?: string | null}) {
return `${usePreviewUrl(props.previewUrl, 'presentation', props.previewSearchParam || null)}`
return `${usePreviewUrl(props.previewUrl, 'presentation', 'previewDrafts', props.previewSearchParam || null, true)}`
}

describe('previewUrl handling', () => {
Expand All @@ -51,19 +51,21 @@ describe('previewUrl handling', () => {
client: null as unknown as SanityClient,
previewUrlSecret: 'abc123',
previewSearchParam: null,
studioPreviewPerspective: 'previewDraft',
})
vi.mocked(suspend).mockReturnValue(resolvedPreviewUrl)
expect(renderToStaticMarkup(<TestPrinter previewUrl={previewUrl} />)).toMatchInlineSnapshot(
`"http://localhost:3000/api/draft?sanity-preview-secret=abc123&amp;sanity-preview-pathname=%2F"`,
`"http://localhost:3000/api/draft?sanity-preview-secret=abc123&amp;sanity-preview-perspective=previewDraft&amp;sanity-preview-pathname=%2F"`,
)
resolvedPreviewUrl = await resolvePreviewUrl({
client: null as unknown as SanityClient,
previewUrlSecret: 'dfg456',
previewSearchParam: '/preview',
studioPreviewPerspective: 'previewDraft',
})
vi.mocked(suspend).mockReturnValue(resolvedPreviewUrl)
expect(renderToStaticMarkup(<TestPrinter previewUrl={previewUrl} />)).toMatchInlineSnapshot(
`"http://localhost:3000/api/draft?sanity-preview-secret=dfg456&amp;sanity-preview-pathname=%2Fpreview"`,
`"http://localhost:3000/api/draft?sanity-preview-secret=dfg456&amp;sanity-preview-perspective=previewDraft&amp;sanity-preview-pathname=%2Fpreview"`,
)
})

Expand All @@ -77,19 +79,21 @@ describe('previewUrl handling', () => {
client: null as unknown as SanityClient,
previewUrlSecret: 'abc123',
previewSearchParam: null,
studioPreviewPerspective: 'previewDraft',
})
vi.mocked(suspend).mockReturnValue(resolvedPreviewUrl)
expect(renderToStaticMarkup(<TestPrinter previewUrl={previewUrl} />)).toMatchInlineSnapshot(
`"http://localhost:3000/api/draft?sanity-preview-secret=abc123&amp;sanity-preview-pathname=%2Fpreview"`,
`"http://localhost:3000/api/draft?sanity-preview-secret=abc123&amp;sanity-preview-perspective=previewDraft&amp;sanity-preview-pathname=%2Fpreview"`,
)
resolvedPreviewUrl = await resolvePreviewUrl({
client: null as unknown as SanityClient,
previewUrlSecret: 'dfg456',
previewSearchParam: '/preview',
studioPreviewPerspective: 'previewDraft',
})
vi.mocked(suspend).mockReturnValue(resolvedPreviewUrl)
expect(renderToStaticMarkup(<TestPrinter previewUrl={previewUrl} />)).toMatchInlineSnapshot(
`"http://localhost:3000/api/draft?sanity-preview-secret=dfg456&amp;sanity-preview-pathname=%2Fpreview"`,
`"http://localhost:3000/api/draft?sanity-preview-secret=dfg456&amp;sanity-preview-perspective=previewDraft&amp;sanity-preview-pathname=%2Fpreview"`,
)
})

Expand All @@ -103,19 +107,21 @@ describe('previewUrl handling', () => {
client: null as unknown as SanityClient,
previewUrlSecret: 'abc123',
previewSearchParam: null,
studioPreviewPerspective: 'previewDraft',
})
vi.mocked(suspend).mockReturnValue(resolvedPreviewUrl)
expect(renderToStaticMarkup(<TestPrinter previewUrl={previewUrl} />)).toMatchInlineSnapshot(
`"https://my.vercel.app/api/draft?sanity-preview-secret=abc123&amp;sanity-preview-pathname=%2F"`,
`"https://my.vercel.app/api/draft?sanity-preview-secret=abc123&amp;sanity-preview-perspective=previewDraft&amp;sanity-preview-pathname=%2F"`,
)
resolvedPreviewUrl = await resolvePreviewUrl({
client: null as unknown as SanityClient,
previewUrlSecret: 'dfg456',
previewSearchParam: '/preview',
studioPreviewPerspective: 'previewDraft',
})
vi.mocked(suspend).mockReturnValue(resolvedPreviewUrl)
expect(renderToStaticMarkup(<TestPrinter previewUrl={previewUrl} />)).toMatchInlineSnapshot(
`"https://my.vercel.app/api/draft?sanity-preview-secret=dfg456&amp;sanity-preview-pathname=%2Fpreview"`,
`"https://my.vercel.app/api/draft?sanity-preview-secret=dfg456&amp;sanity-preview-perspective=previewDraft&amp;sanity-preview-pathname=%2Fpreview"`,
)
})

Expand All @@ -130,19 +136,21 @@ describe('previewUrl handling', () => {
client: null as unknown as SanityClient,
previewUrlSecret: 'abc123',
previewSearchParam: null,
studioPreviewPerspective: 'previewDraft',
})
vi.mocked(suspend).mockReturnValue(resolvedPreviewUrl)
expect(renderToStaticMarkup(<TestPrinter previewUrl={previewUrl} />)).toMatchInlineSnapshot(
`"https://my.vercel.app/api/draft?sanity-preview-secret=abc123&amp;sanity-preview-pathname=%2Fpreview"`,
`"https://my.vercel.app/api/draft?sanity-preview-secret=abc123&amp;sanity-preview-perspective=previewDraft&amp;sanity-preview-pathname=%2Fpreview"`,
)
resolvedPreviewUrl = await resolvePreviewUrl({
client: null as unknown as SanityClient,
previewUrlSecret: 'dfg456',
previewSearchParam: '/preview',
studioPreviewPerspective: 'previewDraft',
})
vi.mocked(suspend).mockReturnValue(resolvedPreviewUrl)
expect(renderToStaticMarkup(<TestPrinter previewUrl={previewUrl} />)).toMatchInlineSnapshot(
`"https://my.vercel.app/api/draft?sanity-preview-secret=dfg456&amp;sanity-preview-pathname=%2Fpreview"`,
`"https://my.vercel.app/api/draft?sanity-preview-secret=dfg456&amp;sanity-preview-perspective=previewDraft&amp;sanity-preview-pathname=%2Fpreview"`,
)
})

Expand Down

0 comments on commit 53e9c38

Please sign in to comment.