This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 4 files changed +53
-8
lines changed
4 files changed +53
-8
lines changed Original file line number Diff line number Diff line change 16
16
<!--Sidebar content-->
17
17
18
18
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 >
19
24
20
25
</ div >
21
26
< div class ="col-md-10 ">
22
27
<!--Body content-->
23
28
24
29
< 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 >
27
32
< p > {{phone.snippet}}</ p >
28
33
</ li >
29
34
</ ul >
Original file line number Diff line number Diff line change @@ -7,10 +7,15 @@ var phonecatApp = angular.module('phonecatApp', []);
7
7
phonecatApp . controller ( 'PhoneListCtrl' , function ( $scope ) {
8
8
$scope . phones = [
9
9
{ 'name' : 'Nexus S' ,
10
- 'snippet' : 'Fast just got faster with Nexus S.' } ,
10
+ 'snippet' : 'Fast just got faster with Nexus S.' ,
11
+ 'age' : 1 } ,
11
12
{ 'name' : 'Motorola XOOM™ with Wi-Fi' ,
12
- 'snippet' : 'The Next, Next Generation tablet.' } ,
13
+ 'snippet' : 'The Next, Next Generation tablet.' ,
14
+ 'age' : 2 } ,
13
15
{ 'name' : 'MOTOROLA XOOM™' ,
14
- 'snippet' : 'The Next, Next Generation tablet.' }
16
+ 'snippet' : 'The Next, Next Generation tablet.' ,
17
+ 'age' : 3 }
15
18
] ;
19
+
20
+ $scope . orderProp = 'age' ;
16
21
} ) ;
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 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
+ } ) ;
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 scope , ctrl ;
7
8
8
9
beforeEach ( module ( 'phonecatApp' ) ) ;
9
10
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
+
13
16
17
+ it ( 'should create "phones" model with 3 phones' , inject ( function ( $controller ) {
14
18
expect ( scope . phones . length ) . toBe ( 3 ) ;
15
19
} ) ) ;
16
20
21
+
22
+ it ( 'should set the default value of orderProp model' , function ( ) {
23
+ expect ( scope . orderProp ) . toBe ( 'age' ) ;
24
+ } ) ;
17
25
} ) ;
18
26
} ) ;
You can’t perform that action at this time.
0 commit comments