Merge branch '8784-dir-listings'
[arvados.git] / apps / workbench / test / integration / work_units_test.rb
index eded53e2166a2efbba45dfdbeb859c22e5bca359..ed214d62cc674d62d479fac90cc00aff9ee95d76 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
 require 'helpers/fake_websocket_helper'
 require 'integration_helper'
 
@@ -60,11 +64,11 @@ class WorkUnitsTest < ActionDispatch::IntegrationTest
   end
 
   [
-    ['jobs', 'running_job_with_components', true],
-    ['pipeline_instances', 'components_is_jobspec', false],
+    ['jobs', 'running_job_with_components', true, true],
+    ['pipeline_instances', 'components_is_jobspec', true, true],
     ['containers', 'running', false],
     ['container_requests', 'running', true],
-  ].each do |type, fixture, cancelable|
+  ].each do |type, fixture, cancelable, confirm_cancellation|
     test "cancel button for #{type}/#{fixture}" do
       if cancelable
         need_selenium 'to cancel'
@@ -75,11 +79,31 @@ class WorkUnitsTest < ActionDispatch::IntegrationTest
 
       assert_text 'created_at'
       if cancelable
-        assert_selector 'button', text: 'Cancel'
-        click_button 'Cancel'
+        assert_text 'priority: 1' if type.include?('container')
+        if type.include?('pipeline')
+          assert_selector 'a', text: 'Pause'
+          first('a,link', text: 'Pause').click
+        else
+          assert_selector 'button', text: 'Cancel'
+          first('a,button', text: 'Cancel').click
+        end
+        if confirm_cancellation
+          alert = page.driver.browser.switch_to.alert
+          alert.accept
+        end
         wait_for_ajax
       end
-      assert_no_selector 'button', text: 'Cancel'
+
+      if type.include?('pipeline')
+        assert_selector 'a', text: 'Resume'
+        assert_no_selector 'a', text: 'Pause'
+      elsif type.include?('job')
+        assert_text 'Cancelled'
+        assert_text 'Paused'  # this job has a pipeline child which was also cancelled
+        assert_no_selector 'button', text: 'Cancel'
+      elsif cancelable
+        assert_text 'priority: 0'
+      end
     end
   end
 
@@ -107,8 +131,8 @@ class WorkUnitsTest < ActionDispatch::IntegrationTest
   end
 
   [
-    ['Two Part Pipeline Template', 'part-one', 'Provide a value for the following'],
-    ['Workflow with input specifications', 'this workflow has inputs specified', 'Provide a value for the following'],
+    ['Pipeline with default input specifications', 'part-one', 'Provide values for the following'],
+    ['Workflow with default input specifications', 'this workflow has inputs specified', 'Provide a value for the following'],
   ].each do |template_name, preview_txt, process_txt|
     test "run a process using template #{template_name} from dashboard" do
       visit page_with_token('admin')
@@ -116,7 +140,7 @@ class WorkUnitsTest < ActionDispatch::IntegrationTest
 
       within('.recent-processes-actions') do
         assert page.has_link?('All processes')
-        find('a', text: 'Run a pipeline').click
+        find('a', text: 'Run a process').click
       end
 
       # in the chooser, verify preview and click Next button
@@ -129,6 +153,10 @@ class WorkUnitsTest < ActionDispatch::IntegrationTest
       # in the process page now
       assert_text process_txt
       assert_selector 'a', text: template_name
+
+      assert_equal "Set value for ex_string_def", find('div.form-group > div > p.form-control-static > a', text: "hello-testing-123")[:"data-title"]
+
+      page.assert_selector 'a.disabled,button.disabled', text: 'Run'
     end
   end
 
@@ -205,4 +233,70 @@ class WorkUnitsTest < ActionDispatch::IntegrationTest
       assert_text(expect_log_text)
     end
   end
+
+  [
+    ['jobs', 'active', 'running_job_with_components', 'component1', '/jobs/zzzzz-8i9sb-jyq01m7in1jlofj#Log'],
+    ['pipeline_instances', 'active', 'pipeline_in_running_state', 'foo', '/jobs/zzzzz-8i9sb-pshmckwoma9plh7#Log'],
+    ['pipeline_instances', nil, 'pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', 'foo', 'Log unavailable'],
+  ].each do |type, token, fixture, child, log_link|
+    test "link_to_log for #{fixture} for #{token}" do
+      obj = api_fixture(type)[fixture]
+      if token
+        visit page_with_token token, "/#{type}/#{obj['uuid']}"
+      else
+        Rails.configuration.anonymous_user_token =
+          api_fixture("api_client_authorizations", "anonymous", "api_token")
+        visit "/#{type}/#{obj['uuid']}"
+      end
+
+      click_link(child)
+
+      if token
+        assert_selector "a[href=\"#{log_link}\"]"
+      else
+        assert_text log_link
+      end
+    end
+  end
+
+  test 'Run from workflows index page' do
+    visit page_with_token('active', '/workflows')
+
+    wf_count = page.all('a[data-original-title="show workflow"]').count
+    assert_equal true, wf_count>0
+
+    # Run one of the workflows
+    wf_name = 'Workflow with input specifications'
+    within('tr', text: wf_name) do
+      find('a,button', text: 'Run').click
+    end
+
+    # Choose project for the container_request being created
+    within('.modal-dialog') do
+      find('.selectable', text: 'A Project').click
+      find('button', text: 'Choose').click
+    end
+
+    # In newly created container_request page now
+    assert_text 'A Project' # CR created in "A Project"
+    assert_text "This container request was created from the workflow #{wf_name}"
+    assert_match /Provide a value for .* then click the \"Run\" button to start the workflow/, page.text
+  end
+
+  test 'Run workflow from show page' do
+    visit page_with_token('active', '/workflows/zzzzz-7fd4e-validwithinputs')
+
+    find('a,button', text: 'Run this workflow').click
+
+    # Choose project for the container_request being created
+    within('.modal-dialog') do
+      find('.selectable', text: 'A Project').click
+      find('button', text: 'Choose').click
+    end
+
+    # In newly created container_request page now
+    assert_text 'A Project' # CR created in "A Project"
+    assert_text "This container request was created from the workflow"
+    assert_match /Provide a value for .* then click the \"Run\" button to start the workflow/, page.text
+  end
 end