Skip to content

Commit 731cf72

Browse files
author
Adam Bradley
committed
test(floatingLabel): snapshot tests
1 parent 5f1ea5f commit 731cf72

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: floatingLabel
3+
component: itemFloatingLabel
4+
---
5+
6+
<ion-header-bar class="bar-positive">
7+
<h1 class="title">
8+
Text Input: Floating Label
9+
</h1>
10+
</ion-header-bar>
11+
12+
<ion-content ng-controller="AppCtrl">
13+
14+
<div class="list">
15+
<label class="item item-input item-floating-label">
16+
<span class="input-label">Name</span>
17+
<input type="text" placeholder="Name">
18+
</label>
19+
<label class="item item-input item-floating-label">
20+
<span class="input-label">Profession</span>
21+
<input type="text" placeholder="Profession">
22+
</label>
23+
<label class="item item-input item-floating-label">
24+
<span class="input-label">Favorite Song</span>
25+
<textarea placeholder="Favorite Song" ng-model="favSong"></textarea>
26+
</label>
27+
</div>
28+
29+
</ion-content>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: floatingLabel
3+
component: itemFloatingLabel
4+
---
5+
6+
var app = angular.module('floatingLabel', ['ionic']);
7+
8+
app.controller('AppCtrl', function($scope) {
9+
10+
$scope.favSong = "Tubthumping";
11+
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: floatingLabel
3+
component: itemFloatingLabel
4+
---
5+
6+
it('should enter text into floating label inputs', function(){
7+
var ele = element.all(by.css('label.item-floating-label input, label.item-floating-label textarea'));
8+
ele.get(0).sendKeys('Dr. Pumpernickel');
9+
ele.get(1).sendKeys('Round House Kicks');
10+
});
11+
12+
it('should add and remove text from floating label inputs', function(){
13+
var ele = element.all(by.css('label.item-floating-label input, label.item-floating-label textarea'));
14+
15+
for(var x=0; x<'Dr. Pumpernickel'.length; x++) {
16+
ele.get(0).sendKeys(protractor.Key.BACK_SPACE);
17+
}
18+
19+
ele.get(1).sendKeys(" To The Face");
20+
21+
for(var x=0; x<'Tubthumping'.length; x++) {
22+
ele.get(2).sendKeys(protractor.Key.BACK_SPACE);
23+
}
24+
25+
});

js/angular/directive/itemFloatingLabel.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ IonicModule
1111
if ( !input || !inputLabel ) return;
1212

1313
var onInput = function() {
14-
var hasInput = inputLabel.classList.contains('has-input');
15-
if ( input.value && !hasInput ) {
14+
if ( input.value ) {
1615
inputLabel.classList.add('has-input');
17-
}
18-
else if ( !input.value && hasInput ) {
16+
} else {
1917
inputLabel.classList.remove('has-input');
2018
}
2119
};
@@ -26,8 +24,6 @@ IonicModule
2624
if ( ngModelCtrl ) {
2725
ngModelCtrl.$render = function() {
2826
input.value = ngModelCtrl.$viewValue || '';
29-
if ( ngModelCtrl.$viewValue ) input.value = ngModelCtrl.$viewValue;
30-
else input.value = '';
3127
onInput();
3228
};
3329
}

0 commit comments

Comments
 (0)