mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 19:56:38 +02:00
✨ Import text-editor code into the repository
This commit is contained in:
parent
68397edd4d
commit
04a0d867b0
65 changed files with 11112 additions and 7 deletions
26
frontend/text-editor/editor/content/dom/TextNode.test.js
Normal file
26
frontend/text-editor/editor/content/dom/TextNode.test.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { describe, test, expect } from 'vitest';
|
||||
import { isTextNode, getTextNodeLength } from './TextNode';
|
||||
import { createLineBreak } from './LineBreak';
|
||||
|
||||
/* @vitest-environment jsdom */
|
||||
describe("TextNode", () => {
|
||||
test("isTextNode should return true when the passed node is a Text", () => {
|
||||
expect(isTextNode(new Text("Hello, World!"))).toBe(true);
|
||||
expect(isTextNode(Infinity)).toBe(false);
|
||||
expect(isTextNode(true)).toBe(false);
|
||||
expect(isTextNode("hola")).toBe(false);
|
||||
expect(isTextNode({})).toBe(false);
|
||||
expect(isTextNode([])).toBe(false);
|
||||
expect(() => isTextNode(undefined)).toThrowError('Invalid text node');
|
||||
expect(() => isTextNode(null)).toThrowError('Invalid text node');
|
||||
expect(() => isTextNode(0)).toThrowError('Invalid text node');
|
||||
});
|
||||
|
||||
test("getTextNodeLength should return the length of the text node or 0 if it is a <br>", () => {
|
||||
expect(getTextNodeLength(new Text("Hello, World!"))).toBe(13);
|
||||
expect(getTextNodeLength(createLineBreak())).toBe(0);
|
||||
expect(() => getTextNodeLength(undefined)).toThrowError('Invalid text node');
|
||||
expect(() => getTextNodeLength(null)).toThrowError('Invalid text node');
|
||||
expect(() => getTextNodeLength(0)).toThrowError('Invalid text node');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue