whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [37/50] Commit 842b4b1: reset react server app between tests; get initials working
Date Fri, 22 Jan 2016 02:40:57 GMT
Commit 842b4b15a8266d737d9e70ec4929629cf38dd026:
    reset react server app between tests; get initials working


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
spec/form_spec.rb                                            | ++++++++ ---
views/add-comment.js.rb                                      | + -
views/agenda.js.rb                                           | + -
views/main.js.rb                                             | ++ --
------------------------------------------------------------
49 changes: 36 additions, 13 deletions.
------------------------------------------------------------


diff --git a/spec/form_spec.rb b/spec/form_spec.rb
index 38c0f26..40b74e2 100644
--- a/spec/form_spec.rb
+++ b/spec/form_spec.rb
@@ -3,16 +3,19 @@
 require 'ruby2js/filter/react'
 
 describe "forms", type: :feature do
-  before :all do
-    @app, Capybara.app = Capybara.app, ReactServer.new
-    ReactServer.start
-    Dir.chdir File.expand_path('../../views', __FILE__) do
-      @script = Ruby2JS.convert(File.read('app.js.rb'), file: 'app.js.rb')
+  it "has an add-comment form with a disabled Save button" do
+    on_react_server do
+      React.render _AddComment(server: {initials: 'sr'}), document.body do
+        response.end document.body.innerHTML
+      end
     end
-  end
 
-  def on_react_server(&block)
-    page.driver.post('/', @script + ';' + Ruby2JS.convert(block, react: true))
+    expect(page).to have_selector '.modal#comment-form'
+    expect(page).to have_selector '.modal .modal-dialog .modal-header h4',
+      text: 'Enter a comment'
+    expect(page).to have_selector '.modal-body input[value="sr"]'
+    expect(page).to have_selector '.modal-footer button[disabled]',
+      text: 'Save'
   end
 
   it "has an add-comment form with a disabled Save button" do
@@ -31,8 +34,28 @@ def on_react_server(&block)
       text: 'Save'
   end
 
+  # administrivia
+
+  before :all do
+    ReactServer.start
+    Dir.chdir File.expand_path('../../views', __FILE__) do
+      @script = Ruby2JS.convert(File.read('app.js.rb'), file: 'app.js.rb')
+    end
+  end
+
+  before :each do
+    @app, Capybara.app = Capybara.app, ReactServer.new
+  end
+
+  def on_react_server(&block)
+    page.driver.post('/', @script + ';' + Ruby2JS.convert(block, react: true))
+  end
+
+  after :each do
+    Capybara.app = @app
+  end
+
   after :all do
     ReactServer.stop
-    Capybara.app = @app
   end
 end
diff --git a/views/add-comment.js.rb b/views/add-comment.js.rb
index 766dc86..507feb3 100644
--- a/views/add-comment.js.rb
+++ b/views/add-comment.js.rb
@@ -21,7 +21,7 @@ def render
       _div.form_group do
         _label 'Initials', for: 'comment-initials'
         _input.comment_initials!.form_control label: 'Initials',
-          placeholder: 'initials', defaultValue: Server.initials
+          placeholder: 'initials', defaultValue: @@server.initials
       end
 
       #input field: comment text
diff --git a/views/agenda.js.rb b/views/agenda.js.rb
index c8670a2..66e7646 100644
--- a/views/agenda.js.rb
+++ b/views/agenda.js.rb
@@ -103,7 +103,7 @@ def self.next
       date = agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
 
       if date > @@date and (result.title == 'Help' or date < result.title)
-	result = {title: date, href: "../#{date}/"}
+	      result = {title: date, href: "../#{date}/"}
       end
     end
 
diff --git a/views/main.js.rb b/views/main.js.rb
index 872f39b..3be7504 100644
--- a/views/main.js.rb
+++ b/views/main.js.rb
@@ -63,7 +63,7 @@ def route(path, query)
     @item = Main.item = item
   end
 
-  # common render for all pages: header, main, and footer
+  # common layout for all pages: header, main, footer, and forms
   def render
     _Header item: @item
 
@@ -75,7 +75,7 @@ def render
 
     if @item.forms
       @item.forms.each do |form|
-        React.createElement(form, item: @item) if form
+        React.createElement(form, item: @item, server: @@server) if form
       end
     end
   end

Mime
View raw message