Skip to content
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

test: split pasting tests into collab/non-collab #210

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/editor/e2e-tests/__tests__/pasting-collaboration.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @jest-environment ./setup/collaborative.jest.env.ts */

import {describe, expect, it} from '@jest/globals'

// Ideally pasting should be tested in a testing-library test, but I have not found a way to do it natively with testing-lib.
// The problem is to get permission to write to the host clipboard.
// We can do it in these test's though (as we can override browser permissions through packages/@sanity/portable-text-editor/test/setup/collaborative.jest.env.ts)
describe('Feature: Pasting Collaboration', () => {
it('can paste into an populated editor', async () => {
const [editorA, editorB] = await getEditors()
await editorB.insertText('Hey!')
await editorA.paste('Yo!')
const valueA = await editorA.getValue()
expect(valueA).toMatchObject([
{
_key: 'B-4',
_type: 'block',
children: [{_type: 'span', marks: [], text: 'Hey!Yo!'}], // _key is random here (from @sanity/block-tools) and is left out.
markDefs: [],
style: 'normal',
},
])
})
})
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/** @jest-environment ./setup/collaborative.jest.env.ts */
import '../setup/globals.jest'
/** @jest-environment ./setup/jest.env.ts */

import {describe, expect, it} from '@jest/globals'

// Ideally pasting should be tested in a testing-library test, but I have not found a way to do it natively with testing-lib.
// The problem is to get permission to write to the host clipboard.
// We can do it in these test's though (as we can override browser permissions through packages/@sanity/portable-text-editor/test/setup/collaborative.jest.env.ts)
describe('pasting', () => {
describe('Feature: Pasting', () => {
it('can paste into an empty editor', async () => {
const [editorA] = await getEditors()
const editorA = await getEditor()
await editorA.paste('Yo!')
const valueA = await editorA.getValue()
expect(valueA).toMatchObject([
Expand All @@ -21,24 +21,8 @@ describe('pasting', () => {
])
})

it('can paste into an populated editor', async () => {
const [editorA, editorB] = await getEditors()
await editorB.insertText('Hey!')
await editorA.paste('Yo!')
const valueA = await editorA.getValue()
expect(valueA).toMatchObject([
{
_key: 'B-4',
_type: 'block',
children: [{_type: 'span', marks: [], text: 'Hey!Yo!'}], // _key is random here (from @sanity/block-tools) and is left out.
markDefs: [],
style: 'normal',
},
])
})

it.skip('can paste empty lines from clipboard without duplicating keys', async () => {
const [editorA] = await getEditors()
it('can paste empty lines from clipboard without duplicating keys', async () => {
const editorA = await getEditor()
await editorA.paste('\n\n', 'text/plain')
const data = `<meta charset='utf-8'><div class="pt-block pt-text-block pt-text-block-style-normal" spellcheck="true"><div><div><div data-as="div" data-ui="Box" data-testid="text-block" class="sc-pyfCe ejpaYo"><div data-as="div" data-ui="Box" data-testid="text-block__wrapper" class="sc-pyfCe fzrBED sc-cqQeAO jubvhE"><div data-as="div" data-ui="Flex" class="sc-pyfCe hDoDhD sc-csuSiG dCdti"><div data-as="div" data-ui="Box" class="sc-pyfCe jRVwRg"><div data-read-only="false" data-testid="text-block__text" class="sc-jeToga carTaU"><div data-as="div" data-ui="Flex" class="sc-pyfCe fzrBED sc-csuSiG jCgSkH sc-cTVMo ixGLsO"><div data-text=""><div data-ui="Text" data-testid="text-style--normal" class="sc-bcXHqe bHshCf"><span><div class="sc-dMVFSy jJslKz"><div data-testid="text-style--normal" class="sc-dMVFSy jJslKz"><span><span><span data-slate-length="0">
</span></span></span></div></div></span></div></div></div></div></div><div data-as="div" data-ui="Box" class="sc-pyfCe fzrBED sc-eSEOys fsTfdf"><div data-as="div" data-ui="Box" class="sc-pyfCe kflhPW sc-ayeQl gUcksj"><div data-as="div" data-ui="Flex" class="sc-pyfCe fzrBED sc-csuSiG dCdti sc-iQAVnG htHGtr"></div></div></div></div></div></div></div></div></div><div class="pt-block pt-text-block pt-text-block-style-normal" spellcheck="true"><div><div><div data-as="div" data-ui="Box" data-testid="text-block" class="sc-pyfCe ejpaYo"><div data-as="div" data-ui="Box" data-testid="text-block__wrapper" class="sc-pyfCe fzrBED sc-cqQeAO jubvhE"><div data-as="div" data-ui="Flex" class="sc-pyfCe hDoDhD sc-csuSiG dCdti"><div data-as="div" data-ui="Box" class="sc-pyfCe jRVwRg"><div data-read-only="false" data-testid="text-block__text" class="sc-jeToga carTaU"><div data-as="div" data-ui="Flex" class="sc-pyfCe fzrBED sc-csuSiG jCgSkH sc-cTVMo ixGLsO"><div data-text=""><div data-ui="Text" data-testid="text-style--normal" class="sc-bcXHqe bHshCf"><span><div class="sc-dMVFSy jJslKz"><div data-testid="text-style--normal" class="sc-dMVFSy jJslKz"><span><span><span>
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/e2e-tests/setup/jest.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default class CollaborationEnvironment extends NodeEnvironment {
}

this.global.getEditor = async () => {
const editorId = `editor${testId}`
const editorId = `A${testId}`

return getPageEditor({
page: this._page!,
Expand Down Expand Up @@ -161,7 +161,7 @@ export default class CollaborationEnvironment extends NodeEnvironment {

// Open up the test document
await this._page?.goto(
`${WEB_SERVER_ROOT_URL}?editorId=editor${testId}&testId=${testId}`,
`${WEB_SERVER_ROOT_URL}?editorId=A${testId}&testId=${testId}`,
{
waitUntil: 'load',
},
Expand Down