15258: Explicitly require libs instead of relying on autoloading.
[arvados.git] / apps / workbench / test / integration / application_layout_test.rb
index 5ce850dd1af15b00c10517d4a34bfaea383cbde5..51c3720985a85e0fbfd3ebd60ff1473134af78ab 100644 (file)
@@ -1,21 +1,21 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'integration_helper'
-require 'selenium-webdriver'
-require 'headless'
+require 'config_validators'
 
 class ApplicationLayoutTest < ActionDispatch::IntegrationTest
-  setup do
-    headless = Headless.new
-    headless.start
-    Capybara.current_driver = :selenium
-
-    @user_profile_form_fields = Rails.configuration.user_profile_form_fields
-  end
+  # These tests don't do state-changing API calls. Save some time by
+  # skipping the database reset.
+  reset_api_fixtures :after_each_test, false
+  reset_api_fixtures :after_suite, true
 
-  teardown do
-    Rails.configuration.user_profile_form_fields = @user_profile_form_fields
+  setup do
+    need_javascript
   end
 
-  def verify_homepage_with_profile user, invited, has_profile
+  def verify_homepage user, invited, has_profile
     profile_config = Rails.configuration.user_profile_form_fields
 
     if !user
@@ -23,39 +23,56 @@ class ApplicationLayoutTest < ActionDispatch::IntegrationTest
       assert page.has_text?('The "Log in" button below will show you a Google sign-in page'), 'Not found text - google sign in page'
       assert page.has_no_text?('My projects'), 'Found text - My projects'
       assert page.has_link?("Log in to #{Rails.configuration.site_name}"), 'Not found text - log in to'
-    elsif profile_config && !has_profile && user['is_active']
-      add_profile user
     elsif user['is_active']
-      assert page.has_text?('My projects'), 'Not found text - My projects'
-      assert page.has_text?('Projects shared with me'), 'Not found text - Project shared with me'
-      assert page.has_no_text?('Save profile'), 'Found text - Save profile'
+      if profile_config && !has_profile
+        assert page.has_text?('Save profile'), 'No text - Save profile'
+      else
+        assert page.has_link?("Projects"), 'Not found link - Projects'
+        page.find("#projects-menu").click
+        assert_selector 'a', text: 'Search all projects'
+        assert_no_selector 'a', text: 'Browse public projects'
+        assert_selector 'a', text: 'Add a new project'
+        assert_selector 'li[class="dropdown-header"]', text: 'My projects'
+      end
     elsif invited
       assert page.has_text?('Please check the box below to indicate that you have read and accepted the user agreement'), 'Not found text - Please check the box below . . .'
-      assert page.has_no_text?('Save profile'), 'Found text - Save profile'
     else
       assert page.has_text?('Your account is inactive'), 'Not found text - Your account is inactive'
-      assert page.has_no_text?('Save profile'), 'Found text - Save profile'
     end
 
     within('.navbar-fixed-top') do
       if !user
+        assert_text Rails.configuration.site_name.downcase
+        assert_no_selector 'a', text: Rails.configuration.site_name.downcase
         assert page.has_link?('Log in'), 'Not found link - Log in'
       else
         # my account menu
-        assert page.has_link?("#{user['email']}"), 'Not found link - email'
-        find('a', text: "#{user['email']}").click
+        assert_selector 'a', text: Rails.configuration.site_name.downcase
+        assert(page.has_link?("notifications-menu"), 'no user menu')
+        page.find("#notifications-menu").click
         within('.dropdown-menu') do
           if user['is_active']
             assert page.has_no_link?('Not active'), 'Found link - Not active'
             assert page.has_no_link?('Sign agreements'), 'Found link - Sign agreements'
 
-            assert page.has_link?('Manage account'), 'No link - Manage account'
+            assert_selector "a[href=\"/projects/#{user['uuid']}\"]", text: 'Home project'
+            assert_selector "a[href=\"/users/#{user['uuid']}/virtual_machines\"]", text: 'Virtual machines'
+            assert_selector "a[href=\"/repositories\"]", text: 'Repositories'
+            assert_selector "a[href=\"/current_token\"]", text: 'Current token'
+            assert_selector "a[href=\"/users/#{user['uuid']}/ssh_keys\"]", text: 'SSH keys'
 
             if profile_config
