UNPKG

@ithaka/bonsai

Version:
59 lines (43 loc) 1.77 kB
import {BonsaiTextEditor} from "../bonsai.texteditor"; jest.mock("quill"); describe("Bonsai Text Editor", function () { let editors; beforeEach(() => { document.body.innerHTML = ` <div id='editor' data-text-editor></div> <div id='editor2' data-text-editor data-help-link="https://www.google.com"></div>`; editors = BonsaiTextEditor.editorFactory(); }); test("editors have been created", function () { expect(editors.length).toBe(2); }); test("expect editor can be retreived by ID", function() { expect(BonsaiTextEditor.getEditorById(editors, "editor")).not.toBeUndefined(); }); test("toolbars are created", function () { expect($("[data-quill-toolbar]").length).toBe(2); }); test("save buttons are created", function () { expect($("[data-quill-save]").length).toBe(2); }); test("editors have unique ids", function () { expect(editors[0].uuid).not.toBe(editors[1].uuid); }); test("save button emits save event", function () { expect.assertions(2); $("#editor").on("save.bonsai-text-editor", (event, data, html) => { expect(data).not.toBeNull(); expect(html).not.toBeNull(); }); $("[data-quill-save]").click(); }); test("help button is hidden when there is no data-help-link", function() { expect(editors[0].$toolbar.find(".help-button").length).toBe(0); }); test("help button is displayed when there is a data-help-link", function() { expect(editors[1].$toolbar.find(".help-button").length).toBe(1); }); test("cancel link is displayed", function() { expect(editors[1].$cancelLink).not.toBeUndefined(); }); });