define(["require", "exports", "chai", "wed/util", "../submode-config", "../wed-test-util"], function (require, exports, chai_1, util_1, submode_config_1, wed_test_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    describe("wed submodes", () => {
        let setup;
        let editor;
        before(() => {
            setup = new wed_test_util_1.EditorSetup(`${wed_test_util_1.dataPath}/wed_test_data/source_for_submodes_converted.xml`, submode_config_1.config, document);
            ({ editor } = setup);
            return setup.init();
        });
        after(() => {
            setup.restore();
        });
        it("dispatch to proper decorators", () => {
            const wrapped = editor.guiRoot.querySelectorAll(`[${util_1.encodeAttrName("rend")}='wrap'].tei\\:p._real`);
            chai_1.expect(wrapped).to.have.length(2);
            function parentTest(el, msg, expected) {
                const parent = el.parentNode;
                chai_1.expect(parent.classList.contains("_gui_test"), msg).to.equal(expected);
            }
            parentTest(wrapped[0], "the first paragraph with rend='wrap' should be decorated by \
the test mode", true);
            parentTest(wrapped[1], "the second paragraph with rend='wrap' should not be decorated \
by the test mode", false);
        });
        it("present a contextual menu showing mode-specific actions", () => {
            function check(el, custom) {
                chai_1.expect(el).to.not.be.null;
                wed_test_util_1.activateContextMenu(editor, el);
                wed_test_util_1.contextMenuHasOption(editor, /^Test draggable$/, custom ? 1 : 0);
                editor.editingMenuManager.dismiss();
            }
            const first = editor.guiRoot.querySelector(".tei\\:sourceDesc._real>.tei\\:p._real");
            check(first, true);
            const second = editor.guiRoot.querySelector(".tei\\:body._real>.tei\\:p._real");
            check(second, false);
        });
        it("present mode-specific completions", () => {
            function check(el, custom) {
                chai_1.expect(el).to.not.be.null;
                const attrVals = wed_test_util_1.getAttributeValuesFor(el);
                editor.caretManager.setCaret(attrVals[0].firstChild, 0);
                // This is an arbitrary menu item we check for.
                if (custom) {
                    wed_test_util_1.contextMenuHasOption(editor, /^completion1$/);
                }
                else {
                    const menu = editor.window.document
                        .getElementsByClassName("wed-context-menu")[0];
                    chai_1.expect(menu).to.be.undefined;
                }
            }
            const first = editor.guiRoot.querySelector(".tei\\:sourceDesc._real>.tei\\:p._real");
            check(first, true);
            const second = editor.guiRoot.querySelectorAll(".tei\\:body._real>.tei\\:p._real")[13];
            check(second, false);
        });
        it("adds mode-specific toolbar buttons", () => {
            function check(el, expected) {
                if (el !== null) {
                    editor.caretManager.setCaret(el, 0);
                }
                const span = editor.toolbar.top.lastElementChild;
                chai_1.expect(span.children).to.have.lengthOf(expected);
            }
            // Initially we are out and so no mode-specific button.
            check(null, 0);
            // Move into the submode, and check again.
            const inSubmode = editor.guiRoot.querySelector(".tei\\:sourceDesc._real>.tei\\:p._real");
            check(inSubmode, 1);
            // Move out, and check again.
            const outsideSubmode = editor.guiRoot.querySelectorAll(".tei\\:body._real>.tei\\:p._real")[13];
            check(outsideSubmode, 0);
        });
    });
});
//# sourceMappingURL=wed-submode-test.js.map