Skip to content

Commit

Permalink
test(playwright-ct): add tests for CommentInput
Browse files Browse the repository at this point in the history
Add some basic tests for the comment input. More to come.
  • Loading branch information
skogsmaskin committed Oct 20, 2023
1 parent b952256 commit 12486b1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/sanity/playwright-ct/tests/comments/CommentInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {expect, test} from '@playwright/experimental-ct-react'
import React from 'react'
import {testHelpers} from '../utils/testHelpers'
import {CommentsInputStory} from './CommentInputStory'

test.describe('Comments', () => {
test.describe('CommentInput', () => {
test('Should render', async ({mount, page}) => {
await mount(<CommentsInputStory />)
const $editable = page.getByTestId('comment-input-editable')
await expect($editable).toBeVisible()
})

test('Should be able to type into', async ({mount, page}) => {
const {insertPortableText} = testHelpers({page})
await mount(<CommentsInputStory />)
const $editable = page.getByTestId('comment-input-editable')
await expect($editable).toBeEditable()
await insertPortableText('My first comment!', $editable)
await expect($editable).toHaveText('My first comment!')
})

test('Should bring up mentions menu when typing @', async ({mount, page}) => {
await mount(<CommentsInputStory />)
const $editable = page.getByTestId('comment-input-editable')
await expect($editable).toBeEditable()
await page.keyboard.type(`@`)
await expect(page.getByTestId('comments-mentions-menu')).toBeVisible()
})
})
})
40 changes: 40 additions & 0 deletions packages/sanity/playwright-ct/tests/comments/CommentInputStory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, {useState} from 'react'
import {CurrentUser, PortableTextBlock} from '@sanity/types'
import {CommentInput} from '../../../src/desk/comments/src/components/pte/comment-input/CommentInput'
import {TestWrapper} from '../formBuilder/utils/TestWrapper'

const currentUser: CurrentUser = {
email: '',
id: '',
name: '',
role: '',
roles: [],
profileImage: '',
provider: '',
}

const SCHEMA_TYPES: [] = []

export function CommentsInputStory() {
const [value, setValue] = useState<PortableTextBlock[] | null>(null)

return (
<TestWrapper schemaTypes={SCHEMA_TYPES}>
<CommentInput
focusOnMount
placeholder="Your comment..."
focusLock
currentUser={currentUser}
onChange={setValue}
value={value}
mentionOptions={{data: [], error: null, loading: false}}
onEditDiscard={() => {

Check failure on line 31 in packages/sanity/playwright-ct/tests/comments/CommentInputStory.tsx

View workflow job for this annotation

GitHub Actions / typeCheck

Type '{ focusOnMount: true; placeholder: string; focusLock: true; currentUser: CurrentUser; onChange: Dispatch<SetStateAction<PortableTextBlock[] | null>>; value: PortableTextBlock[] | null; mentionOptions: { ...; }; onEditDiscard: () => void; onSubmit: () => void; }' is not assignable to type 'IntrinsicAttributes & CommentInputProps & RefAttributes<CommentInputHandle>'.
// ...
}}
onSubmit={() => {
// ...
}}
/>
</TestWrapper>
)
}

0 comments on commit 12486b1

Please sign in to comment.