workbench: Add basic smoke test.
authorBrett Smith <brett@curoverse.com>
Fri, 21 Mar 2014 21:24:07 +0000 (17:24 -0400)
committerBrett Smith <brett@curoverse.com>
Fri, 21 Mar 2014 21:24:25 +0000 (17:24 -0400)
This visits all the link on a user's front page and makes sure they
all return 200.

It's easy to extend this to crawl the entire site, checking for
success.  I've included the code for that.  We need to squash some
bugs and check the timing before we start doing that, though.

This overlaps api_client_authorizations_test, so I deleted that.

apps/workbench/test/integration/api_client_authorizations_test.rb [deleted file]
apps/workbench/test/integration/smoke_test.rb [new file with mode: 0644]

diff --git a/apps/workbench/test/integration/api_client_authorizations_test.rb b/apps/workbench/test/integration/api_client_authorizations_test.rb
deleted file mode 100644 (file)
index 6312034..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-require 'integration_helper'
-
-class ApiClientAuthorizationsTest < ActionDispatch::IntegrationTest
-  test "try loading Manage API tokens page" do
-    Capybara.current_driver = Capybara.javascript_driver
-    visit page_with_token('admin_trustedclient')
-    click_link 'user-menu'
-    click_link 'Manage API tokens'
-    assert_equal 200, status_code
-  end
-end
diff --git a/apps/workbench/test/integration/smoke_test.rb b/apps/workbench/test/integration/smoke_test.rb
new file mode 100644 (file)
index 0000000..700c8e6
--- /dev/null
@@ -0,0 +1,39 @@
+require 'integration_helper'
+require 'uri'
+
+class SmokeTest < ActionDispatch::IntegrationTest
+  def assert_visit_success(allowed=[200])
+    assert_includes(allowed, status_code,
+                    "#{current_url} returned #{status_code}, not one of " +
+                    allowed.inspect)
+  end
+
+  def all_links_in(find_spec, text_regexp=//)
+    find(find_spec).all('a').collect { |tag|
+      if tag[:href].nil? or tag[:href].empty? or (tag.text !~ text_regexp)
+        nil
+      else
+        url = URI(tag[:href])
+        url.host.nil? ? url.path : nil
+      end
+    }.compact
+  end
+
+  test "all first-level links succeed" do
+    visit page_with_token('active_trustedclient', '/')
+    assert_visit_success
+    click_link 'user-menu'
+    urls = [all_links_in('.arvados-nav'),
+            all_links_in('.navbar', /^Manage /)].flatten
+    seen_urls = ['/']
+    while not (url = urls.shift).nil?
+      next if seen_urls.include? url
+      visit url
+      seen_urls << url
+      assert_visit_success
+      # Uncommenting the line below lets you crawl the entire site for a
+      # more thorough test.
+      # urls += all_links_in('body')
+    end
+  end
+end