-              assert page.has_link?('Manage profile'), 'No link - Manage profile'
+              assert_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
             else
-              assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
+              assert_no_selector "a[href=\"/users/#{user['uuid']}/profile\"]", text: 'Manage profile'
             end
+          else
+            assert_no_selector 'a', text: 'Home project'
+            assert page.has_no_link?('Virtual machines'), 'Found link - Virtual machines'
+            assert page.has_no_link?('Repositories'), 'Found link - Repositories'
+            assert page.has_no_link?('Current token'), 'Found link - Current token'
+            assert page.has_no_link?('SSH keys'), 'Found link - SSH keys'
+            assert page.has_no_link?('Manage profile'), 'Found link - Manage profile'
           end
           assert page.has_link?('Log out'), 'No link - Log out'
         end
@@ -68,6 +85,8 @@ class ApplicationLayoutTest < ActionDispatch::IntegrationTest
     within('.navbar-fixed-top') do
       page.find("#arv-help").click
       within('.dropdown-menu') do
+        assert_no_selector 'a', text:'Getting Started ...'
+        assert_selector 'a', text:'Public Pipelines and Data sets'
         assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
         assert page.has_link?('API Reference'), 'No link - API Reference'
         assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
@@ -79,192 +98,221 @@ class ApplicationLayoutTest < ActionDispatch::IntegrationTest
   end
 
   def verify_system_menu user
-    if user && user['is_active']
-      look_for_add_new = nil
+    if user && user['is_admin']
+      assert page.has_link?('system-menu'), 'No link - system menu'
       within('.navbar-fixed-top') do
         page.find("#system-menu").click
-        if user['is_admin']
-          within('.dropdown-menu') do
-            assert page.has_text?('Groups'), 'No text - Groups'
-            assert page.has_link?('Repositories'), 'No link - Repositories'
-            assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
-            assert page.has_link?('SSH keys'), 'No link - SSH keys'
-            assert page.has_link?('API tokens'), 'No link - API tokens'
-            find('a', text: 'Users').click
-            look_for_add_new = 'Add a new user'
-          end
-        else
-          within('.dropdown-menu') do
-            assert page.has_no_text?('Users'), 'Found text - Users'
-            assert page.has_no_link?('Repositories'), 'Found link - Repositories'
-            assert page.has_no_link?('Virtual machines'), 'Found link - Virtual machines'
-            assert page.has_no_link?('SSH keys'), 'Found link - SSH keys'
-            assert page.has_no_link?('API tokens'), 'Found link - API tokens'
-
-            find('a', text: 'Groups').click
-            look_for_add_new = 'Add a new group'
-          end
+        within('.dropdown-menu') do
+          assert page.has_text?('Groups'), 'No text - Groups'
+          assert page.has_link?('Repositories'), 'No link - Repositories'
+          assert page.has_link?('Virtual machines'), 'No link - Virtual machines'
+          assert page.has_link?('SSH keys'), 'No link - SSH keys'
+          assert page.has_link?('API tokens'), 'No link - API tokens'
+          find('a', text: 'Users').click
         end
       end
-      if look_for_add_new
-        assert page.has_text? look_for_add_new
-      end
+      assert page.has_text? 'Add a new user'
     else
-      assert page.has_no_link?('#system-menu'), 'Found link - system menu'
+      assert page.has_no_link?('system-menu'), 'Found link - system menu'
+    end
+  end
+
+  [
+    [nil, nil, false, false],
+    ['inactive', api_fixture('users')['inactive'], true, false],
+    ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
+    ['active', api_fixture('users')['active'], true, true],
+    ['admin', api_fixture('users')['admin'], true, true],
+    ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
+    ['active_no_prefs_profile_no_getting_started_shown',
+        api_fixture('users')['active_no_prefs_profile_no_getting_started_shown'], true, false],
+  ].each do |token, user, invited, has_profile|
+
+    test "visit home page for user #{token}" do
+      if !token
+        visit ('/')
+      else
+        visit page_with_token(token)
+      end
+
+      check_help_menu
+      verify_homepage user, invited, has_profile
+      verify_system_menu user
     end
   end
 
