<commit_before>// Copyright (c) 2013 Titanium I.T. LLC. All rights reserved. See LICENSE.TXT for details.
/*global phantom, document, example */

(function() {
	"use strict";

	var URL = "http://localhost:5000";

	var page = require("webpage").create();

	page.onConsoleMessage = function(message) {
		console.log("CONSOLE: " + message);
	};

	page.open(URL, function(success) {
		if (success !== "success") die("PhantomJS could not load " + URL);

		try {
			runTest(inBrowserTest);
			phantom.exit(0);
		}
		catch(err) {
			die("Exception from PhantomJS: " + err);
		}
	});

	function inBrowserTest() {
		return page.evaluate(function() {
			try {
				var textField = document.getElementById("textField");
				var validateButton = document.getElementById("validate");

				validateButton.click();
				var actual = textField.getAttribute("class");
				var expected = example.REQUIRED_FIELD_CLASS;
				if (actual !== expected) return "textField class expected " + expected + " but was " + actual;
				else return null;
			}
			catch(err) {
				return "Exception in PhantomJS browser code";
			}
		});
	}

	function runTest(testFn) {
		var error = testFn();
		if (error) die(error);
	}

	function die(error) {
		console.log(error);
		phantom.exit(1);
	}

}());<commit_msg>Added user interaction test<commit_after>// Copyright (c) 2013 Titanium I.T. LLC. All rights reserved. See LICENSE.TXT for details.
/*global phantom, document, example */

(function() {
	"use strict";

	var URL = "http://localhost:5000";

	var page = require("webpage").create();

	page.onConsoleMessage = function(message) {
		console.log("CONSOLE: " + message);
	};

	page.open(URL, function(success) {
		if (success !== "success") die("PhantomJS could not load " + URL);

		try {
			runTest(inBrowserTest);
			runTest(userInteractionTest);
			phantom.exit(0);
		}
		catch(err) {
			die("Exception from PhantomJS: " + err.stack);
		}
	});

	function inBrowserTest() {
		return page.evaluate(function() {
			try {
				// Get the DOM elements
				var textField = document.getElementById("textField");
				var validateButton = document.getElementById("validate");

				// Click the validate button
				validateButton.click();

				// Check the CSS class
				var actual = textField.className;
				var expected = example.REQUIRED_FIELD_CLASS;
				if (actual !== expected) return "textField class expected " + expected + " but was " + actual;
				else return null;
			}
			catch(err) {
				return "Exception in PhantomJS browser code";
			}
		});
	}

	function userInteractionTest() {
		// Get validate button location
		var location = page.evaluate(function() {
			var validateButton = document.getElementById("validate");
			var bounds = validateButton.getBoundingClientRect();
			return {
				x: bounds.left + document.body.scrollLeft,
				y: bounds.top + document.body.scrollTop
			};
		});

		// Click the validate button
		page.sendEvent("click", location.x, location.y);

		// Check the CSS class
		return page.evaluate(function() {
			var textField = document.getElementById("textField");
			var actual = textField.className;
			var expected = example.REQUIRED_FIELD_CLASS;
			if (actual !== expected) return "textField class expected " + expected + " but was " + actual;
			else return null;
		});
	}

	function runTest(testFn) {
		var error = testFn();
		if (error) die(error);
	}

	function die(error) {
		console.log(error);
		phantom.exit(1);
	}

}());
{'fraction_non_alphanumeric': 0.14044289044289043, 'fraction_numerical': 0.005827505827505828, 'mean_word_length': 3.6080536912751677, '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': '2438070', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1042, 'n_words': 274}