<commit_before>casper.test.comment('Widget - Change picture');

/**
 * Open the change picture modal with assertions
 */
var verifyOpenChangePicture = function() {
    casper.waitForSelector('#me-clip-container .oae-clip-content > button', function() {
        casper.click('#me-clip-container .oae-clip-content > button');
        casper.test.assertExists('.oae-trigger-changepic', 'Change picture trigger exists');
        casper.click('.oae-trigger-changepic');
        casper.wait(1000, function() {
            casper.test.assertVisible('#changepic-modal', 'Change picture pane is showing after trigger');
            casper.click('#me-clip-container .oae-clip-content > button');
        });
    });
};

/**
 * Open the change picture modal without doing any assertions
 */
var openChangePicture = function() {
    casper.waitForSelector('#me-clip-container .oae-clip-content > button', function() {
        casper.click('#me-clip-container .oae-clip-content > button');
        casper.click('.oae-trigger-changepic');
        casper.wait(1000, function() {
            casper.click('#me-clip-container .oae-clip-content > button');
        });
    });
};

/**
 * Goes through the workflow of uploading and saving the user picture
 */
var verifyPictureUpload = function() {
	// Verify the upload form is present
	casper.test.assertExists('form#changepic-form', 'The change picture form is present');
	// Verify the no-image placeholder is present
	casper.test.assertSelectorHasText('.changepic-dropzone-content small', 'Drag a photo here to upload', 'Some help is shown to users that have no profile picture yet');
	// Upload an image
    casper.fill('form#changepic-form', {
        'file': 'tests/casperjs/data/balloons.jpg'
    }, false);
    casper.waitForSelector('.jcrop-holder', function() {
        // Verify the image is showing in the cropping area
        casper.test.assertExists('.jcrop-holder > img', 'The image is showing in the cropping area');
        // Verify the 'set picture' button is present
        casper.test.assertExists('#changepic-set', 'The \'Set picture\' button is present');
        // Click the button
        casper.click('#changepic-set');
        // Verify that setting the picture worked
        casper.waitForSelector('#oae-notification-container .alert', function() {
            casper.test.assertDoesntExist('#oae-notification-container .alert.alert-error', 'Picture successfully submitted and stored');
            casper.click('#oae-notification-container .close');
        });
    });
};

/**
 * Goes through the workflow of uploading and saving the user picture
 */
var verifyLargePictureValidation = function() {
    // Verify the upload form is present
    casper.test.assertExists('form#changepic-form', 'The change picture form is present');
    // Upload an image over 5 megabytes to trigger validation
    casper.fill('form#changepic-form', {
        'file': 'tests/casperjs/data/guitar.png'
    }, false);
    // Verify that the picture failed to be set
    casper.waitForSelector('#oae-notification-container .alert', function() {
        casper.test.assertExists('#oae-notification-container .alert.alert-error', 'Pictures over 5MB are rejected');
        casper.click('#oae-notification-container .close');
    });
};

casper.start('http://test.oae.com', function() {
    // Create a user to test changepicture with
    var user = null;
    userUtil().createUsers(1, function(users) {
        user = users[0];
    });

    // Login with that user
    casper.then(function() {
        userUtil().doLogIn(user.username, 'password');
    });

    // Open the changepicture modal
    casper.then(function() {
        casper.echo('Verify open change picture modal', 'INFO');
        verifyOpenChangePicture();
    });

    // Verify picture upload
    casper.then(function() {
        casper.echo('Verify picture upload', 'INFO');
        verifyPictureUpload();
    });

    // Verify picture upload validation
    casper.then(function() {
        casper.echo('Verify pictures over 10MB aren\'t accepted', 'INFO');
        casper.reload(function() {
            casper.then(openChangePicture);
            casper.then(verifyLargePictureValidation);
        });
    });

    // Log out at the end of the test
    casper.then(function() {
        userUtil().doLogOut();
    });
});

casper.run(function() {
    this.test.done();
});
<commit_msg>5MB -> 10MB description of test<commit_after>casper.test.comment('Widget - Change picture');

