File tree Expand file tree Collapse file tree 3 files changed +22
-18
lines changed Expand file tree Collapse file tree 3 files changed +22
-18
lines changed Original file line number Diff line number Diff line change 44
55var phonecatApp = angular . module ( 'phonecatApp' , [ ] ) ;
66
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- ] ;
7+ phonecatApp . controller ( 'PhoneListCtrl' , function ( $scope , $http ) {
8+ $http . get ( 'phones/phones.json' ) . success ( function ( data ) {
9+ $scope . phones = data ;
10+ } ) ;
1911
2012 $scope . orderProp = 'age' ;
2113} ) ;
Original file line number Diff line number Diff line change @@ -12,13 +12,13 @@ describe('PhoneCat App', function() {
1212
1313
1414 it ( 'should filter the phone list as user types into the search box' , function ( ) {
15- expect ( repeater ( '.phones li' ) . count ( ) ) . toBe ( 3 ) ;
15+ expect ( repeater ( '.phones li' ) . count ( ) ) . toBe ( 20 ) ;
1616
1717 input ( 'query' ) . enter ( 'nexus' ) ;
1818 expect ( repeater ( '.phones li' ) . count ( ) ) . toBe ( 1 ) ;
1919
2020 input ( 'query' ) . enter ( 'motorola' ) ;
21- expect ( repeater ( '.phones li' ) . count ( ) ) . toBe ( 2 ) ;
21+ expect ( repeater ( '.phones li' ) . count ( ) ) . toBe ( 8 ) ;
2222 } ) ;
2323
2424
Original file line number Diff line number Diff line change 44describe ( 'PhoneCat controllers' , function ( ) {
55
66 describe ( 'PhoneListCtrl' , function ( ) {
7- var scope , ctrl ;
7+ var scope , ctrl , $httpBackend ;
88
99 beforeEach ( module ( 'phonecatApp' ) ) ;
10+ beforeEach ( inject ( function ( _$httpBackend_ , $rootScope , $controller ) {
11+ $httpBackend = _$httpBackend_ ;
12+ $httpBackend . expectGET ( 'phones/phones.json' ) .
13+ respond ( [ { name : 'Nexus S' } , { name : 'Motorola DROID' } ] ) ;
1014
11- beforeEach ( inject ( function ( $controller ) {
12- scope = { } ;
13- ctrl = $controller ( 'PhoneListCtrl' , { $scope :scope } ) ;
15+ scope = $rootScope . $new ( ) ;
16+ ctrl = $controller ( 'PhoneListCtrl' , { $scope : scope } ) ;
1417 } ) ) ;
1518
1619
20+ it ( 'should create "phones" model with 2 phones fetched from xhr' , function ( ) {
21+ expect ( scope . phones ) . toBeUndefined ( ) ;
22+ $httpBackend . flush ( ) ;
23+
24+ expect ( scope . phones ) . toEqual ( [ { name : 'Nexus S' } ,
25+ { name : 'Motorola DROID' } ] ) ;
26+ } ) ;
27+
28+
1729 it ( 'should set the default value of orderProp model' , function ( ) {
1830 expect ( scope . orderProp ) . toBe ( 'age' ) ;
1931 } ) ;
You can’t perform that action at this time.
0 commit comments