Files
simple-react-app-kit/packages/lexical/src/plugins/selection-anchor.test.ts
T

30 lines
870 B
TypeScript
Raw Normal View History

// @vitest-environment jsdom
import { describe, expect, it } from "vitest"
import { createSelectionAnchor } from "./selection-anchor"
describe("createSelectionAnchor", () => {
it("does not use a browser selection outside the editor", () => {
const rootElement = document.createElement("div")
const externalElement = document.createElement("p")
const externalText = document.createTextNode("outside")
externalElement.append(externalText)
document.body.append(rootElement, externalElement)
const range = document.createRange()
range.selectNodeContents(externalText)
const selection = window.getSelection()
selection?.removeAllRanges()
selection?.addRange(range)
expect(createSelectionAnchor(rootElement)).toBe(rootElement)
selection?.removeAllRanges()
rootElement.remove()
externalElement.remove()
})
})