<commit_before>// Copyright (c) 2012 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
/*global Raphael, mocha, Touch, $ */

(function() {
	"use strict";

	var client = require("./client.js");
	var HtmlElement = require("./html_element.js");

	mocha.setup({ignoreLeaks: true});

	describe("Drawing area", function() {
		var drawingArea;
		var documentBody;
		var svgCanvas;

		beforeEach(function() {
			documentBody = new HtmlElement($(document.body));
			drawingArea = HtmlElement.fromHtml("<div style='height: 300px; width: 600px'>hi</div>");
			drawingArea.appendSelfToBody();
			svgCanvas = client.initializeDrawingArea(drawingArea);
		});

		afterEach(function() {
			drawingArea.remove();
			client.drawingAreaHasBeenRemovedFromDom();
			$(document.body).off();
		});

		describe("mouse events", function() {
			it("draws a line in response to mouse drag", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseUp(50, 60);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60]
				]);
			});

			it("draws multiple line segments when mouse is dragged multiple places", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseMove(40, 20);
				drawingArea.doMouseMove(10, 15);
				drawingArea.doMouseUp(10, 15);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60],
					[50, 60, 40, 20],
					[40, 20, 10, 15]
				]);
			});

			it("draws multiple line segments when there are multiple drags", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseUp(50, 60);

				drawingArea.doMouseMove(40, 20);

				drawingArea.doMouseDown(30, 25);
				drawingArea.doMouseMove(10, 15);
				drawingArea.doMouseUp(10, 15);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60],
					[30, 25, 10, 15]
				]);
			});

			it("does not draw line segment when mouse button is released", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseUp(50, 60);

				expect(lineSegments()).to.eql([]);
			});

			it("does not draw line segments when mouse button has never been pushed", function() {
				drawingArea.doMouseMove(20, 30);
				drawingArea.doMouseMove(50, 60);

				expect(lineSegments()).to.eql([]);
			});

			it("stops drawing line segments after mouse button is released", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseUp(50, 60);

				drawingArea.doMouseMove(10, 15);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60]
				]);
			});

//			it("continues drawing if mouse leaves drawing area and comes back in", function() {
//				drawingArea.doMouseDown(20, 30);
//				drawingArea.doMouseMove(50, 60);
//				drawingArea.doMouseLeave(700, 70);
//
//				documentBody.doMouseMove(700, 70);
//				drawingArea.doMouseMove(90, 40);
//				drawingArea.doMouseUp(90, 40);
//
//				expect(lineSegments()).to.eql([
//					[20, 30, 50, 60],
//					[50, 60, 700, 70],
//					[700, 70, 90, 40]
//				]);
//			});

			it("does not start drawing if drag is started outside drawing area", function() {
				documentBody.doMouseDown(601, 150);<commit_msg>Test of mouse leaving drawing area now works properly cross-browser<commit_after>// Copyright (c) 2012 Titanium I.T. LLC. All rights reserved. See LICENSE.txt for details.
/*global Raphael, mocha, Touch, $ */

(function() {
	"use strict";

	var client = require("./client.js");
	var HtmlElement = require("./html_element.js");

	mocha.setup({ignoreLeaks: true});

	describe("Drawing area", function() {
		var drawingArea;
		var documentBody;
		var svgCanvas;

		beforeEach(function() {
			documentBody = new HtmlElement($(document.body));
			drawingArea = HtmlElement.fromHtml("<div style='height: 300px; width: 600px'>hi</div>");
			drawingArea.appendSelfToBody();
			svgCanvas = client.initializeDrawingArea(drawingArea);
		});

		afterEach(function() {
			drawingArea.remove();
			client.drawingAreaHasBeenRemovedFromDom();
			documentBody.removeAllEventHandlers();
		});

		describe("mouse events", function() {
			it("draws a line in response to mouse drag", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseUp(50, 60);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60]
				]);
			});

			it("draws multiple line segments when mouse is dragged multiple places", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseMove(40, 20);
				drawingArea.doMouseMove(10, 15);
				drawingArea.doMouseUp(10, 15);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60],
					[50, 60, 40, 20],
					[40, 20, 10, 15]
				]);
			});

			it("draws multiple line segments when there are multiple drags", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseUp(50, 60);

				drawingArea.doMouseMove(40, 20);

				drawingArea.doMouseDown(30, 25);
				drawingArea.doMouseMove(10, 15);
				drawingArea.doMouseUp(10, 15);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60],
					[30, 25, 10, 15]
				]);
			});

			it("does not draw line segment when mouse button is released", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseUp(50, 60);

				expect(lineSegments()).to.eql([]);
			});

			it("does not draw line segments when mouse button has never been pushed", function() {
				drawingArea.doMouseMove(20, 30);
				drawingArea.doMouseMove(50, 60);

				expect(lineSegments()).to.eql([]);
			});

			it("stops drawing line segments after mouse button is released", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseUp(50, 60);

				drawingArea.doMouseMove(10, 15);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60]
				]);
			});

			it("continues drawing if mouse leaves drawing area and comes back in", function() {
				drawingArea.doMouseDown(20, 30);
				drawingArea.doMouseMove(50, 60);
				drawingArea.doMouseLeave(700, 70);

				var pageCoordinates = drawingArea.pageOffset({x: 700, y: 70});
				var bodyRelative = documentBody.relativeOffset(pageCoordinates);

				documentBody.doMouseMove(bodyRelative.x, bodyRelative.y);
				drawingArea.doMouseMove(90, 40);
				drawingArea.doMouseUp(90, 40);

				expect(lineSegments()).to.eql([
					[20, 30, 50, 60],
					[50, 60, 700, 70],
					[700, 70, 90, 40]
				]);
			});

			it("does not start drawing if drag is started outside drawing area", function() {
				documentBody.doMouseDown(601, 150);
{'fraction_non_alphanumeric': 0.15525801113284188, 'fraction_numerical': 0.06499172559049195, 'mean_word_length': 3.629526462395543, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3278415', 'n_tokens_mistral': 3066, 'n_tokens_neox': 2227, 'n_words': 523}