Skip to content

Commit

Permalink
test: split pasting tests into collab/non-collab
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhg committed Sep 24, 2024
1 parent cec47b1 commit cb9beba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
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

0 comments on commit cb9beba

Please sign in to comment.