var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
define(["require", "exports", "chai", "sinon", "wed/editor-actions", "wed/gui/toolbar"], function (require, exports, chai_1, sinon, editorActions, toolbar_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    sinon = __importStar(sinon);
    editorActions = __importStar(editorActions);
    // tslint:disable-next-line:max-line-length
    // tslint:disable-next-line:mocha-no-side-effect-code no-object-literal-type-assertion
    const fakeEditor = {
        // tslint:disable-next-line:no-empty
        undo: () => { },
        // tslint:disable-next-line:no-empty
        redo: () => { },
    };
    describe("Toolbar", () => {
        let toolbar;
        let sandbox;
        beforeEach(() => {
            toolbar = new toolbar_1.Toolbar();
            sandbox = sinon.createSandbox();
        });
        afterEach(() => {
            sandbox.restore();
        });
        function checkCustomButtons(num) {
            chai_1.expect(toolbar.top.childNodes).to.have.lengthOf(num + 2);
        }
        function checkModeButtons(num) {
            // tslint:disable-next-line:no-any
            chai_1.expect(toolbar.modeSpan.childNodes).to.have.lengthOf(num);
        }
        describe("#addButton", () => {
            it("takes a single button", () => {
                checkCustomButtons(0);
                const button = new editorActions.Undo(fakeEditor).makeButton();
                toolbar.addButton(button);
                checkCustomButtons(1);
            });
            it("takes an array", () => {
                checkCustomButtons(0);
                const button = new editorActions.Undo(fakeEditor).makeButton();
                const button2 = new editorActions.Redo(fakeEditor).makeButton();
                toolbar.addButton([button, button2]);
                checkCustomButtons(2);
            });
            it("appends by default", () => {
                const button = new editorActions.Undo(fakeEditor).makeButton();
                toolbar.addButton(button);
                const button2 = new editorActions.Redo(fakeEditor).makeButton();
                toolbar.addButton(button2);
                // Clicking the 2nd child executes the child that was added last.
                const spy = sandbox.spy(fakeEditor, "redo");
                toolbar.top.children[1].click();
                chai_1.expect(spy).to.have.been.calledOnce;
            });
            it("can prepend", () => {
                const button = new editorActions.Undo(fakeEditor).makeButton();
                toolbar.addButton(button);
                const button2 = new editorActions.Redo(fakeEditor).makeButton();
                toolbar.addButton(button2, { prepend: true });
                // Clicking the 1st child executes the child that was added last.
                const spy = sandbox.spy(fakeEditor, "redo");
                toolbar.top.firstElementChild.click();
                chai_1.expect(spy).to.have.been.calledOnce;
            });
            it("refuses to allow right and prepend at the same time", () => {
                const button = new editorActions.Undo(fakeEditor).makeButton();
                chai_1.expect(() => {
                    toolbar.addButton(button, { prepend: true, right: true });
                }).to.throw(Error, /^cannot use prepend and right at the same time/);
            });
            it("allows pushing right", () => {
                const button = new editorActions.Undo(fakeEditor).makeButton();
                toolbar.addButton(button, { right: true });
                chai_1.expect(toolbar.top.lastElementChild.classList
                    .contains("pull-right")).to.be.true;
            });
        });
        describe("#setModeButtons", () => {
            it("takes buttons", () => {
                checkCustomButtons(0);
                checkModeButtons(0);
                const button = new editorActions.Undo(fakeEditor).makeButton();
                const button2 = new editorActions.Undo(fakeEditor).makeButton();
                toolbar.setModeButtons([button, button2]);
                checkCustomButtons(0);
                checkModeButtons(2);
            });
            it("replaces buttons", () => {
                checkCustomButtons(0);
                checkModeButtons(0);
                const button = new editorActions.Undo(fakeEditor).makeButton();
                const button2 = new editorActions.Undo(fakeEditor).makeButton();
                toolbar.setModeButtons([button, button2]);
                checkCustomButtons(0);
                checkModeButtons(2);
                toolbar.setModeButtons([]);
                checkCustomButtons(0);
                checkModeButtons(0);
            });
        });
    });
});
//# sourceMappingURL=toolbar-test.js.map