<commit_before>var Dropdown = function(){

	this.openedClass = 'opened';
	this.optionsRepeater = 'option in ctrl.data';
	this.dropdowns = element.all(by.css('.pg-dropdown'));
	
};

describe('Dropdown Spec', function(){

	var elements = new Dropdown();

	beforeEach(function(){

		browser.get('/');
		
	});

	it('should have dropdowns on index.html', hasDropdowns);
	it('should have options inside a dropdown', hasOptions);
	it('should focus dropdown on tab key press', tabFocus);
	it('should open dropdown on click', clickOpen);
	it('should open dropdown on enter key press', enterKeyOpen);
	it('should close dropdown on esc key press', escKeyClose);
	it('should select an option when clicked', clickSelectOption);

	function hasDropdowns(){

		elements.dropdowns
		.then(function(dropdowns){

			expect(dropdowns.length).toBeGreaterThan(0);
			
		});
		
	}

	function hasOptions(){

		elements.dropdowns
		.then(function(dropdowns){

			dropdowns[0].all(by.repeater(elements.optionsRepeater))
			.then(function(options){

				expect(options.length).toBeGreaterThan(0);
				
			});
			
		});
		
	}

	function clickOpen(){

		_openClickDropdown(0, function(dropdown){

			expect(dropdown.getAttribute('class')).toMatch(elements.openedClass);
			
		});
		
	}


	function enterKeyOpen(){

		_openEnterDropdown(function(dropdown){

			expect(dropdown.getAttribute('class')).toMatch(elements.openedClass);
			
		});
		
	}

	function escKeyClose(){

		_openEnterDropdown(function(dropdown){

			browser.actions().sendKeys(protractor.Key.ESCAPE).perform()
			.then(function(){

				expect(dropdown.getAttribute('class')).not.toMatch(elements.openedClass);
				
			});
			
		});		
		
	}

	function tabFocus(){

		elements.dropdowns
		.then(function(dropdowns){

			var _dropdown = dropdowns[0];

			browser.actions().sendKeys(protractor.Key.TAB).perform()
			.then(function(){

				browser.driver.switchTo().activeElement()
				.getAttribute('class')
				.then(function(focusedClasses){

					expect(_dropdown.getAttribute('class')).toMatch(focusedClasses);
					
				});
				
			});
			
		});
		
	}

	function clickSelectOption(){

		_openClickDropdown(0, function(dropdown){

			dropdown.all(by.repeater(elements.optionsRepeater))
			.then(function(options){

				var _option = options[0];

				_checkVisible(_option)
				.then(function(){

					_option.element(by.css('span')).getText()
					.then(function(previousText){

						_option.click()
						.then(function(){

							var _current = dropdown.element(by.css('.current-selected-option span'));

							_current.getText()
							.then(function(currentText){

								expect(currentText).toMatch(previousText);
								
							});
							
						});
						
					});
					
				});				
				
			});
			
		});
		
	}

	function _openEnterDropdown(callback){

		browser.actions().sendKeys(protractor.Key.TAB).perform()
		.then(function(){

			var _focused = browser.driver.switchTo().activeElement();

			browser.actions().sendKeys(protractor.Key.ENTER).perform()
			.then(function(){

				callback(_focused);
				
			});
			
		});	
		
	}	

	function _openClickDropdown(index, callback){

		elements.dropdowns
		.then(function(dropdowns){<commit_msg>Add select option via keybindings test<commit_after>var Dropdown = function(){

	this.openedClass = 'opened';
	this.optionsRepeater = 'option in ctrl.data';
	this.dropdowns = element.all(by.css('.pg-dropdown'));
	
};

describe('Dropdown Spec', function(){

	var elements = new Dropdown();

	beforeEach(function(){

		browser.get('/');
		
	});

	it('should have dropdowns on index.html', hasDropdowns);
	it('should have options inside a dropdown', hasOptions);
	it('should focus dropdown on tab key press', tabFocus);
	it('should open dropdown on click', clickOpen);
	it('should open dropdown on enter key press', enterKeyOpen);
	it('should close dropdown on esc key press', escKeyClose);
	it('should select an option when clicked', clickSelectOption);
	it('should select an option when enter key is pressed', enterSelectOption);

	function hasDropdowns(){

		elements.dropdowns
		.then(function(dropdowns){

			expect(dropdowns.length).toBeGreaterThan(0);
			
		});
		
	}

	function hasOptions(){

		elements.dropdowns
		.then(function(dropdowns){

			dropdowns[0].all(by.repeater(elements.optionsRepeater))
			.then(function(options){

				expect(options.length).toBeGreaterThan(0);
				
			});
			
		});
		
	}

	function clickOpen(){

		_openClickDropdown(0, function(dropdown){

			expect(dropdown.getAttribute('class')).toMatch(elements.openedClass);
			
		});
		
	}


	function enterKeyOpen(){

		_openEnterDropdown(function(dropdown){

			expect(dropdown.getAttribute('class')).toMatch(elements.openedClass);
			
		});
		
	}

	function escKeyClose(){

		_openEnterDropdown(function(dropdown){

			browser.actions().sendKeys(protractor.Key.ESCAPE).perform()
			.then(function(){

				expect(dropdown.getAttribute('class')).not.toMatch(elements.openedClass);
				
			});
			
		});		
		
	}

	function tabFocus(){

		elements.dropdowns
		.then(function(dropdowns){

			var _dropdown = dropdowns[0];

			browser.actions().sendKeys(protractor.Key.TAB).perform()
			.then(function(){

				browser.driver.switchTo().activeElement()
				.getAttribute('class')
				.then(function(focusedClasses){

					expect(_dropdown.getAttribute('class')).toMatch(focusedClasses);
					
				});
				
			});
			
		});
		
	}

	function clickSelectOption(){

		_openClickDropdown(0, function(dropdown){

			dropdown.all(by.repeater(elements.optionsRepeater))
			.then(function(options){

				var _option = options[0];

				_checkVisible(_option)
				.then(function(){

					_option.element(by.css('span')).getText()
					.then(function(optionText){

						_option.click()
						.then(function(){

							var _current = dropdown.element(by.css('.current-selected-option span'));

							_current.getText()
							.then(function(currentText){

								expect(currentText).toMatch(optionText);
								
							});
							
						});
						
					});
					
				});				
				
			});
			
		});
		
	}

	function enterSelectOption(){

		_openClickDropdown(0, function(dropdown){

			dropdown.all(by.repeater(elements.optionsRepeater))
			.then(function(options){

				var _option = options[0];

				_checkVisible(_option)
				.then(function(){

					_option.element(by.css('span')).getText()
					.then(function(optionText){

						browser.actions().sendKeys(protractor.Key.ARROW_DOWN).perform()
						.then(function(){

							browser.actions().sendKeys(protractor.Key.ENTER).perform()
							.then(function(){

								var _current = dropdown.element(by.css('.current-selected-option span'));

								_current.getText()
								.then(function(currentText){

									expect(currentText).toMatch(optionText);
									
								});								
								
							});
							
						});

					});
					
				});
				
			});
			
		});
		
	}

	function _openEnterDropdown(callback){

		browser.actions().sendKeys(protractor.Key.TAB).perform()
		.then(function(){

			var _focused = browser.driver.switchTo().activeElement();

			browser.actions().sendKeys(protractor.Key.ENTER).perform()
			.then(function(){

				callback(_focused);
				
			});
			
		});	
		
	}	

	function _openClickDropdown(index, callback){

		elements.dropdowns
		.then(function(dropdowns){
{'fraction_non_alphanumeric': 0.14959660877888692, 'fraction_numerical': 0.0021878845890879258, 'mean_word_length': 3.356164383561644, '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': '4480399', 'n_tokens_mistral': 2958, 'n_tokens_neox': 2178, 'n_words': 332}