Skip to content

Commit

Permalink
try this
Browse files Browse the repository at this point in the history
  • Loading branch information
ricokahler committed Apr 17, 2024
1 parent 36212f4 commit 55b7748
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 26 deletions.
24 changes: 11 additions & 13 deletions packages/sanity/playwright-ct/tests/comments/CommentInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ test.describe('Comments', () => {
const $editable = page.getByTestId('comment-input-editable')
await $editable.waitFor({state: 'visible'})
await page.keyboard.type('@')
const $mentionsMenu = page.getByTestId('comments-mentions-menu')
await $mentionsMenu.waitFor({state: 'visible'})
await expect(page.getByTestId('comments-mentions-menu')).toBeVisible()
await page.keyboard.press('Enter')
await $mentionsMenu.waitFor({state: 'detached'})
await expect(page.getByTestId('comments-mentions-menu')).not.toBeVisible()
// TODO: find a way to mock `useUser`!
await page.getByTestId('comment-mentions-loading-skeleton').waitFor({state: 'visible'})
await expect(page.getByTestId('comment-mentions-loading-skeleton')).toBeVisible()
})

test('Should bring up mentions menu when pressing the @ button, whilst retaining focus on PTE', async ({
Expand All @@ -42,28 +41,27 @@ test.describe('Comments', () => {
const $editable = page.getByTestId('comment-input-editable')
await $editable.waitFor({state: 'visible'})
const $mentionButton = page.getByTestId('comment-input-mention-button')
await $mentionButton.waitFor({state: 'visible'})
await $mentionButton.click()
await page.getByTestId('comments-mentions-menu').waitFor({state: 'visible'})
await expect(page.getByTestId('comments-mentions-menu')).toBeVisible()
await expect($editable).toBeFocused()
})

test('Should be able to submit', async ({mount, page}) => {
const {insertPortableText} = testHelpers({page})
let resolve!: () => void
const submitted = Object.assign(new Promise<void>((r) => (resolve = r)), {resolve})

// eslint-disable-next-line react/jsx-handler-names
await mount(<CommentsInputStory onSubmit={submitted.resolve} />)
let submitted = false
const onSubmit = () => {
submitted = true
}
await mount(<CommentsInputStory onSubmit={onSubmit} />)
const $editable = page.getByTestId('comment-input-editable')
$editable.waitFor({state: 'visible'})
await expect($editable).toBeEditable()
// Test that blank comments can't be submitted
await page.keyboard.press('Enter')
expect(submitted).toBe(false)
await insertPortableText('This is a comment!', $editable)
await expect($editable).toHaveText('This is a comment!')
await page.keyboard.press('Enter')
await submitted
expect(submitted).toBe(true)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {type CurrentUser, type PortableTextBlock} from '@sanity/types'
import {noop} from 'lodash'
import {useState} from 'react'
import {CommentInput} from 'sanity'

import {CommentInput} from '../../../src/core/comments/components/pte/comment-input/CommentInput'
import {type UserListWithPermissionsHookValue} from '../../../src/core/hooks/useUserListWithPermissions'
import {TestWrapper} from '../formBuilder/utils/TestWrapper'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import {type SanityClient} from '@sanity/client'
import {type SchemaTypeDefinition} from '@sanity/types'
import {Card, LayerProvider, studioTheme, ThemeProvider, ToastProvider} from '@sanity/ui'
import {type ReactNode, Suspense, useEffect, useState} from 'react'
import {
ResourceCacheProvider,
type SchemaTypeDefinition,
SourceProvider,
type Workspace,
WorkspaceProvider,
} from 'sanity'
import {Pane, PaneContent, PaneLayout} from 'sanity/structure'

import {type Workspace} from '../../../../src/core/config/types'
import {ResourceCacheProvider} from '../../../../src/core/store/_legacy/ResourceCacheProvider'
import {SourceProvider} from '../../../../src/core/studio/source'
import {WorkspaceProvider} from '../../../../src/core/studio/workspace'
import {Pane, PaneContent, PaneLayout} from '../../../../src/structure/components'
import {createMockSanityClient} from '../../../../test/mocks/mockSanityClient'
import {getMockWorkspace} from '../../../../test/testUtils/getMockWorkspaceFromConfig'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface CommentInputHandle {
}

/**
* @beta
* @internal
* @hidden
*/
export const CommentInput = forwardRef<CommentInputHandle, CommentInputProps>(
Expand Down
1 change: 1 addition & 0 deletions packages/sanity/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './changeIndicators'
export {
CommentInput,
type CommentIntentGetter,
COMMENTS_INSPECTOR_NAME,
CommentsIntentProvider,
Expand Down
3 changes: 1 addition & 2 deletions packages/sanity/src/structure/components/pane/Pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ const Root = styled(Card)`
`

/**
*
* @hidden
* @beta This API will change. DO NOT USE IN PRODUCTION.
* @internal
*/
// eslint-disable-next-line complexity
export const Pane = forwardRef(function Pane(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ interface PaneContentProps {
}

/**
*
* @hidden
* @beta This API will change. DO NOT USE IN PRODUCTION.
* @internal
*/
export const PaneContent = forwardRef(function PaneContent(
props: PaneContentProps & Omit<HTMLProps<HTMLDivElement>, 'as' | 'height' | 'ref'>,
Expand Down
9 changes: 8 additions & 1 deletion packages/sanity/src/structure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ export type {
ParameterizedLinkProps,
ReferenceChildLinkProps,
} from './components'
export {ConfirmDeleteDialog, PaneLayout, PaneRouterContext, usePaneRouter} from './components'
export {
ConfirmDeleteDialog,
Pane,
PaneContent,
PaneLayout,
PaneRouterContext,
usePaneRouter,
} from './components'
export {structureLocaleNamespace, type StructureLocaleResourceKeys} from './i18n'
export * from './panes/document'
export {DocumentInspectorHeader} from './panes/document/documentInspector'
Expand Down

0 comments on commit 55b7748

Please sign in to comment.