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", "sinon", "wed/gui/typeahead-popup"], function (require, exports, sinon, typeahead_popup_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    sinon = __importStar(sinon);
    const assert = chai.assert;
    function substringMatcher(strs) {
        return function findMatches(q, cb) {
            const re = new RegExp(q, "i");
            const matches = [];
            for (const str of strs) {
                if (re.test(str)) {
                    matches.push({ value: str });
                }
            }
            cb(matches);
        };
    }
    const testData = [];
    for (let i = 0; i < 100; ++i) {
        testData.push(`Test ${i}`);
    }
    describe("TypeaheadPopup", () => {
        let ta;
        let cb;
        beforeEach(() => {
            cb = sinon.spy();
            ta = new typeahead_popup_1.TypeaheadPopup(window.document, 0, 0, 300, "Placeholder", {
                options: {
                    autoselect: true,
                    hint: true,
                    highlight: true,
                    minLength: 1,
                },
                datasets: [{
                        source: substringMatcher(testData),
                    }],
            }, cb);
        });
        afterEach(() => {
            if (ta !== undefined) {
                ta.dismiss();
            }
        });
        describe("setValue", () => {
            it("sets the value", () => {
                const ttInput = document.getElementsByClassName("tt-input")[0];
                assert.notEqual(ttInput.value, "foo");
                ta.setValue("foo");
                assert.equal(ttInput.value, "foo");
            });
        });
        describe("hideSpinner", () => {
            it("hides the spinner", () => {
                const spinner = document.querySelector(".wed-typeahead-popup .spinner");
                assert.notEqual(spinner.style.display, "none");
                ta.hideSpinner();
                assert.equal(spinner.style.display, "none");
            });
        });
        describe("dismiss", () => {
            it("calls the callback without a value if no value is given", () => {
                ta.dismiss();
                assert.isTrue(cb.calledWith(undefined));
            });
            it("calls the callback with the value passed", () => {
                ta.dismiss(testData[0]);
                assert.isTrue(cb.calledWith(testData[0]));
            });
            it("calls the callback with the value passed", () => {
                ta.dismiss(testData[0]);
                assert.isTrue(cb.calledWith(testData[0]));
            });
            it("calls the callback only once", () => {
                ta.dismiss();
                ta.dismiss();
                assert.isTrue(cb.calledOnce);
            });
        });
    });
});
//# sourceMappingURL=typeahead-popup-test.js.map