Commit 1c526417

mo k <mo@mokhan.ca>
2012-09-18 22:55:43
update the preview when url info is received.
1 parent 76db9fb
Changed files (2)
app
assets
javascripts
spec
javascripts
app/assets/javascripts/presenters/new_tutorial_presenter.js.coffee
@@ -18,3 +18,8 @@ class window.NewTutorialPresenter
       @view.hidden_tag_list.val( @view.hidden_tag_list.val() + ', ' + new_tag)
 
   display_url_info:(data) ->
+    @view.preview.heading.val(data.title)
+    @view.preview.heading.text(data.title)
+    @view.preview.description.text(data.description)
+    @view.preview.image.attr('src', data.thumbnail_url)
+    @view.preview.hidden_image_url.val(data.thumbnail_url)
spec/javascripts/presenters/new_tutorial_presenter_spec.js
@@ -5,7 +5,13 @@ describe ("NewTutorialPresenter", function() {
       tag_list: $('<ul id="tag-list">'),
       tag_input: $('<input type="text" />'),
       hidden_tag_list: $('<input type="hidden" />'),
-      url_input: $('<input type="text" />')
+      url_input: $('<input type="text" />'),
+      preview: {
+        heading: $('<h3>'),
+        description: $('<p>'),
+        image: $('<img>'),
+        hidden_image_url: $('<input type="hidden">'),
+      }
     };
     service = {
       retrieve_info_on:null
@@ -54,4 +60,26 @@ describe ("NewTutorialPresenter", function() {
     });
     var url;
   });
+  describe ("when information is received about a url", function() {
+    it ("should update the preview heading", function() {
+      expect(view.preview.heading.text()).toEqual('the title');
+    });
+    it ("should update the preview description", function() {
+      expect(view.preview.description.text()).toEqual('the description');
+    });
+    it ("should update the preview image", function() {
+      expect(view.preview.image.attr('src')).toEqual('http://');
+    });
+    it ("should update the hidden input image url", function() {
+      expect(view.preview.hidden_image_url.val()).toEqual('http://');
+    });
+    beforeEach (function() {
+      var payload = {
+        title: 'the title',
+        description: 'the description',
+        thumbnail_url: 'http://'
+      };
+      sut.display_url_info(payload);
+    });
+  });
 });