This repository was archived by the owner on Feb 26, 2024. It is now read-only.
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 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 ">
30+ < li ng-repeat ="phone in phones | filter:query | orderBy:orderProp ">
2631 < span > {{phone.name}}</ span >
2732 < p > {{phone.snippet}}</ p >
2833 </ li >
Original file line number Diff line number Diff line change @@ -7,10 +7,15 @@ var phonecatApp = angular.module('phonecatApp', []);
77phonecatApp . 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} ) ;
Original file line number Diff line number Diff 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} ) ;
Original file line number Diff line number Diff line change 44describe ( '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' , function ( ) {
1418 expect ( scope . phones . length ) . toBe ( 3 ) ;
15- } ) ) ;
19+ } ) ;
20+
1621
22+ it ( 'should set the default value of orderProp model' , function ( ) {
23+ expect ( scope . orderProp ) . toBe ( 'age' ) ;
24+ } ) ;
1725 } ) ;
1826} ) ;
You can’t perform that action at this time.
0 commit comments