Commit cfd44945

mo k <mo@mokhan.ca>
2012-09-18 20:52:34
switch up presenter spec to use dom elements.
1 parent bddf8eb
Changed files (2)
app
assets
javascripts
spec
javascripts
app/assets/javascripts/presenters/new_tutorial_presenter.js.coffee
@@ -1,6 +1,10 @@
 class window.NewTutorialPresenter
   constructor:(@view) ->
 
+  present:() ->
+    @view.add_tag_button.bind 'click', (event) =>
+      @view.tag_list.append('<li><a href="#" class="label">'+@view.tag_input.val()+'</a></li>')
+
   add_tag: (tag) ->
     @view.add_tag('<li><a href="#" class="label">'+tag+'</a></li>')
 
spec/javascripts/presenters/new_tutorial_presenter_spec.js
@@ -1,6 +1,11 @@
 describe ("NewTutorialPresenter", function() {
   beforeEach (function() {
-    view = {add_tag:null};
+    view = {
+      add_tag:null,
+      add_tag_button: $('<button id="add-tag-button">'),
+      tag_list: $('<ul id="tag-list">'),
+      tag_input: $('<input type="text" />'),
+    };
     sut = new NewTutorialPresenter(view);
   });
   var sut;
@@ -14,4 +19,14 @@ describe ("NewTutorialPresenter", function() {
       sut.add_tag('blah');
     });
   });
+  describe ("when the add tag button is clicked", function() {
+    it ("should add the new tag to the list of tags", function() {
+      expect(view.tag_list.html()).toEqual('<li><a href="#" class="label">ruby</a></li>');
+    });
+    beforeEach (function() {
+      sut.present();
+      view.tag_input.val('ruby');
+      view.add_tag_button.trigger('click');
+    });
+  });
 });