Merge branch '15522-arvmount-ops-encoding'
[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       job = api_fixture('jobs')['running_job_with_components']
29       component1 = api_fixture('jobs')['completed_job_in_publicly_accessible_project']
30       component2 = api_fixture('pipeline_instances')['running_pipeline_with_complete_job']
31       component2_child1 = api_fixture('jobs')['previous_job_run']
32       component2_child2 = api_fixture('jobs')['running']
33
34       visit page_with_token(user, "/jobs/#{job['uuid']}")
35       assert page.has_text? job['script_version']
36       assert page.has_no_text? 'script_parameters'
37
38       # The job_reader2 is allowed to read job, component2, and component2_child1,
39       # and component2_child2 only as a component of the pipeline component2
40       if readable
41         assert page.has_link? 'component1'
42         assert page.has_link? 'component2'
43       else
44         assert page.has_no_link? 'component1'
45         assert page.has_link? 'component2'
46       end
47
48       if readable
49         click_link('component1')
50         within('.panel-collapse') do
51           assert(has_text? component1['uuid'])
52           assert(has_text? component1['script_version'])
53           assert(has_text? 'script_parameters')
54         end
55         click_link('component1')
56       end
57
58       click_link('component2')
59       within('.panel-collapse') do
60         assert(has_text? component2['uuid'])
61         assert(has_text? component2['script_version'])
62         assert(has_no_text? 'script_parameters')
63         assert(has_link? 'previous')
64         assert(has_link? 'running')
65
66         click_link('previous')
67         within('.panel-collapse') do
68           assert(has_text? component2_child1['uuid'])
69           assert(has_text? component2_child1['script_version'])
70         end
71         click_link('previous')
72
73         click_link('running')
74         within('.panel-collapse') do
75           assert(has_text? component2_child2['uuid'])
76           if readable
77             assert(has_text? component2_child2['script_version'])
78           else
79             assert(has_no_text? component2_child2['script_version'])
80           end
81         end
82       end
83     end
84   end
85 end