<commit_before>describe("chorus.views.base", function() {
    describe("initialize", function() {
        describe("resourcesLoaded", function() {
            context("when the resources are already loaded", function() {
                beforeEach(function() {
                    this.model = new chorus.models.Base();
                    this.model.loaded = true;
                    spyOn(chorus.views.Base.prototype, 'resourcesLoaded');
                    this.view = new chorus.views.Base({requiredResources: [this.model]});
                });

                it("calls resourcesLoaded during initialization", function() {
                    expect(this.view.resourcesLoaded).toHaveBeenCalled();
                });
            });

            context("when the resources are not loaded", function() {
                beforeEach(function() {
                    this.model = new chorus.models.Base();
                    this.model.loaded = false;
                    spyOn(this.model, 'url').andReturn('/foo/bar');
                    spyOn(chorus.views.Base.prototype, 'resourcesLoaded');
                    spyOn(chorus.views.Base.prototype, 'render');
                    this.view = new chorus.views.Base({requiredResources: [this.model]});
                    this.model.fetch();
                });

                it("does not call resourcesLoaded during initialization", function() {
                    expect(this.view.resourcesLoaded).not.toHaveBeenCalled();
                });

                describe("once it has been loaded", function() {
                    beforeEach(function() {
                        this.server.completeFetchFor(this.model);
                    });

                    it("calls resourcesLoaded after model has been loaded", function() {
                        expect(this.view.resourcesLoaded).toHaveBeenCalled();
                    });

                    it("calls render", function() {
                        expect(this.view.render).toHaveBeenCalled();
                    });
                });

            });
        });
    });

    describe("event bindings", function() {
        beforeEach(function() {
            this.model = new chorus.models.Base();
        });

        describe("with persistent falsy", function() {
            beforeEach(function() {
                this.view = new chorus.views.Base({model : this.model});
                spyOn(this.view, 'template').andReturn("");
                // render is bound on the view object before we can spy on it.
                spyOn(this.view, "preRender");
            })

            _.each(["reset", "add", "remove", "change"], function(evt) {
                it("re-renders on the " + evt + " event", function() {
                    this.view.resource.trigger(evt);
                    expect(this.view.preRender).toHaveBeenCalled();
                });
            });
        })

        describe("with persistent:true", function() {
            beforeEach(function() {
                chorus.views.Base.prototype.persistent = true
                this.view = new chorus.views.Base({model : this.model});
                spyOn(this.view, 'template').andReturn("");
                // render is bound on the view object before we can spy on it.
                spyOn(this.view, "preRender");
            });
            afterEach(function() {
                delete chorus.views.Base.prototype.persistent;
            });

            _.each(["reset", "add", "remove", "change"], function(evt) {
                it("re-renders on the " + evt + " event", function() {
                    this.view.resource.trigger(evt);
                    expect(this.view.preRender).not.toHaveBeenCalled();
                });
            });
        });
    });

    describe("hotkey bindings", function() {
        beforeEach(function() {
            this.oldHotKeyMeta = chorus.hotKeyMeta;
            chorus.hotKeyMeta = 'ctrl';

            chorus.views.HotKeyTest = chorus.views.Base.extend({
                hotkeys : {
                    'r' : 'my:event'
                }
            })

            spyOn($.fn, "bind").andCallThrough();
            this.view = new chorus.views.HotKeyTest();
        })

        afterEach(function() {
            chorus.hotKeyMeta = this.oldHotKeyMeta;
        })

        it("binds hotkeys", function() {
            expect($.fn.bind).toHaveBeenCalledWith("keydown", "ctrl+r", jasmine.any(Function));
            expect($.fn.bind.mostRecentCall.object).toBe($(document))
        })

        it("triggers events on hotkeys", function() {
            spyOnEvent(this.view, "my:event");
            var ev = $.Event("keydown", { which : 82, ctrlKey : true })
            $(document).trigger(ev);
            expect("my:event").toHaveBeenTriggeredOn(this.view);
        })
    })
    describe("#context", function() {<commit_msg>Fix spec failure on Firefox<commit_after>describe("chorus.views.base", function() {
    describe("initialize", function() {
        describe("resourcesLoaded", function() {
            context("when the resources are already loaded", function() {
                beforeEach(function() {
                    this.model = new chorus.models.Base();
                    this.model.loaded = true;
                    spyOn(chorus.views.Base.prototype, 'resourcesLoaded');
                    this.view = new chorus.views.Base({requiredResources: [this.model]});
                });

                it("calls resourcesLoaded during initialization", function() {
                    expect(this.view.resourcesLoaded).toHaveBeenCalled();
                });
            });

            context("when the resources are not loaded", function() {
                beforeEach(function() {
                    this.model = new chorus.models.Base();
                    this.model.loaded = false;
                    spyOn(this.model, 'url').andReturn('/foo/bar');
                    spyOn(chorus.views.Base.prototype, 'resourcesLoaded');
                    spyOn(chorus.views.Base.prototype, 'render');
                    this.view = new chorus.views.Base({requiredResources: [this.model]});
                    this.model.fetch();
                });

                it("does not call resourcesLoaded during initialization", function() {
                    expect(this.view.resourcesLoaded).not.toHaveBeenCalled();
                });

                describe("once it has been loaded", function() {
                    beforeEach(function() {
                        this.server.completeFetchFor(this.model);
                    });

                    it("calls resourcesLoaded after model has been loaded", function() {
                        expect(this.view.resourcesLoaded).toHaveBeenCalled();
                    });

                    it("calls render", function() {
                        expect(this.view.render).toHaveBeenCalled();
                    });
                });

            });
        });
    });

    describe("event bindings", function() {
        beforeEach(function() {
            this.model = new chorus.models.Base();
        });

        describe("with persistent falsy", function() {
            beforeEach(function() {
                this.view = new chorus.views.Base({model : this.model});
                spyOn(this.view, 'template').andReturn("");
                // render is bound on the view object before we can spy on it.
                spyOn(this.view, "preRender");
            })

            _.each(["reset", "add", "remove", "change"], function(evt) {
                it("re-renders on the " + evt + " event", function() {
                    this.view.resource.trigger(evt);
                    expect(this.view.preRender).toHaveBeenCalled();
                });
            });
        })

        describe("with persistent:true", function() {
            beforeEach(function() {
                chorus.views.Base.prototype.persistent = true
                this.view = new chorus.views.Base({model : this.model});
                spyOn(this.view, 'template').andReturn("");
                // render is bound on the view object before we can spy on it.
                spyOn(this.view, "preRender");
            });
            afterEach(function() {
                delete chorus.views.Base.prototype.persistent;
            });

            _.each(["reset", "add", "remove", "change"], function(evt) {
                it("re-renders on the " + evt + " event", function() {
                    this.view.resource.trigger(evt);
                    expect(this.view.preRender).not.toHaveBeenCalled();
                });
            });
        });
    });

    describe("hotkey bindings", function() {
        beforeEach(function() {
            this.oldHotKeyMeta = chorus.hotKeyMeta;
            chorus.hotKeyMeta = 'ctrl';

            chorus.views.HotKeyTest = chorus.views.Base.extend({
                hotkeys : {
                    'r' : 'my:event'
                }
            })

            spyOn($.fn, "bind").andCallThrough();
            this.view = new chorus.views.HotKeyTest();
        })

        afterEach(function() {
            chorus.hotKeyMeta = this.oldHotKeyMeta;
        })

        it("binds hotkeys", function() {
            expect($.fn.bind).toHaveBeenCalledWith("keydown", "ctrl+r", jasmine.any(Function));
        })

        it("triggers events on hotkeys", function() {
            spyOnEvent(this.view, "my:event");
            var ev = $.Event("keydown", { which : 82, ctrlKey : true })
            $(document).trigger(ev);
            expect("my:event").toHaveBeenTriggeredOn(this.view);
        })
    })
    describe("#context", function() {
{'fraction_non_alphanumeric': 0.1355601233299075, 'fraction_numerical': 0.00041109969167523125, 'mean_word_length': 1.5440522875816993, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4875205', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2362, 'n_words': 441}