-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(playwright-ct): add tests for CommentInput
Add some basic tests for the comment input. More to come.
- Loading branch information
1 parent
b952256
commit 12486b1
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
packages/sanity/playwright-ct/tests/comments/CommentInput.spec.tsx
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,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
40
packages/sanity/playwright-ct/tests/comments/CommentInputStory.tsx
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,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 GitHub Actions / typeCheck
|
||
// ... | ||
}} | ||
onSubmit={() => { | ||
// ... | ||
}} | ||
/> | ||
</TestWrapper> | ||
) | ||
} |