<commit_before>﻿
describe("OnLocal/RemoteChange", function() {
    beforeEach(function() {
        jasmine.Ajax.install();
        // stub initial HTTP request
        jasmine.Ajax.stubRequest(window.location.href).andReturn(TestResponses.defaultInit.success);
    });

    afterEach(function() {
        this.puppet.unobserve();
        jasmine.Ajax.uninstall();
    });

    beforeEach(function() {
        jasmine.WebSocket.install();
    });
    afterEach(function() {
        jasmine.WebSocket.uninstall();
    });
    it("should call onLocalChange callback for outgoing patches", function(done) {
        var sentSpy = jasmine.createSpy("onLocalChange");

        var puppet = this.puppet = new Puppet({
            useWebSocket: true,
            onLocalChange: sentSpy
        });
        var websocket = jasmine.WebSocket.spy.calls.mostRecent().returnValue;
        //open WS for changes
        websocket.open();
        this.puppet.obj.hello = "onLocalChange callback";

        // wait for observer and mocked initial HTTP response
        setTimeout(function() {
            expect(puppet.obj.hello).toEqual("onLocalChange callback");
            expect(sentSpy.calls.mostRecent().args[0]).toEqual([{
                "op": "replace",
                "path": "/hello",
                "value": "onLocalChange callback"
            }]);
            done();
        }, 100); // for FF
    });

    it("should call onRemoteChange callback for applied patches", function(done) {
        var receivedSpy = jasmine.createSpy("onRemoteChange");

        var puppet = this.puppet = new Puppet({
            useWebSocket: true,
            onRemoteChange: receivedSpy
        });
        var websocket = jasmine.WebSocket.spy.calls.mostRecent().returnValue;
        //open WS for changes
        websocket.open();
        websocket.onmessage({
            data: '[{"op":"replace","path":"/hello","value":"onRemoteChange callback"}]'
        });

        // wait for observer and mocked initial HTTP response
        setTimeout(function() {
            expect(puppet.obj.hello).toEqual("onRemoteChange callback");
            var mostRecentCall = receivedSpy.calls.mostRecent();
            expect(mostRecentCall.args[0]).toEqual([{
                "op": "replace",
                "path": "/hello",
                "value": "onRemoteChange callback"
            }]);
            expect(mostRecentCall.args[1]).toEqual([{removed: 'world'}]);
            done();
        }, 100); // for FF
    });

    it("should fire patch-applied event for applied patches", function(done) {
        var receivedSpy = jasmine.createSpy("patch-applied");

        var puppet = this.puppet = new Puppet({
            useWebSocket: true
        });
        puppet.addEventListener('patch-applied', receivedSpy);
        var websocket = jasmine.WebSocket.spy.calls.mostRecent().returnValue;
        //open WS for changes
        websocket.open();
        websocket.onmessage({
            data: '[{"op":"replace","path":"/hello","value":"patch-applied"}]'
        });

        // wait for observer and mocked initial HTTP response
        setTimeout(function() {
            var detail = receivedSpy.calls.mostRecent().args[0].detail;
            expect(detail.patches).toEqual([{
                "op": "replace",
                "path": "/hello",
                "value": "patch-applied"
            }]);
            expect(detail.results).toEqual([{removed: 'world'}]);
            done();
        }, 100); // for FF
    });
});<commit_msg>Fix test for simple return values of jsonpatch.apply<commit_after>﻿
describe("OnLocal/RemoteChange", function() {
    beforeEach(function() {
        jasmine.Ajax.install();
        // stub initial HTTP request
        jasmine.Ajax.stubRequest(window.location.href).andReturn(TestResponses.defaultInit.success);
    });

    afterEach(function() {
        this.puppet.unobserve();
        jasmine.Ajax.uninstall();
    });

    beforeEach(function() {
        jasmine.WebSocket.install();
    });
    afterEach(function() {
        jasmine.WebSocket.uninstall();
    });
    it("should call onLocalChange callback for outgoing patches", function(done) {
        var sentSpy = jasmine.createSpy("onLocalChange");

        var puppet = this.puppet = new Puppet({
            useWebSocket: true,
            onLocalChange: sentSpy
        });
        var websocket = jasmine.WebSocket.spy.calls.mostRecent().returnValue;
        //open WS for changes
        websocket.open();
        this.puppet.obj.hello = "onLocalChange callback";

        // wait for observer and mocked initial HTTP response
        setTimeout(function() {
            expect(puppet.obj.hello).toEqual("onLocalChange callback");
            expect(sentSpy.calls.mostRecent().args[0]).toEqual([{
                "op": "replace",
                "path": "/hello",
                "value": "onLocalChange callback"
            }]);
            done();
        }, 100); // for FF
    });

    it("should call onRemoteChange callback for applied patches", function(done) {
        var receivedSpy = jasmine.createSpy("onRemoteChange");

        var puppet = this.puppet = new Puppet({
            useWebSocket: true,
            onRemoteChange: receivedSpy
        });
        var websocket = jasmine.WebSocket.spy.calls.mostRecent().returnValue;
        //open WS for changes
        websocket.open();
        websocket.onmessage({
            data: '[{"op":"replace","path":"/hello","value":"onRemoteChange callback"}]'
        });

        // wait for observer and mocked initial HTTP response
        setTimeout(function() {
            expect(puppet.obj.hello).toEqual("onRemoteChange callback");
            var mostRecentCall = receivedSpy.calls.mostRecent();
            expect(mostRecentCall.args[0]).toEqual([{
                "op": "replace",
                "path": "/hello",
                "value": "onRemoteChange callback"
            }]);
            expect(mostRecentCall.args[1]).toEqual(['world']);
            done();
        }, 100); // for FF
    });

    it("should fire patch-applied event for applied patches", function(done) {
        var receivedSpy = jasmine.createSpy("patch-applied");

        var puppet = this.puppet = new Puppet({
            useWebSocket: true
        });
        puppet.addEventListener('patch-applied', receivedSpy);
        var websocket = jasmine.WebSocket.spy.calls.mostRecent().returnValue;
        //open WS for changes
        websocket.open();
        websocket.onmessage({
            data: '[{"op":"replace","path":"/hello","value":"patch-applied"}]'
        });

        // wait for observer and mocked initial HTTP response
        setTimeout(function() {
            var detail = receivedSpy.calls.mostRecent().args[0].detail;
            expect(detail.patches).toEqual([{
                "op": "replace",
                "path": "/hello",
                "value": "patch-applied"
            }]);
            expect(detail.results).toEqual(['world']);
            done();
        }, 100); // for FF
    });
});
{'fraction_non_alphanumeric': 0.13966322343285695, 'fraction_numerical': 0.003679071741898967, 'mean_word_length': 2.106813186813187, 'pattern_counts': {'":': 30, '<': 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': '3088356', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1900, 'n_words': 379}