Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 749230e

Browse files
IgorMinarpetebacondarwin
authored andcommitted
step-4 phone ordering
- Add "age" property to the phone model - Add select box to control phone list order - Override the default order value in controller - Add unit and e2e test for this feature
1 parent 5bcf1da commit 749230e

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

app/index.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616
<!--Sidebar content-->
1717

1818
Search: <input ng-model="query">
19+
Sort by:
20+
<select ng-model="orderProp">
21+
<option value="name">Alphabetical</option>
22+
<option value="age">Newest</option>
23+
</select>
1924

2025
</div>
2126
<div class="col-md-10">
2227
<!--Body content-->
2328

2429
<ul class="phones">
25-
<li ng-repeat="phone in phones | filter:query">
26-
{{phone.name}}
30+
<li ng-repeat="phone in phones | filter:query | orderBy:orderProp">
31+
<span>{{phone.name}}</span>
2732
<p>{{phone.snippet}}</p>
2833
</li>
2934
</ul>

app/js/controllers.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ var phonecatApp = angular.module('phonecatApp', []);
77
phonecatApp.controller('PhoneListCtrl', function($scope) {
88
$scope.phones = [
99
{'name': 'Nexus S',
10-
'snippet': 'Fast just got faster with Nexus S.'},
10+
'snippet': 'Fast just got faster with Nexus S.',
11+
'age': 1},
1112
{'name': 'Motorola XOOM™ with Wi-Fi',
12-
'snippet': 'The Next, Next Generation tablet.'},
13+
'snippet': 'The Next, Next Generation tablet.',
14+
'age': 2},
1315
{'name': 'MOTOROLA XOOM™',
14-
'snippet': 'The Next, Next Generation tablet.'}
16+
'snippet': 'The Next, Next Generation tablet.',
17+
'age': 3}
1518
];
19+
20+
$scope.orderProp = 'age';
1621
});

test/e2e/scenarios.js

+27
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,32 @@ describe('PhoneCat App', function() {
2525
query.sendKeys('motorola');
2626
expect(phoneList.count()).toBe(2);
2727
});
28+
29+
30+
it('should be possible to control phone order via the drop down select box', function() {
31+
32+
var phoneNameColumn = element.all(by.repeater('phone in phones').column('{{phone.name}}'));
33+
var query = element(by.model('query'));
34+
35+
function getNames() {
36+
return phoneNameColumn.map(function(elm) {
37+
return elm.getText();
38+
});
39+
}
40+
41+
query.sendKeys('tablet'); //let's narrow the dataset to make the test assertions shorter
42+
43+
expect(getNames()).toEqual([
44+
"Motorola XOOM\u2122 with Wi-Fi",
45+
"MOTOROLA XOOM\u2122"
46+
]);
47+
48+
element(by.model('orderProp')).element(by.css('option[value="name"]')).click();
49+
50+
expect(getNames()).toEqual([
51+
"MOTOROLA XOOM\u2122",
52+
"Motorola XOOM\u2122 with Wi-Fi"
53+
]);
54+
});
2855
});
2956
});

test/unit/controllersSpec.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@
44
describe('PhoneCat controllers', function() {
55

66
describe('PhoneListCtrl', function(){
7+
var scope, ctrl;
78

89
beforeEach(module('phonecatApp'));
910

10-
it('should create "phones" model with 3 phones', inject(function($controller) {
11-
var scope = {},
12-
ctrl = $controller('PhoneListCtrl', {$scope:scope});
11+
beforeEach(inject(function($controller) {
12+
scope = {};
13+
ctrl = $controller('PhoneListCtrl', {$scope:scope});
14+
}));
15+
1316

17+
it('should create "phones" model with 3 phones', inject(function($controller) {
1418
expect(scope.phones.length).toBe(3);
1519
}));
1620

21+
22+
it('should set the default value of orderProp model', function() {
23+
expect(scope.orderProp).toBe('age');
24+
});
1725
});
1826
});

0 commit comments

Comments
 (0)