<commit_before>/*jslint browser: true*/
/*global sinon,Backbone,jasmine,expect,GDP,_,expect,window*/
describe('GDP.ADVANCED.view.DataDetailsView', function() {
	var model,
	templateSpy,
	renderSpy,
	loggerSpy,
	server,
	testView,
	callWpsSpy,
	wpsDeferred,
	wps,
	url = 'http://cida.usgs.gov';
	
	//no-op alert
	window.alert = function(){};
	
	//mock promises for patching
	var resolveWithResponse = function(response){
		return function(){
			var deferred = $.Deferred();
			deferred.resolve(response);
			return deferred.promise();
		};
	};
	
	var rejectWithErrorMessage = function(message){
		return function(){
			var deferred = $.Deferred();
			deferred.reject(null, null, message);
			return deferred.promise();
		};
	};
	
	beforeEach(function() {
		server = sinon.fakeServer.create();
		model = new GDP.ADVANCED.model.Job();

		wpsDeferred = $.Deferred();

		templateSpy = jasmine.createSpy('templateSpy');
		renderSpy = jasmine.createSpy('renderSpy');
		loggerSpy = jasmine.createSpyObj('logger', ['error']);
		callWpsSpy = jasmine.createSpy('callWpsSpy').andReturn(wpsDeferred);

		GDP.logger = loggerSpy;
		wps = {
			sendWpsExecuteRequest : callWpsSpy
		};

		testView = new GDP.ADVANCED.view.DataDetailsView({
			model : model,
			template : templateSpy,
			wps: wps
		});
		testView.render = renderSpy;
	});

	afterEach(function() {
		server.restore();
	});
	it('Expects setUrl() to change the model\'s dataSourceUrl property', function() {
		testView.setUrl({ target : { value : url } });
		expect(testView.model.get('dataSourceUrl')).toEqual(url);
	});
	
	it('Expects selectVariables() to change the model\'s dataSourceVariables property', function() {
		var options = [
			{
			text: '',
			value: '',
			selected: null
			},
			{
			text: 'Var One',
			value: 'var1',
			selected: 'selected'
			},
			{
			text: 'Var Two',
			value: 'var2',
			selected: ''
			}
		];
		
		//call the function with 0, 1, 2, and 3 options.
		_.each(_.range(options.length), function(numberOfOptions){
			var optionsToUse = _.first(options, numberOfOptions);
			testView.selectVariables({ target : {options: optionsToUse }});
			var selectedOptions= testView.model.get('dataSourceVariables');
			var expectedToActualPairs = _.zip(optionsToUse, selectedOptions.models);
			_.each(expectedToActualPairs, function(expectedToActual){
				var expected = expectedToActual[0],
					actual = expectedToActual[1].attributes;
				expect(expected).toEqual(actual);
			});
		});
	});
	it('should reject the getDateRange promise with an error message if the web service call fails', function(){
		var expectedErrorMessage = 'error message';
		testView.wps.sendWpsExecuteRequest = rejectWithErrorMessage(expectedErrorMessage);
		var promise, actualErrorMessage;
		runs(function(){
			promise = testView.getDateRange('mockUrl', 'mockVariableName').fail(function(myMessage){
				actualErrorMessage = myMessage;
			});
		});
		waitsFor(function(){<commit_msg>Fixed test.<commit_after>/*jslint browser: true*/
/*global sinon,Backbone,jasmine,expect,GDP,_,expect,window*/
describe('GDP.ADVANCED.view.DataDetailsView', function() {
	var model,
	templateSpy,
	renderSpy,
	loggerSpy,
	server,
	testView,
	callWpsSpy,
	wpsDeferred,
	wps,
	url = 'http://cida.usgs.gov';
	
	//no-op alert
	window.alert = function(){};
	
	//mock promises for patching
	var resolveWithResponse = function(response){
		return function(){
			var deferred = $.Deferred();
			deferred.resolve(response);
			return deferred.promise();
		};
	};
	
	var rejectWithErrorMessage = function(message){
		return function(){
			var deferred = $.Deferred();
			deferred.reject(null, null, message);
			return deferred.promise();
		};
	};
	
	beforeEach(function() {
		server = sinon.fakeServer.create();
		model = new GDP.ADVANCED.model.Job();

		wpsDeferred = $.Deferred();

		templateSpy = jasmine.createSpy('templateSpy');
		renderSpy = jasmine.createSpy('renderSpy');
		loggerSpy = jasmine.createSpyObj('logger', ['error']);
		callWpsSpy = jasmine.createSpy('callWpsSpy').andReturn(wpsDeferred);

		GDP.logger = loggerSpy;
		wps = {
			sendWpsExecuteRequest : callWpsSpy
		};

		testView = new GDP.ADVANCED.view.DataDetailsView({
			model : model,
			template : templateSpy,
			wps: wps
		});
		testView.render = renderSpy;
	});

	afterEach(function() {
		server.restore();
	});
	it('Expects setUrl() to change the model\'s dataSourceUrl property', function() {
		testView.setUrl({ target : { value : url } });
		expect(testView.model.get('dataSourceUrl')).toEqual(url);
	});
	
	it('Expects setSelectedVariables() to change the model\'s dataSourceVariables property', function() {
		var options = [
			{
			text: '',
			value: '',
			selected: null
			},
			{
			text: 'Var One',
			value: 'var1',
			selected: 'selected'
			},
			{
			text: 'Var Two',
			value: 'var2',
			selected: ''
			}
		];
		
		//call the function with 0, 1, 2, and 3 options.
		_.each(_.range(options.length), function(numberOfOptions){
			var optionsToUse = _.first(options, numberOfOptions);
			testView.setSelectedVariables({ target : {options: optionsToUse }});
			var selectedOptions= testView.model.get('dataSourceVariables');
			var expectedToActualPairs = _.zip(optionsToUse, selectedOptions.models);
			_.each(expectedToActualPairs, function(expectedToActual){
				var expected = expectedToActual[0],
					actual = expectedToActual[1].attributes;
				expect(expected).toEqual(actual);
			});
		});
	});
	it('should reject the getDateRange promise with an error message if the web service call fails', function(){
		var expectedErrorMessage = 'error message';
		testView.wps.sendWpsExecuteRequest = rejectWithErrorMessage(expectedErrorMessage);
		var promise, actualErrorMessage;
		runs(function(){
			promise = testView.getDateRange('mockUrl', 'mockVariableName').fail(function(myMessage){
				actualErrorMessage = myMessage;
			});
		});
		waitsFor(function(){
{'fraction_non_alphanumeric': 0.14458036017669046, 'fraction_numerical': 0.0027183146449201497, 'mean_word_length': 4.356687898089172, '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': '6974970', 'n_tokens_mistral': 2200, 'n_tokens_neox': 1911, 'n_words': 390}