Repository: ueberdosis/tiptap
File: demos/src/Marks/Link/React/index.spec.js (JavaScript)

Code before:
    cy.get('.tiptap').paste({
      pastePayload:
        'https://example1.com, https://example2.com/foobar, (http://example3.com/foobar)',
      pasteType: 'text/plain',
    })

    cy.get('.tiptap')
      .find('a[href="https://example1.com"]')
      .should('contain', 'https://example1.com')

    cy.get('.tiptap')
      .find('a[href="https://example2.com/foobar"]')
      .should('contain', 'https://example2.com/foobar')

    cy.get('.tiptap')
      .find('a[href="http://example3.com/foobar"]')
      .should('contain', 'http://example3.com/foobar')
  })

  it('should not allow links with disallowed protocols', () => {
    const disallowedProtocols = ['ftp://example.com', 'file:///example.txt', 'mailto:test@example.com']

    disallowedProtocols.forEach(url => {
      cy.get('.tiptap').then(([{ editor }]) => {
        editor.commands.setContent(`<p><a href="${url}">Example Text</a></p>`)
        expect(editor.getHTML()).to.not.include(`<a href="${url}">`)
      })
    })
  })

  it('should not allow links with disallowed domains', () => {
    const disallowedDomains = ['https://example-phishing.com', 'https://malicious-site.net']

    disallowedDomains.forEach(url => {
      cy.get('.tiptap').then(([{ editor }]) => {
        editor.commands.setContent(`<p><a href="${url}">Example Text</a></p>`)
        expect(editor.getHTML()).to.not.include(`<a href="${url}">`)
      })
    })
  })

  it('should not auto-link a URL from a disallowed domain', () => {
    cy.get('.tiptap').type('https://example-phishing.com ') // disallowed domain
    cy.get('.tiptap').should('not.have.descendants', 'a')
    cy.get('.tiptap').should('contain.text', 'https://example-phishing.com')
  })
})


Review comment (suggestion):
```suggestion
        expect(editor.getHTML()).to.not.include(url)
```
Just a little more robust if the a tag had more attributes or something

Code after:
    cy.get('.tiptap').paste({
      pastePayload:
        'https://example1.com, https://example2.com/foobar, (http://example3.com/foobar)',
      pasteType: 'text/plain',
    })

    cy.get('.tiptap')
      .find('a[href="https://example1.com"]')
      .should('contain', 'https://example1.com')

    cy.get('.tiptap')
      .find('a[href="https://example2.com/foobar"]')
      .should('contain', 'https://example2.com/foobar')

    cy.get('.tiptap')
      .find('a[href="http://example3.com/foobar"]')
      .should('contain', 'http://example3.com/foobar')
  })

  it('should not allow links with disallowed protocols', () => {
    const disallowedProtocols = ['ftp://example.com', 'file:///example.txt', 'mailto:test@example.com']

    disallowedProtocols.forEach(url => {
      cy.get('.tiptap').then(([{ editor }]) => {
        editor.commands.setContent(`<p><a href="${url}">Example Text</a></p>`)
        expect(editor.getHTML()).to.not.include(url)
      })
    })
  })

  it('should not allow links with disallowed domains', () => {
    const disallowedDomains = ['https://example-phishing.com', 'https://malicious-site.net']

    disallowedDomains.forEach(url => {
      cy.get('.tiptap').then(([{ editor }]) => {
        editor.commands.setContent(`<p><a href="${url}">Example Text</a></p>`)
        expect(editor.getHTML()).to.not.include(url)
      })
    })
  })

  it('should not auto-link a URL from a disallowed domain', () => {
    cy.get('.tiptap').type('https://example-phishing.com ') // disallowed domain
    cy.get('.tiptap').should('not.have.descendants', 'a')
    cy.get('.tiptap').should('contain.text', 'https://example-phishing.com')
  })
})