From 0a604bdb90e9dff9399bae0fb4941fe46cc7e9f9 Mon Sep 17 00:00:00 2001 From: Kenneth R. Culp Date: Tue, 26 Apr 2011 09:54:08 -0700 Subject: Tutorial files for your perusal. --- docs/tutorial.step_10.ngdoc | 109 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 docs/tutorial.step_10.ngdoc (limited to 'docs/tutorial.step_10.ngdoc') diff --git a/docs/tutorial.step_10.ngdoc b/docs/tutorial.step_10.ngdoc new file mode 100644 index 00000000..a993bee1 --- /dev/null +++ b/docs/tutorial.step_10.ngdoc @@ -0,0 +1,109 @@ +@workInProgress +@ngdoc overview +@name Tutorial: Step 10 +@description + + + + + + + + +
{@link tutorial.step_9 Previous}{@link http://angular.github.com/angular-phonecat/step-10/app Example}{@link tutorial Tutorial Home}{@link +https://github.com/angular/angular-phonecat/commit/abe1e13c7d9e725fdd3b811ca5ec28ea0d973aab Code +Diff}{@link tutorial.step_11 Next}
+ +In this step we will add a phone image swapping feature. We want to be able to click on a +thumbnail image in the phone details page, and have that action change the large phone image to +match the selection. + +__`app/partials/phone-detail.html`.__ +
+
+
+

{{phone.name}}

+ +

{{phone.description}}

+ + +... +
+ +__`app/js/controllers.js`.__ +
+...
+function PhoneDetailCtrl($xhr) {
+  var self = this;
+
+  $xhr('GET', 'phones/' + self.params.phoneId + '.json', function(code, response) {
+    self.phone = response;
+    self.mainImageUrl = response.images[0];
+  });
+
+  self.setImage = function(imageUrl) {
+    self.mainImageUrl = imageUrl;
+  }
+}
+
+//PhoneDetailCtrl.$inject = ['$xhr'];
+
+ +__`test/e2e/scenarios.js`.__ +
+/* jasmine-like end2end tests go here */
+...
+  describe('Phone detail view', function() {
+
+    beforeEach(function() {
+      browser().navigateTo('../../app/index.html#/phones/nexus-s');
+    });
+
+
+    it('should display nexus-s page', function() {
+      expect(binding('phone.name')).toBe('Nexus S');
+    });
+
+    it('should display "0.large" image as the main phone image', function() {
+       expect(element('img.phone').attr('src')).toBe('img/phones/nexus-s.0.jpg');
+    });
+
+
+    it('should swap main image if a thumbnail image is clicked on', function() {
+      element('.phone-thumbs li:nth-child(3) img').click();
+      expect(element('img.phone').attr('src')).toBe('img/phones/nexus-s.2.jpg');
+
+      element('.phone-thumbs li:nth-child(1) img').click();
+      expect(element('img.phone').attr('src')).toBe('img/phones/nexus-s.0.jpg');
+    });
+  });
+});
+
+ +## Discussion: + +Adding the phone image swapping feature is fairly straightforward: + +- We defined the `mainImageUrl` model variable in the details controller (`PhoneDetailCtrl`) and +set the default value of `mainImageUrl` to the first image in the array of images. +- We created a `setImage` controller method to change `mainImageUrl` to the image clicked on by +the user. +- We registered an `ng:click` handler for thumb images to use the `setImage` controller method. +- And of course, we added e2e tests for our new feature. + + + + + + + + + + +
{@link tutorial.step_9 Previous}{@link http://angular.github.com/angular-phonecat/step-10/app Example}{@link tutorial Tutorial Home}{@link +https://github.com/angular/angular-phonecat/commit/abe1e13c7d9e725fdd3b811ca5ec28ea0d973aab Code +Diff}{@link tutorial.step_11 Next}
-- cgit v1.2.3