<commit_before>'use strict';

describe('test module ng.django.forms', function() {
	var john = '<EMAIL>';
	var template =
		'<form name="valid_form" action=".">' +
		'<input name="email_field" ng-model="mail_addr" type="text" {value} />'
		'</form>';
	
	describe('overrides internal form behavior', function() {
		var unbound_form, bound_form, scope;

		beforeEach(inject(function($rootScope, $compile) {
			scope = $rootScope.$new();
			//bound_form = angular.element(template.replace('{value}', 'value="' + john + '"'));
			//$compile(bound_form)(scope);
			unbound_form = angular.element(template.replace('{value}', ''));
			dump($compile(unbound_form)(scope));
		}));

		
		it('should read from attribute "value" into ng-model', function() {
			dump(unbound_form);
			dump(scope.valid_form.email_field);
			//expect(email_field.val()).toBe(john);
			//expect(scope.valid_form.email).toBe(john);
			expect(true).toBe(true);
		});

	});

});<commit_msg>Added unit testing for module ng.django.forms<commit_after>'use strict';

describe('unit tests for module ng.django.forms', function() {
	var john = '<EMAIL>';
	var template =
		'<form name="valid_form" action=".">' +
		'<input name="email_field" ng-model="model.email" type="text" {value} />' +
		'</form>';

	function compileUnboundForm($compile, scope) {
		var doc = template.replace('{value}', '').replace('{date}', '');
		var unbound_form = angular.element(doc);
		$compile(unbound_form)(scope);
		scope.$digest();
	}

	function compileBoundForm($compile, scope) {
		var doc = template.replace('{value}', 'value="' + john + '"').replace('{date}', '');
		var bound_form = angular.element(doc);
		$compile(bound_form)(scope);
		scope.$digest();
	}

	describe('test default form behavior', function() {
		var scope;

		beforeEach(inject(function($rootScope) {
			scope = $rootScope.$new();
		}));

		describe('on unbound forms', function() {
			it('the view value of empty input fields should remain undefined', inject(function($compile) {
				compileUnboundForm($compile, scope);
				expect(scope.valid_form.email_field.$viewValue).toBe(undefined);
			}));
		});

		describe('on bound forms', function() {
			it('the view value of filled input fields should remain undefined', inject(function($compile) {
				compileBoundForm($compile, scope);
				expect(scope.valid_form.email_field.$viewValue).toBe(undefined);
			}));
		});
	});

	describe('test overridden form behavior', function() {
		var scope;
	
		beforeEach(function() {
			// djangular's 'form' directive, overrides the behavior of the view value.
			module('ng.django.forms');
		});

		beforeEach(inject(function($rootScope) {
			scope = $rootScope.$new();
		}));

		describe('on unbound forms', function() {
			it('the view value of empty input fields should be empty', inject(function($compile) {
				compileUnboundForm($compile, scope);
				expect(scope.valid_form.email_field.$viewValue).toBe('');
			}));
		});

		describe('on bound forms', function() {
			it('the view value of filled input fields should remain as is', inject(function($compile) {
				compileBoundForm($compile, scope);
				expect(scope.valid_form.email_field.$viewValue).toBe(john);
			}));
		});

	});

	describe('test directive validateDate', function() {
		var scope, form;
	
		beforeEach(function() {
			// djangular's 'form' directive, overrides the behavior of the view value.
			module('ng.django.forms');
		});

		beforeEach(inject(function($rootScope) {
			scope = $rootScope.$new();
		}));

		beforeEach(inject(function($compile) {
			var doc =
				'<form name="form">' +
				'<input name="date_field" ng-model="model.date" type="text" validate-date="^(\\d{4})-(\\d{1,2})-(\\d{1,2})$" />' +
				'</form>';
			var element = angular.element(doc);
			scope.model = { date: null };
			$compile(element)(scope);
			form = scope.form;
		}));

		it('to reject 2014/04/01', function() {
			form.date_field.$setViewValue('2014/04/01');
			scope.$digest();
			expect(form.date_field.$valid).toBe(false);
		});

		it('to accept 2014-04-01', function() {
			form.date_field.$setViewValue('2014-03-01');
			scope.$digest();
			expect(form.date_field.$valid).toBe(true);
		});

		it('to reject 2014-04-31', function() {
			form.date_field.$setViewValue('2014-02-29');
			scope.$digest();
			expect(form.date_field.$valid).toBe(false);
		});
	});
});
{'fraction_non_alphanumeric': 0.19202397418165054, 'fraction_numerical': 0.012217611802674043, 'mean_word_length': 4.485461441213654, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, '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': '2623009', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1391, 'n_words': 275}