<commit_before>/* globals describe, before, after, beforeEach, $fixture, qq, assert, it, qqtest, helpme, purl, Q */
if (qqtest.canDownloadFileAsBlob) {
    describe("autoUpload = false tests for validation, submission, and cancel features", function() {
        "use strict";

        var oldWrapCallbacks,
            testImgKey = "up.jpg",
            testImgType = "image/jpeg",
            testBlob;

        before(function() {
            oldWrapCallbacks = qq.FineUploaderBasic.prototype._wrapCallbacks;

            // "Turn off" wrapping of callbacks that squelches errors.  We need AssertionErrors in callbacks to bubble.
            qq.FineUploaderBasic.prototype._wrapCallbacks = function() {};
        });

        after(function() {
            qq.FineUploaderBasic.prototype._wrapCallbacks = oldWrapCallbacks;
        });

        it("handles a simple blob submission correctly (autoUpload = false)", function(done) {
            var uploader = new qq.FineUploaderBasic({
                autoUpload: false,
                callbacks: {
                    onSubmit: function(id, name) {
                        callbackOrder.push("submit");
                        assert.equal(id, 0);
                        assert.equal(name, expectedName);
                    },
                    onSubmitted: function(id, name) {
                        callbackOrder.push("submitted");
                        assert.equal(id, 0);
                        assert.equal(name, expectedName);
                    },
                    onValidate: function(blobData) {
                        callbackOrder.push("validate");
                        assert.equal(blobData.name, expectedName);
                        assert.equal(blobData.size, expectedFileSize);
                    },
                    onValidateBatch: function(blobDataArray) {
                        callbackOrder.push("validateBatch");
                        assert.equal(blobDataArray.length, 1);
                        assert.equal(blobDataArray[0].name, expectedName);
                        assert.equal(blobDataArray[0].size, expectedFileSize);
                    },
                    onStatusChange: function(id, oldStatus, newStatus) {
                        assert.equal(id, 0);
                        statusChangeOrder.push(newStatus);
                    }
                }
            }),
                callbackOrder = [],
                statusChangeOrder = [],
                expectedFileSize = 3266,
                expectedName = "testname",
                expectedCallbackOrder = ["validateBatch", "validate", "submit", "submitted"],
                expectedStatusChangeOrder = [qq.status.SUBMITTING, qq.status.SUBMITTED];

            qqtest.downloadFileAsBlob(testImgKey, testImgType).then(function(blob) {
                uploader.addBlobs({blob: blob, name: expectedName});

                assert.deepEqual(callbackOrder, expectedCallbackOrder);
                assert.deepEqual(statusChangeOrder, expectedStatusChangeOrder);
                assert.equal(uploader.getName(0), expectedName);
                assert.equal(uploader.getNetUploads(), 0);
                assert.equal(uploader.getSize(0), expectedFileSize);
                assert.equal(uploader.getUploads().length, 1);
                assert.equal(uploader.getUploads({id: 0}).name, expectedName);
                assert.equal(uploader.getUploads({id: 0}).originalName, expectedName);
                assert.equal(uploader.getUploads({id: 0}).size, expectedFileSize);
                assert.equal(uploader.getUploads({id: 0}).status, qq.status.SUBMITTED);

                done();
            });
        });

        it("only ever passes name and size to onValidate callbacks", function(done) {
            var uploader = new qq.FineUploaderBasic({
                callbacks: {
                    onValidate: function(blobData, button) {
                        assert.ok(blobData.name);
                        assert.ok(blobData.size);
                        assert.equal(undefined, blobData.foo);
                        qq.log(button);
                        assert.ok(button);
                    }
                }
            });

            qqtest.downloadFileAsBlob(testImgKey, testImgType).then(function(blob) {
                blob.foo = "bar";

                uploader.addBlobs([
                    {blob: blob, name: "name1"},
                    {blob: blob, name: "name2"}
                ]);
                done();
            });
        });

        describe("file rejection via callback", function() {
            function setupUploader(callback, blob, done, useQ) {
                var uploader = new qq.FineUploaderBasic({
                    autoUpload: false,
                    callbacks: (function() {
                        var callbacks = {},
                            callbackName = "on" + callback.charAt(0).toUpperCase() + callback.substr(1);

                        if (done) {
                            callbacks[callbackName] = function() {
                                if (useQ) {
                                    return Q.Promise(function(resolve, reject) {<commit_msg>chore($logging): remove log stmt in test #1261<commit_after>/* globals describe, before, after, beforeEach, $fixture, qq, assert, it, qqtest, helpme, purl, Q */
if (qqtest.canDownloadFileAsBlob) {
    describe("autoUpload = false tests for validation, submission, and cancel features", function() {
        "use strict";

        var oldWrapCallbacks,
            testImgKey = "up.jpg",
            testImgType = "image/jpeg",
            testBlob;

        before(function() {
            oldWrapCallbacks = qq.FineUploaderBasic.prototype._wrapCallbacks;

            // "Turn off" wrapping of callbacks that squelches errors.  We need AssertionErrors in callbacks to bubble.
            qq.FineUploaderBasic.prototype._wrapCallbacks = function() {};
        });

        after(function() {
            qq.FineUploaderBasic.prototype._wrapCallbacks = oldWrapCallbacks;
        });

        it("handles a simple blob submission correctly (autoUpload = false)", function(done) {
            var uploader = new qq.FineUploaderBasic({
                autoUpload: false,
                callbacks: {
                    onSubmit: function(id, name) {
                        callbackOrder.push("submit");
                        assert.equal(id, 0);
                        assert.equal(name, expectedName);
                    },
                    onSubmitted: function(id, name) {
                        callbackOrder.push("submitted");
                        assert.equal(id, 0);
                        assert.equal(name, expectedName);
                    },
                    onValidate: function(blobData) {
                        callbackOrder.push("validate");
                        assert.equal(blobData.name, expectedName);
                        assert.equal(blobData.size, expectedFileSize);
                    },
                    onValidateBatch: function(blobDataArray) {
                        callbackOrder.push("validateBatch");
                        assert.equal(blobDataArray.length, 1);
                        assert.equal(blobDataArray[0].name, expectedName);
                        assert.equal(blobDataArray[0].size, expectedFileSize);
                    },
                    onStatusChange: function(id, oldStatus, newStatus) {
                        assert.equal(id, 0);
                        statusChangeOrder.push(newStatus);
                    }
                }
            }),
                callbackOrder = [],
                statusChangeOrder = [],
                expectedFileSize = 3266,
                expectedName = "testname",
                expectedCallbackOrder = ["validateBatch", "validate", "submit", "submitted"],
                expectedStatusChangeOrder = [qq.status.SUBMITTING, qq.status.SUBMITTED];

            qqtest.downloadFileAsBlob(testImgKey, testImgType).then(function(blob) {
                uploader.addBlobs({blob: blob, name: expectedName});

                assert.deepEqual(callbackOrder, expectedCallbackOrder);
                assert.deepEqual(statusChangeOrder, expectedStatusChangeOrder);
                assert.equal(uploader.getName(0), expectedName);
                assert.equal(uploader.getNetUploads(), 0);
                assert.equal(uploader.getSize(0), expectedFileSize);
                assert.equal(uploader.getUploads().length, 1);
                assert.equal(uploader.getUploads({id: 0}).name, expectedName);
                assert.equal(uploader.getUploads({id: 0}).originalName, expectedName);
                assert.equal(uploader.getUploads({id: 0}).size, expectedFileSize);
                assert.equal(uploader.getUploads({id: 0}).status, qq.status.SUBMITTED);

                done();
            });
        });

        it("only ever passes name and size to onValidate callbacks", function(done) {
            var uploader = new qq.FineUploaderBasic({
                callbacks: {
                    onValidate: function(blobData, button) {
                        assert.ok(blobData.name);
                        assert.ok(blobData.size);
                        assert.equal(undefined, blobData.foo);
                        assert.ok(button);
                    }
                }
            });

            qqtest.downloadFileAsBlob(testImgKey, testImgType).then(function(blob) {
                blob.foo = "bar";

                uploader.addBlobs([
                    {blob: blob, name: "name1"},
                    {blob: blob, name: "name2"}
                ]);
                done();
            });
        });

        describe("file rejection via callback", function() {
            function setupUploader(callback, blob, done, useQ) {
                var uploader = new qq.FineUploaderBasic({
                    autoUpload: false,
                    callbacks: (function() {
                        var callbacks = {},
                            callbackName = "on" + callback.charAt(0).toUpperCase() + callback.substr(1);

                        if (done) {
                            callbacks[callbackName] = function() {
                                if (useQ) {
                                    return Q.Promise(function(resolve, reject) {
{'fraction_non_alphanumeric': 0.10381987876455306, 'fraction_numerical': 0.004618493216588088, 'mean_word_length': 1.4824456651540483, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2346911', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2417, 'n_words': 463}