Merge branch 'master' into 14716-webdav-cluster-config
[arvados.git] / apps / workbench / test / integration / jobs_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'fileutils'
6 require 'tmpdir'
7
8 require 'integration_helper'
9
10 class JobsTest < ActionDispatch::IntegrationTest
11   setup do
12       need_javascript
13   end
14
15   def fakepipe_with_log_data
16     content =
17       "2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 1\n" +
18       "2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 2\n" +
19       "2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 3\n"
20     StringIO.new content, 'r'
21   end
22
23   [
24     ['active', true],
25     ['job_reader2', false],
26   ].each do |user, readable|
27     test "view job with components as #{user} user" do
28       Rails.configuration.Users.AnonymousUserToken = ""
29       job = api_fixture('jobs')['running_job_with_components']
30       component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
31       component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
32       component2_child1 = api_fixture('jobs')['previous_job_run']
33       component2_child2 = api_fixture('jobs')['running']
34
35       visit page_with_token(user, "/jobs/#{job['uuid']}")
36       assert page.has_text? job['script_version']
37       assert page.has_no_text? 'script_parameters'
38
39       # The job_reader2 is allowed to read job, component2, and component2_child1,
40       # and component2_child2 only as a component of the pipeline component2
41       if readable
42         assert page.has_link? 'component1'
43         assert page.has_link? 'component2'
44       else
45         assert page.has_no_link? 'component1'
46         assert page.has_link? 'component2'
47       end
48
49       if readable
50         click_link('component1')
51         within('.panel-collapse') do
52           assert(has_text? component1['uuid'])
53           assert(has_text? component1['script_version'])
54           assert(has_text? 'script_parameters')
55         end
56         click_link('component1')
57       end
58
59       click_link('component2')
60       within('.panel-collapse') do
61         assert(has_text? component2['uuid'])
62         assert(has_text? component2['script_version'])
63         assert(has_no_text? 'script_parameters')
64         assert(has_link? 'previous')
65         assert(has_link? 'running')
66
67         click_link('previous')
68         within('.panel-collapse') do
69           assert(has_text? component2_child1['uuid'])
70           assert(has_text? component2_child1['script_version'])
71         end
72         click_link('previous')
73
74         click_link('running')
75         within('.panel-collapse') do
76           assert(has_text? component2_child2['uuid'])
77           if readable
78             assert(has_text? component2_child2['script_version'])
79           else
80             assert(has_no_text? component2_child2['script_version'])
81           end
82         end
83       end
84     end
85   end
86 end