File tree 4 files changed +99
-0
lines changed
4 files changed +99
-0
lines changed Original file line number Diff line number Diff line change 14
14
15
15
<!-- Use a custom component to render a list of phones -->
16
16
< phone-list > </ phone-list >
17
+ < div class ="container-fluid ">
18
+ < div class ="row ">
19
+ < div class ="col-md-2 ">
20
+ <!--Sidebar content-->
21
+
22
+ Search: < input ng-model ="query ">
23
+ Sort by:
24
+ < select ng-model ="orderProp ">
25
+ < option value ="name "> Alphabetical</ option >
26
+ < option value ="age "> Newest</ option >
27
+ </ select >
28
+
29
+ </ div >
30
+ < div class ="col-md-10 ">
31
+ <!--Body content-->
32
+
33
+ < ul class ="phones ">
34
+ < li ng-repeat ="phone in phones | filter:query | orderBy:orderProp ">
35
+ < span > {{phone.name}}</ span >
36
+ < p > {{phone.snippet}}</ p >
37
+ </ li >
38
+ </ ul >
39
+
40
+ </ div >
41
+ </ div >
42
+ </ div >
17
43
18
44
</ body >
19
45
</ html >
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /* Controllers */
4
+
5
+ var phonecatApp = angular . module ( 'phonecatApp' , [ ] ) ;
6
+
7
+ phonecatApp . controller ( 'PhoneListCtrl' , function ( $scope ) {
8
+ $scope . phones = [
9
+ { 'name' : 'Nexus S' ,
10
+ 'snippet' : 'Fast just got faster with Nexus S.' ,
11
+ 'age' : 1 } ,
12
+ { 'name' : 'Motorola XOOM™ with Wi-Fi' ,
13
+ 'snippet' : 'The Next, Next Generation tablet.' ,
14
+ 'age' : 2 } ,
15
+ { 'name' : 'MOTOROLA XOOM™' ,
16
+ 'snippet' : 'The Next, Next Generation tablet.' ,
17
+ 'age' : 3 }
18
+ ] ;
19
+
20
+ $scope . orderProp = 'age' ;
21
+ } ) ;
Original file line number Diff line number Diff line change @@ -25,6 +25,32 @@ describe('PhoneCat Application', function() {
25
25
expect ( phoneList . count ( ) ) . toBe ( 2 ) ;
26
26
} ) ;
27
27
28
+
29
+ it ( 'should be possible to control phone order via the drop down select box' , function ( ) {
30
+
31
+ var phoneNameColumn = element . all ( by . repeater ( 'phone in phones' ) . column ( 'phone.name' ) ) ;
32
+ var query = element ( by . model ( 'query' ) ) ;
33
+
34
+ function getNames ( ) {
35
+ return phoneNameColumn . map ( function ( elm ) {
36
+ return elm . getText ( ) ;
37
+ } ) ;
38
+ }
39
+
40
+ query . sendKeys ( 'tablet' ) ; //let's narrow the dataset to make the test assertions shorter
41
+
42
+ expect ( getNames ( ) ) . toEqual ( [
43
+ "Motorola XOOM\u2122 with Wi-Fi" ,
44
+ "MOTOROLA XOOM\u2122"
45
+ ] ) ;
46
+
47
+ element ( by . model ( 'orderProp' ) ) . element ( by . css ( 'option[value="name"]' ) ) . click ( ) ;
48
+
49
+ expect ( getNames ( ) ) . toEqual ( [
50
+ "MOTOROLA XOOM\u2122" ,
51
+ "Motorola XOOM\u2122 with Wi-Fi"
52
+ ] ) ;
53
+ } ) ;
28
54
} ) ;
29
55
30
56
} ) ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ /* jasmine specs for controllers go here */
4
+ describe ( 'PhoneCat controllers' , function ( ) {
5
+
6
+ describe ( 'PhoneListCtrl' , function ( ) {
7
+ var scope , ctrl ;
8
+
9
+ beforeEach ( module ( 'phonecatApp' ) ) ;
10
+
11
+ beforeEach ( inject ( function ( $controller ) {
12
+ scope = { } ;
13
+ ctrl = $controller ( 'PhoneListCtrl' , { $scope :scope } ) ;
14
+ } ) ) ;
15
+
16
+
17
+ it ( 'should create "phones" model with 3 phones' , function ( ) {
18
+ expect ( scope . phones . length ) . toBe ( 3 ) ;
19
+ } ) ;
20
+
21
+
22
+ it ( 'should set the default value of orderProp model' , function ( ) {
23
+ expect ( scope . orderProp ) . toBe ( 'age' ) ;
24
+ } ) ;
25
+ } ) ;
26
+ } ) ;
You can’t perform that action at this time.
0 commit comments