File tree Expand file tree Collapse file tree 4 files changed +53
-8
lines changed Expand file tree Collapse file tree 4 files changed +53
-8
lines changed Original file line number Diff line number Diff line change @@ -10,10 +10,15 @@ phonecatApp.component('phoneList', {
10
10
} ) . controller ( 'PhoneListCtrl' , function ( ) {
11
11
this . phones = [
12
12
{ 'name' : 'Nexus S' ,
13
- 'snippet' : 'Fast just got faster with Nexus S.' } ,
13
+ 'snippet' : 'Fast just got faster with Nexus S.' ,
14
+ 'age' : 1 } ,
14
15
{ 'name' : 'Motorola XOOM™ with Wi-Fi' ,
15
- 'snippet' : 'The Next, Next Generation tablet.' } ,
16
+ 'snippet' : 'The Next, Next Generation tablet.' ,
17
+ 'age' : 2 } ,
16
18
{ 'name' : 'MOTOROLA XOOM™' ,
17
- 'snippet' : 'The Next, Next Generation tablet.' }
19
+ 'snippet' : 'The Next, Next Generation tablet.' ,
20
+ 'age' : 3 }
18
21
] ;
22
+
23
+ this . orderProp = 'age' ;
19
24
} ) ;
Original file line number Diff line number Diff line change 4
4
<!--Sidebar content-->
5
5
6
6
Search: < input ng-model ="$ctrl.query ">
7
+ Sort by:
8
+ < select ng-model ="$ctrl.orderProp ">
9
+ < option value ="name "> Alphabetical</ option >
10
+ < option value ="age "> Newest</ option >
11
+ </ select >
7
12
8
13
</ div >
9
14
< div class ="col-md-10 ">
10
15
<!--Body content-->
11
16
12
17
< ul class ="phones ">
13
- < li ng-repeat ="phone in $ctrl.phones | filter:$ctrl.query ">
14
- {{phone.name}}
18
+ < li ng-repeat ="phone in $ctrl.phones | filter:$ctrl.query | orderBy:$ctrl.orderProp ">
19
+ < span > {{phone.name}}</ span >
15
20
< p > {{phone.snippet}}</ p >
16
21
</ li >
17
22
</ ul >
Original file line number Diff line number Diff line change @@ -25,5 +25,32 @@ describe('PhoneCat App', function() {
25
25
query . sendKeys ( 'motorola' ) ;
26
26
expect ( phoneList . count ( ) ) . toBe ( 2 ) ;
27
27
} ) ;
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 $ctrl.phones' ) . column ( 'phone.name' ) ) ;
33
+ var query = element ( by . model ( '$ctrl.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 ( '$ctrl.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
+ } ) ;
28
55
} ) ;
29
56
} ) ;
Original file line number Diff line number Diff line change 4
4
describe ( 'PhoneCat controllers' , function ( ) {
5
5
6
6
describe ( 'PhoneListCtrl' , function ( ) {
7
+ var ctrl ;
7
8
8
9
beforeEach ( module ( 'phonecatApp' ) ) ;
9
10
10
- it ( 'should create "phones" model with 3 phones' , inject ( function ( $controller ) {
11
- var ctrl = $controller ( 'PhoneListCtrl' ) ;
11
+ beforeEach ( inject ( function ( $controller ) {
12
+ ctrl = $controller ( 'PhoneListCtrl' ) ;
13
+ } ) ) ;
14
+
12
15
16
+ it ( 'should create "phones" model with 3 phones' , function ( ) {
13
17
expect ( ctrl . phones . length ) . toBe ( 3 ) ;
14
- } ) ) ;
18
+ } ) ;
19
+
15
20
21
+ it ( 'should set the default value of orderProp model' , function ( ) {
22
+ expect ( ctrl . orderProp ) . toBe ( 'age' ) ;
23
+ } ) ;
16
24
} ) ;
17
25
} ) ;
You can’t perform that action at this time.
0 commit comments