From 731cf726a9906543ca8a6e0f744586f42dd116f0 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 13 Jun 2014 09:36:14 -0500 Subject: [PATCH] test(floatingLabel): snapshot tests --- .../textInput/floatingLabel/index.html | 29 +++++++++++++++++++ .../textInput/floatingLabel/index.js | 12 ++++++++ .../textInput/floatingLabel/test.scenario.js | 25 ++++++++++++++++ js/angular/directive/itemFloatingLabel.js | 8 ++--- 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 demos/directive/textInput/floatingLabel/index.html create mode 100644 demos/directive/textInput/floatingLabel/index.js create mode 100644 demos/directive/textInput/floatingLabel/test.scenario.js diff --git a/demos/directive/textInput/floatingLabel/index.html b/demos/directive/textInput/floatingLabel/index.html new file mode 100644 index 0000000000..295d703a27 --- /dev/null +++ b/demos/directive/textInput/floatingLabel/index.html @@ -0,0 +1,29 @@ +--- +name: floatingLabel +component: itemFloatingLabel +--- + + +

+ Text Input: Floating Label +

+
+ + + +
+ + + +
+ +
diff --git a/demos/directive/textInput/floatingLabel/index.js b/demos/directive/textInput/floatingLabel/index.js new file mode 100644 index 0000000000..8b076c3555 --- /dev/null +++ b/demos/directive/textInput/floatingLabel/index.js @@ -0,0 +1,12 @@ +--- +name: floatingLabel +component: itemFloatingLabel +--- + +var app = angular.module('floatingLabel', ['ionic']); + +app.controller('AppCtrl', function($scope) { + + $scope.favSong = "Tubthumping"; + +}); diff --git a/demos/directive/textInput/floatingLabel/test.scenario.js b/demos/directive/textInput/floatingLabel/test.scenario.js new file mode 100644 index 0000000000..c7b7bd7d1a --- /dev/null +++ b/demos/directive/textInput/floatingLabel/test.scenario.js @@ -0,0 +1,25 @@ +--- +name: floatingLabel +component: itemFloatingLabel +--- + +it('should enter text into floating label inputs', function(){ + var ele = element.all(by.css('label.item-floating-label input, label.item-floating-label textarea')); + ele.get(0).sendKeys('Dr. Pumpernickel'); + ele.get(1).sendKeys('Round House Kicks'); +}); + +it('should add and remove text from floating label inputs', function(){ + var ele = element.all(by.css('label.item-floating-label input, label.item-floating-label textarea')); + + for(var x=0; x<'Dr. Pumpernickel'.length; x++) { + ele.get(0).sendKeys(protractor.Key.BACK_SPACE); + } + + ele.get(1).sendKeys(" To The Face"); + + for(var x=0; x<'Tubthumping'.length; x++) { + ele.get(2).sendKeys(protractor.Key.BACK_SPACE); + } + +}); diff --git a/js/angular/directive/itemFloatingLabel.js b/js/angular/directive/itemFloatingLabel.js index a4a0cd4d84..cb8e5275d3 100644 --- a/js/angular/directive/itemFloatingLabel.js +++ b/js/angular/directive/itemFloatingLabel.js @@ -11,11 +11,9 @@ IonicModule if ( !input || !inputLabel ) return; var onInput = function() { - var hasInput = inputLabel.classList.contains('has-input'); - if ( input.value && !hasInput ) { + if ( input.value ) { inputLabel.classList.add('has-input'); - } - else if ( !input.value && hasInput ) { + } else { inputLabel.classList.remove('has-input'); } }; @@ -26,8 +24,6 @@ IonicModule if ( ngModelCtrl ) { ngModelCtrl.$render = function() { input.value = ngModelCtrl.$viewValue || ''; - if ( ngModelCtrl.$viewValue ) input.value = ngModelCtrl.$viewValue; - else input.value = ''; onInput(); }; }