/**
 * Open the change picture modal with assertions
 */
var verifyOpenChangePicture = function() {
    casper.waitForSelector('#me-clip-container .oae-clip-content > button', function() {
        casper.click('#me-clip-container .oae-clip-content > button');
        casper.test.assertExists('.oae-trigger-changepic', 'Change picture trigger exists');
        casper.click('.oae-trigger-changepic');
        casper.wait(1000, function() {
            casper.test.assertVisible('#changepic-modal', 'Change picture pane is showing after trigger');
            casper.click('#me-clip-container .oae-clip-content > button');
        });
    });
};

/**
 * Open the change picture modal without doing any assertions
 */
var openChangePicture = function() {
    casper.waitForSelector('#me-clip-container .oae-clip-content > button', function() {
        casper.click('#me-clip-container .oae-clip-content > button');
        casper.click('.oae-trigger-changepic');
        casper.wait(1000, function() {
            casper.click('#me-clip-container .oae-clip-content > button');
        });
    });
};

/**
 * Goes through the workflow of uploading and saving the user picture
 */
var verifyPictureUpload = function() {
	// Verify the upload form is present
	casper.test.assertExists('form#changepic-form', 'The change picture form is present');
	// Verify the no-image placeholder is present
	casper.test.assertSelectorHasText('.changepic-dropzone-content small', 'Drag a photo here to upload', 'Some help is shown to users that have no profile picture yet');
	// Upload an image
    casper.fill('form#changepic-form', {
        'file': 'tests/casperjs/data/balloons.jpg'
    }, false);
    casper.waitForSelector('.jcrop-holder', function() {
        // Verify the image is showing in the cropping area
        casper.test.assertExists('.jcrop-holder > img', 'The image is showing in the cropping area');
        // Verify the 'set picture' button is present
        casper.test.assertExists('#changepic-set', 'The \'Set picture\' button is present');
        // Click the button
        casper.click('#changepic-set');
        // Verify that setting the picture worked
        casper.waitForSelector('#oae-notification-container .alert', function() {
            casper.test.assertDoesntExist('#oae-notification-container .alert.alert-error', 'Picture successfully submitted and stored');
            casper.click('#oae-notification-container .close');
        });
    });
};

/**
 * Goes through the workflow of uploading and saving the user picture
 */
var verifyLargePictureValidation = function() {
    // Verify the upload form is present
    casper.test.assertExists('form#changepic-form', 'The change picture form is present');
    // Upload an image over 5 megabytes to trigger validation
    casper.fill('form#changepic-form', {
        'file': 'tests/casperjs/data/guitar.png'
    }, false);
    // Verify that the picture failed to be set
    casper.waitForSelector('#oae-notification-container .alert', function() {
        casper.test.assertExists('#oae-notification-container .alert.alert-error', 'Pictures over 10MB are rejected');
        casper.click('#oae-notification-container .close');
    });
};

casper.start('http://test.oae.com', function() {
    // Create a user to test changepicture with
    var user = null;
    userUtil().createUsers(1, function(users) {
        user = users[0];
    });

    // Login with that user
    casper.then(function() {
        userUtil().doLogIn(user.username, 'password');
    });

    // Open the changepicture modal
    casper.then(function() {
        casper.echo('Verify open change picture modal', 'INFO');
        verifyOpenChangePicture();
    });

    // Verify picture upload
    casper.then(function() {
        casper.echo('Verify picture upload', 'INFO');
        verifyPictureUpload();
    });

    // Verify picture upload validation
    casper.then(function() {
        casper.echo('Verify pictures over 10MB aren\'t accepted', 'INFO');
        casper.reload(function() {
            casper.then(openChangePicture);
            casper.then(verifyLargePictureValidation);
        });
    });

    // Log out at the end of the test
    casper.then(function() {
        userUtil().doLogOut();
    });
});

casper.run(function() {
    this.test.done();
});

{'fraction_non_alphanumeric': 0.1385644630910534, 'fraction_numerical': 0.0036285293117133462, 'mean_word_length': 3.014565316340464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '5622633', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2445, 'n_words': 628}