-  # test manage_account page
-  def verify_manage_account user
-    if user && user['is_active']
+  [
+    [false, false],
+    ['http://wb2.example.org//', false],
+    ['ftp://wb2.example.org', false],
+    ['wb2.example.org', false],
+    ['http://wb2.example.org', true],
+    ['https://wb2.example.org', true],
+    ['http://wb2.example.org/', true],
+    ['https://wb2.example.org/', true],
+  ].each do |wb2_url_config, wb2_menu_appear|
+    test "workbench2_url=#{wb2_url_config} should#{wb2_menu_appear ? '' : ' not'} show WB2 menu" do
+      Rails.configuration.workbench2_url = wb2_url_config
+      assert_equal wb2_menu_appear, ConfigValidators::validate_wb2_url_config()
+
+      visit page_with_token('active')
       within('.navbar-fixed-top') do
-        find('a', text: "#{user['email']}").click
+        page.find("#notifications-menu").click
         within('.dropdown-menu') do
-          find('a', text: 'Manage account').click
+          assert_equal wb2_menu_appear, page.has_text?('Go to Workbench 2')
         end
       end
+    end
+  end
 
-      # now in manage account page
-      assert page.has_text?('Virtual Machines'), 'No text - Virtual Machines'
-      assert page.has_text?('Repositories'), 'No text - Repositories'
-      assert page.has_text?('SSH Keys'), 'No text - SSH Keys'
-      assert page.has_text?('Current Token'), 'No text - Current Token'
+  [
+    ['active', true],
+    ['active_with_prefs_profile_no_getting_started_shown', false],
+  ].each do |token, getting_started_shown|
+    test "getting started help menu item #{getting_started_shown}" do
+      Rails.configuration.enable_getting_started_popup = true
 
-      assert page.has_text?('The Arvados API token is a secret key that enables the Arvados SDKs to access Arvados'), 'No text - Arvados API token'
+      visit page_with_token(token)
 
-      click_link 'Add new SSH key'
+      if getting_started_shown
+        within '.navbar-fixed-top' do
+          find('.help-menu > a').click
+          find('.help-menu .dropdown-menu a', text: 'Getting Started ...').click
+        end
+      end
 
       within '.modal-content' do
-        assert page.has_text?('Public Key'), 'No text - Public Key'
-        assert page.has_button?('Cancel'), 'No button - Cancel'
-        assert page.has_button?('Submit'), 'No button - Submit'
-
-        page.find_field('public_key').set 'first test with an incorrect ssh key value'
-        click_button 'Submit'
-        assert page.has_text?('Public key does not appear to be a valid ssh-rsa or dsa public key'), 'No text - Public key does not appear to be a valid'
-
-        public_key_str = api_fixture('authorized_keys')['active']['public_key']
-        page.find_field('public_key').set public_key_str
-        page.find_field('name').set 'added_in_test'
-        click_button 'Submit'
-        assert page.has_text?('Public key already exists in the database, use a different key.'), 'No text - Public key already exists'
-
-        new_key = SSHKey.generate
-        page.find_field('public_key').set new_key.ssh_public_key
-        page.find_field('name').set 'added_in_test'
-        click_button 'Submit'
-      end
+        assert_text 'Getting Started'
+        assert_selector 'button:not([disabled])', text: 'Next'
+        assert_no_selector 'button:not([disabled])', text: 'Prev'
+
+        # Use Next button to enable Prev button
+        click_button 'Next'
+        assert_selector 'button:not([disabled])', text: 'Prev'  # Prev button is now enabled
+        click_button 'Prev'
+        assert_no_selector 'button:not([disabled])', text: 'Prev'  # Prev button is again disabled
+
+        # Click Next until last page is reached and verify that it is disabled
+        (0..20).each do |i|   # currently we only have 4 pages, and don't expect to have more than 20 in future
+          click_button 'Next'
+          begin
+            find('button:not([disabled])', text: 'Next')
+          rescue => e
+            break
+          end
+        end
+        assert_no_selector 'button:not([disabled])', text: 'Next'  # Next button is disabled
+        assert_selector 'button:not([disabled])', text: 'Prev'     # Prev button is enabled
+        click_button 'Prev'
+        assert_selector 'button:not([disabled])', text: 'Next'     # Next button is now enabled
 
