<commit_before>define(["pat-tooltip", "pat-inject"], function(pattern, inject) {
    var utils = {
        createTooltip: function(c) {
            var cfg = c || {};
            return $("<a/>", {
                "id":   cfg.id || "tooltip",
                "href": cfg.href || "#anchor",
                "title": cfg.title || "tooltip title attribute",
                "data-pat-tooltip": "" || cfg.data,
                "class": "pat-tooltip"
            }).appendTo($("div#lab"));
        },

        removeTooltip: function removeTooltip() {
            var $el = $("a#tooltip");
            $el.remove();
        },

        createTooltipSource: function() {
            return $("<span style='display: none' id='tooltip-source'>"+
                    "<stong>Local content</strong></span>")
                .appendTo($("div#lab"));
        },

        click: {
            type: "click",
            preventDefault: function () {}
        }
    };

    describe("pat-tooltip", function () {
        beforeEach(function() {
            $("<div/>", {id: "lab"}).appendTo(document.body);
        });

        afterEach(function() {
            $("#lab").remove();
        });

        describe("A Tooltip", function () {

            it("will be closed when a form with class .close-panel is submitted", function () {
                runs(function () {
                    var $div = $("<div/>", {id: "content"});
                    var $form = $("<form/>", {"class": "close-panel"});
                    $div.appendTo(document.body);
                    $form.appendTo($div[0]);
                    utils.createTooltip({
                        data: "source: content",
                        href: "#content"
                    });
                    var $el = $("a#tooltip");
                    spyOn(pattern, "show").andCallThrough();
                    spyOn(pattern, "hide").andCallThrough();
                    pattern.init($el);
                    $el.trigger(utils.click);
                    expect(pattern.show).toHaveBeenCalled();
                });
                waits(100); // hide events get registered 50 ms after show
                runs(function () {
                    $(document).on("submit", function (ev) { ev.preventDefault(); });
                    $("form.close-panel").submit();
                    expect(pattern.hide).toHaveBeenCalled();
                    $("div#content").remove();
                });
            });

            it("will NOT be closed when a form WITHOUT class .close-panel is submitted", function () {
                runs(function () {
                    var $div = $("<div/>", {id: "content"});
                    var $form = $("<form/>");
                    $div.appendTo(document.body);
                    $form.appendTo($div[0]);
                    utils.createTooltip({
                        data: "source: content",
                        href: "#content"
                    });
                    var $el = $("a#tooltip");
                    spyOn(pattern, "show").andCallThrough();
                    spyOn(pattern, "hide").andCallThrough();
                    pattern.init($el);
                    $el.trigger(utils.click);
                    expect(pattern.show).toHaveBeenCalled();
                });
                waits(100); // hide events get registered 50 ms after show
                runs(function () {
                    $(document).on("submit", function (ev) { ev.preventDefault(); });
                    $("#content form").submit();
                    expect(pattern.hide).not.toHaveBeenCalled();
                    $("div#content").remove();
                });
            });

            it("gets a .close-panel element when closing=close-button", function () {
                utils.createTooltip({
                    data: "closing: close-button",
                    href: "/tests/content.html#content"
                });
                var $el = $("a#tooltip");
                pattern.init($el);
                $el.trigger(utils.click);
                expect($(".close-panel").length).toBeTruthy();
            });

            it("is closed when one clicks on a .close-panel element", function () {
                runs(function () {
                    utils.createTooltip({
                        data: "trigger: click; closing: close-button",
                        href: "/tests/content.html#content"
                    });
                    spyOn(pattern, "show").andCallThrough();
                    spyOn(pattern, "hide").andCallThrough();
                    var $el = $("a#tooltip");
                    pattern.init($el);
                    $el.trigger(utils.click);
                    expect(pattern.show).toHaveBeenCalled();
                });
                waits(100); // hide events get registered 50 ms after show
                runs(function () {
                    $(".close-panel").click();
                    expect(pattern.hide).toHaveBeenCalled();
                });
            });

            it("is NOT closed when an injection happens", function () {
                    runs(function () {
                        utils.createTooltip({
                            data: "trigger: click; closing: auto",
                            href: "/tests/content.html#content"
                        });
                        var $el = $("a#tooltip");
                        spyOn(pattern, "show").andCallThrough();
                        spyOn(pattern, "hide").andCallThrough();
                        pattern.init($el);
                        $el.trigger(utils.click);
                        expect(pattern.show).toHaveBeenCalled();
                    });
                    waits(100); // hide events get registered 50 ms after show
                    runs(function () {
                        var $el = $("a#tooltip");
                        var $container = $el.data("patterns.tooltip.container");
                        $container.trigger("patterns-inject-triggered");
                        expect(pattern.hide).not.toHaveBeenCalled();
                    });
            });
        });<commit_msg>Add a wait statement to fix heisenbug in browser.<commit_after>define(["pat-tooltip", "pat-inject"], function(pattern, inject) {
    var utils = {
        createTooltip: function(c) {
            var cfg = c || {};
            return $("<a/>", {
                "id":   cfg.id || "tooltip",
                "href": cfg.href || "#anchor",
                "title": cfg.title || "tooltip title attribute",
                "data-pat-tooltip": "" || cfg.data,
                "class": "pat-tooltip"
            }).appendTo($("div#lab"));
        },

        removeTooltip: function removeTooltip() {
            var $el = $("a#tooltip");
            $el.remove();
        },

        createTooltipSource: function() {
            return $("<span style='display: none' id='tooltip-source'>"+
                    "<stong>Local content</strong></span>")
                .appendTo($("div#lab"));
        },

        click: {
            type: "click",
            preventDefault: function () {}
        }
    };

    describe("pat-tooltip", function () {
        beforeEach(function() {
            $("<div/>", {id: "lab"}).appendTo(document.body);
        });

        afterEach(function() {
            $("#lab").remove();
        });

        describe("A Tooltip", function () {

            it("will be closed when a form with class .close-panel is submitted", function () {
                runs(function () {
                    var $div = $("<div/>", {id: "content"});
                    var $form = $("<form/>", {"class": "close-panel"});
                    $div.appendTo(document.body);
                    $form.appendTo($div[0]);
                    utils.createTooltip({
                        data: "source: content",
                        href: "#content"
                    });
                    var $el = $("a#tooltip");
                    spyOn(pattern, "show").andCallThrough();
                    spyOn(pattern, "hide").andCallThrough();
                    pattern.init($el);
                    $el.trigger(utils.click);
                    expect(pattern.show).toHaveBeenCalled();
                });
                waits(100); // hide events get registered 50 ms after show
                runs(function () {
                    $(document).on("submit", function (ev) { ev.preventDefault(); });
                    $("form.close-panel").submit();
                    expect(pattern.hide).toHaveBeenCalled();
                    $("div#content").remove();
                });
            });

            it("will NOT be closed when a form WITHOUT class .close-panel is submitted", function () {
                runs(function () {
                    var $div = $("<div/>", {id: "content"});
                    var $form = $("<form/>");
                    $div.appendTo(document.body);
                    $form.appendTo($div[0]);
                    utils.createTooltip({
                        data: "source: content",
                        href: "#content"
                    });
                    var $el = $("a#tooltip");
                    spyOn(pattern, "show").andCallThrough();
                    spyOn(pattern, "hide").andCallThrough();
                    pattern.init($el);
                    $el.trigger(utils.click);
                    expect(pattern.show).toHaveBeenCalled();
                });
                waits(100); // hide events get registered 50 ms after show
                runs(function () {
                    $(document).on("submit", function (ev) { ev.preventDefault(); });
                    $("#content form").submit();
                    expect(pattern.hide).not.toHaveBeenCalled();
                    $("div#content").remove();
                });
            });

            it("gets a .close-panel element when closing=close-button", function () {
                utils.createTooltip({
                    data: "closing: close-button",
                    href: "/tests/content.html#content"
                });
                var $el = $("a#tooltip");
                pattern.init($el);
                $el.trigger(utils.click);
                expect($(".close-panel").length).toBeTruthy();
            });

            it("is closed when one clicks on a .close-panel element", function () {
                runs(function () {
                    utils.createTooltip({
                        data: "trigger: click; closing: close-button",
                        href: "/tests/content.html#content"
                    });
                    spyOn(pattern, "show").andCallThrough();
                    spyOn(pattern, "hide").andCallThrough();
                    var $el = $("a#tooltip");
                    pattern.init($el);
                    $el.trigger(utils.click);
                    expect(pattern.show).toHaveBeenCalled();
                });
                waits(100); // hide events get registered 50 ms after show
                runs(function () {
                    $(".close-panel").click();
                    expect(pattern.hide).toHaveBeenCalled();
                });
            });

            it("is NOT closed when an injection happens", function () {
                    runs(function () {
                        utils.createTooltip({
                            data: "trigger: click; closing: auto",
                            href: "/tests/content.html#content"
                        });
                        var $el = $("a#tooltip");
                        spyOn(pattern, "show").andCallThrough();
                        spyOn(pattern, "hide").andCallThrough();
                        pattern.init($el);
                        $el.trigger(utils.click);
                        expect(pattern.show).toHaveBeenCalled();
                    });
                    waits(100); // hide events get registered 50 ms after show
                    runs(function () {
                        var $el = $("a#tooltip");
                        var $container = $el.data("patterns.tooltip.container");
                        $container.trigger("patterns-inject-triggered");
                    });
                    waits(100); // hide events get registered 50 ms after show
                    runs(function () {
                        expect(pattern.hide).not.toHaveBeenCalled();
                    });
            });
        });
{'fraction_non_alphanumeric': 0.14701659221442245, 'fraction_numerical': 0.003908742820676452, 'mean_word_length': 1.201791359325606, 'pattern_counts': {'":': 12, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1432549', 'n_tokens_mistral': 3084, 'n_tokens_neox': 2883, 'n_words': 584}