Skip to content

Commit

Permalink
added forward and backward boundary checks for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch committed Oct 10, 2024
1 parent 2434e5f commit 91ad89f
Showing 1 changed file with 68 additions and 3 deletions.
71 changes: 68 additions & 3 deletions tests/cypress/integration/core/getMarkRange.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ describe('getMarkRange', () => {
from: 11,
to: 17,
})

// eslint-disable-next-line no-console
console.log(range)
})

it('gets the correct range for a position at the start of the mark', () => {
Expand Down Expand Up @@ -75,4 +72,72 @@ describe('getMarkRange', () => {

expect(range).to.eq(undefined)
})

it('doesnt cross node boundaries on backward check', () => {
const testDocument = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{ type: 'text', text: 'This is a text with a ' },
{ type: 'text', text: 'link.', marks: [{ type: 'link', attrs: { href: 'https://tiptap.dev' } }] },
],
},
{
type: 'paragraph',
content: [
{ type: 'text', text: 'This is a text without a link.' },
],
},
],
}

const doc = Node.fromJSON(schema, testDocument)
const $pos = doc.resolve(28)
const range = getMarkRange($pos, schema.marks.link)

expect(range).to.deep.eq({
from: 23,
to: 28,
})

const nextRange = getMarkRange(doc.resolve(30), schema.marks.link)

expect(nextRange).to.eq(undefined)
})

it('doesnt cross node boundaries on forward check', () => {
const testDocument = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{ type: 'text', text: 'This is a text without a link.' },
],
},
{
type: 'paragraph',
content: [
{ type: 'text', text: 'A link', marks: [{ type: 'link', attrs: { href: 'https://tiptap.dev' } }] },
{ type: 'text', text: ' is at the start of this paragraph.' },
],
},
],
}
const doc = Node.fromJSON(schema, testDocument)

const range = getMarkRange(doc.resolve(32), schema.marks.link)

expect(range).to.eq(undefined)

const $pos = doc.resolve(33)
const nextRange = getMarkRange($pos, schema.marks.link)

expect(nextRange).to.deep.eq({
from: 33,
to: 39,
})
})
})

0 comments on commit 91ad89f

Please sign in to comment.