-      # key must be added. look for it in the refreshed page
-      assert page.has_text?('added_in_test'), 'No text - added_in_test'
+        first('button', text: 'x').click
+      end
+      assert_text 'Recent pipelines and processes' # seeing dashboard now
     end
   end
 
-  # Check manage profile page and add missing profile to the user
-  def add_profile user
-    assert page.has_no_text?('My projects'), 'Found text - My projects'
-    assert page.has_no_text?('Projects shared with me'), 'Found text - Projects shared with me'
-
-    assert page.has_text?('Profile'), 'No text - Profile'
-    assert page.has_text?('First name'), 'No text - First name'
-    assert page.has_text?('Last name'), 'No text - Last name'
-    assert page.has_text?('Identity URL'), 'No text - Identity URL'
-    assert page.has_text?('Email'), 'No text - Email'
-    assert page.has_text?(user['email']), 'No text - user email'
-
-    # Using the default profile which has message and one required field
-
-    # Save profile without filling in the required field. Expect to be back in this profile page again
-    click_button "Save profile"
-    assert page.has_text?('Profile'), 'No text - Profile'
-    assert page.has_text?('First name'), 'No text - First name'
-    assert page.has_text?('Last name'), 'No text - Last name'
-    assert page.has_text?('Save profile'), 'No text - Save profile'
-
-    # This time fill in required field and then save. Expect to go to requested page after that.
-    profile_message = Rails.configuration.user_profile_form_message
-    required_field_title = ''
-    required_field_key = ''
-    profile_config = Rails.configuration.user_profile_form_fields
-    profile_config.andand.each do |entry|
-      if entry['required']
-        required_field_key = entry['key']
-        required_field_title = entry['form_field_title']
-      end
-    end
+  test "test arvados_public_data_doc_url config unset" do
+    Rails.configuration.arvados_public_data_doc_url = false
 
-    assert page.has_text? profile_message.gsub(/<.*?>/,'')
-    assert page.has_text?(required_field_title), 'No text - configured required field title'
+    visit page_with_token('active')
+    within '.navbar-fixed-top' do
+      find('.help-menu > a').click
 
-    page.find_field('user[prefs][:profile][:'+required_field_key+']').set 'value to fill required field'
+      assert_no_selector 'a', text:'Public Pipelines and Data sets'
+      assert_no_selector 'a', text:'Getting Started ...'
 
-    click_button "Save profile"
-    # profile saved and in profile page now with success
-    assert page.has_text?('Thank you for filling in your profile'), 'No text - Thank you for filling'
-    click_link 'Back to work!'
+      assert page.has_link?('Tutorials and User guide'), 'No link - Tutorials and User guide'
+      assert page.has_link?('API Reference'), 'No link - API Reference'
+      assert page.has_link?('SDK Reference'), 'No link - SDK Reference'
+      assert page.has_link?('Show version / debugging info ...'), 'No link - Show version / debugging info'
+      assert page.has_link?('Report a problem ...'), 'No link - Report a problem'
+    end
+  end
 
-    # profile saved and in home page now
-    assert page.has_text?('My projects'), 'No text - My projects'
-    assert page.has_text?('Projects shared with me'), 'No text - Projects shared with me'
+  test "no SSH public key notification when shell_in_a_box_url is configured" do
+    Rails.configuration.shell_in_a_box_url = 'example.com'
+    visit page_with_token('job_reader')
+    click_link 'notifications-menu'
+    assert_no_selector 'a', text:'Click here to set up an SSH public key for use with Arvados.'
+    assert_selector 'a', text:'Click here to learn how to run an Arvados Crunch pipeline'
   end
 
