diff --git a/demos/src/Extensions/TextAlign/React/index.html b/demos/src/Extensions/TextAlign/React/index.html new file mode 100644 index 00000000..55141727 --- /dev/null +++ b/demos/src/Extensions/TextAlign/React/index.html @@ -0,0 +1,15 @@ + + +
+ + + + + + + + diff --git a/demos/src/Extensions/TextAlign/React/index.jsx b/demos/src/Extensions/TextAlign/React/index.jsx new file mode 100644 index 00000000..9407c669 --- /dev/null +++ b/demos/src/Extensions/TextAlign/React/index.jsx @@ -0,0 +1,61 @@ +import React from "react"; +import { useEditor, EditorContent } from "@tiptap/react"; +import Document from "@tiptap/extension-document"; +import Paragraph from "@tiptap/extension-paragraph"; +import Heading from "@tiptap/extension-heading"; +import Text from "@tiptap/extension-text"; +import TextAlign from "@tiptap/extension-text-align"; + +export default () => { + const editor = useEditor({ + extensions: [ + Document, + Paragraph, + Text, + Heading, + TextAlign.configure({ + types: ["heading", "paragraph"], + }), + ], + content: ` +first paragraph
+second paragraph
+ `, + }); + + if (!editor) { + return null; + } + + return ( +Example Text
"); + }); + }); + + it("should parse left align text correctly (and not render)", () => { + cy.get(".ProseMirror").then(([{ editor }]) => { + editor.commands.setContent('Example Text
'); + expect(editor.getHTML()).to.eq("Example Text
"); + }); + }); + + it("should parse center align text correctly", () => { + cy.get(".ProseMirror").then(([{ editor }]) => { + editor.commands.setContent('Example Text
'); + expect(editor.getHTML()).to.eq('Example Text
'); + }); + }); + + it("should parse right align text correctly", () => { + cy.get(".ProseMirror").then(([{ editor }]) => { + editor.commands.setContent('Example Text
'); + expect(editor.getHTML()).to.eq('Example Text
'); + }); + }); + + it("should parse left justify text correctly", () => { + cy.get(".ProseMirror").then(([{ editor }]) => { + editor.commands.setContent('Example Text
'); + expect(editor.getHTML()).to.eq('Example Text
'); + }); + }); + + it("aligns the text left on the 1st button", () => { + cy.get("button:nth-child(1)").click(); + + cy.get(".ProseMirror").find("p").should("not.have.css", "text-align", "left"); + }); + + it("aligns the text center on the 2nd button", () => { + cy.get("button:nth-child(2)").click(); + + cy.get(".ProseMirror").find("p").should("have.css", "text-align", "center"); + }); + + it("aligns the text right on the 3rd button", () => { + cy.get("button:nth-child(3)").click(); + + cy.get(".ProseMirror").find("p").should("have.css", "text-align", "right"); + }); + + it("aligns the text justified on the 4th button", () => { + cy.get("button:nth-child(4)").click(); + + cy.get(".ProseMirror").find("p").should("have.css", "text-align", "justify"); + }); + + it("aligns the text default on the 5th button", () => { + cy.get("button:nth-child(5)").click(); + + cy.get(".ProseMirror").find("p").should("not.have.css", "text-align", "left"); + }); + + it("aligns the text left when pressing the keyboard shortcut", () => { + cy.get(".ProseMirror") + .trigger("keydown", { modKey: true, shiftKey: true, key: "l" }) + .find("p") + .should("not.have.css", "text-align", "left"); + }); + + it("aligns the text center when pressing the keyboard shortcut", () => { + cy.get(".ProseMirror") + .trigger("keydown", { modKey: true, shiftKey: true, key: "e" }) + .find("p") + .should("have.css", "text-align", "center"); + }); + + it("aligns the text right when pressing the keyboard shortcut", () => { + cy.get(".ProseMirror") + .trigger("keydown", { modKey: true, shiftKey: true, key: "r" }) + .find("p") + .should("have.css", "text-align", "right"); + }); + + it("aligns the text justified when pressing the keyboard shortcut", () => { + cy.get(".ProseMirror") + .trigger("keydown", { modKey: true, shiftKey: true, key: "j" }) + .find("p") + .should("have.css", "text-align", "justify"); + }); +});