2872: Merge branch 'master' into 2872-folder-nav
[arvados.git] / apps / workbench / test / integration / smoke_test.rb
1 require 'integration_helper'
2 require 'uri'
3
4 class SmokeTest < ActionDispatch::IntegrationTest
5   setup do
6     Capybara.current_driver = Capybara.javascript_driver
7   end
8
9   def assert_visit_success(allowed=[200])
10     assert_includes(allowed, status_code,
11                     "#{current_url} returned #{status_code}, not one of " +
12                     allowed.inspect)
13   end
14
15   def all_links_in(find_spec, text_regexp=//)
16     all(find_spec + ' a').collect { |tag|
17       if tag[:href].nil? or tag[:href].empty? or (tag.text !~ text_regexp)
18         nil
19       else
20         url = URI(tag[:href])
21         url.host.nil? ? url.path : nil
22       end
23     }.compact
24   end
25
26   test "all first-level links succeed" do
27     visit page_with_token('active_trustedclient', '/')
28     assert_visit_success
29     click_link 'notifications-menu'
30     urls = [all_links_in('nav'),
31             all_links_in('.navbar', /^Manage /)].flatten
32     seen_urls = ['/']
33     while not (url = urls.shift).nil?
34       next if seen_urls.include? url
35       visit url
36       seen_urls << url
37       assert_visit_success
38       # Uncommenting the line below lets you crawl the entire site for a
39       # more thorough test.
40       # urls += all_links_in('body')
41     end
42   end
43 end