-  [
-    [nil, nil, false, false],
-    ['inactive', api_fixture('users')['inactive'], true, false],
-    ['inactive_uninvited', api_fixture('users')['inactive_uninvited'], false, false],
-    ['active', api_fixture('users')['active'], true, true],
-    ['admin', api_fixture('users')['admin'], true, true],
-    ['active_no_prefs', api_fixture('users')['active_no_prefs'], true, false],
-    ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
-  ].each do |token, user, invited, has_profile|
+   [
+    ['Repositories', nil, 'active/crunchdispatchtest'],
+    ['Virtual machines', nil, 'testvm.shell'],
+    ['SSH keys', nil, 'public_key'],
+    ['Links', nil, 'link_class'],
+    ['Groups', nil, 'All users'],
+    ['Compute nodes', nil, 'ping_secret'],
+    ['Keep services', nil, 'service_ssl_flag'],
+    ['Keep disks', nil, 'bytes_free'],
+  ].each do |page_name, add_button_text, look_for|
+    test "test system menu #{page_name} link" do
+      visit page_with_token('admin')
+      within('.navbar-fixed-top') do
+        page.find("#system-menu").click
+        within('.dropdown-menu') do
+          assert_selector 'a', text: page_name
+          find('a', text: page_name).click
+        end
+      end
 
-    test "visit home page when profile is configured for user #{token}" do
-      # Our test config enabled profile by default. So, no need to update config
-      if !token
-        visit ('/')
+      # click the add button if it exists
+      if add_button_text
+        assert_selector 'button', text: "Add a new #{add_button_text}"
+        find('button', text: "Add a new #{add_button_text}").click
       else
-        visit page_with_token(token)
+        assert_no_selector 'button', text:"Add a new"
       end
 
-      verify_homepage_with_profile user, invited, has_profile
+      # look for unique property in the current page
+      assert_text look_for
     end
+  end
 
-    test "visit home page when profile not configured for user #{token}" do
-      Rails.configuration.user_profile_form_fields = false
+  [
+    ['active', false],
+    ['admin', true],
+  ].each do |token, is_admin|
+    test "visit dashboard as #{token}" do
+      visit page_with_token(token)
 
-      if !token
-        visit ('/')
-      else
-        visit page_with_token(token)
+      assert_text 'Recent pipelines and processes' # seeing dashboard now
+      within('.recent-processes-actions') do
+        assert page.has_link?('Run a process')
+        assert page.has_link?('All processes')
       end
 
-      verify_homepage_with_profile user, invited, has_profile
-    end
+      within('.recent-processes') do
 
-    test "check help for user #{token}" do
-      if !token
-        visit ('/')
-      else
-        visit page_with_token(token)
-      end
+        within('.row-zzzzz-xvhdp-cr4runningcntnr') do
+          assert_text 'running'
+        end
 
-      check_help_menu
-    end
-  end
+        assert_text 'zzzzz-d1hrv-twodonepipeline'
+        within('.row-zzzzz-d1hrv-twodonepipeline')do
+          assert_text 'No output'
+        end
 
-  [
-    ['active', api_fixture('users')['active']],
-    ['admin', api_fixture('users')['admin']],
-  ].each do |token, user|
+        assert_text 'completed container request'
+        within('.row-zzzzz-xvhdp-cr4completedctr')do
+          assert page.has_link? 'foo_file'
+        end
+      end
 
-    test "test system menu for user #{token}" do
-      visit page_with_token(token)
-      verify_system_menu user
-    end
+      within('.compute-node-actions') do
+        if is_admin
+          assert page.has_link?('All nodes')
+        else
+          assert page.has_no_link?('All nodes')
+        end
+      end
 
-    test "test manage account for user #{token}" do
-      visit page_with_token(token)
-      verify_manage_account user
+      within('.compute-node-summary-pane') do
+        click_link 'Details'
+        assert_text 'compute0'
+      end
     end
   end
 end