closes #7753
[arvados.git] / apps / workbench / test / integration / jobs_test.rb
1 require 'fileutils'
2 require 'tmpdir'
3
4 require 'integration_helper'
5
6 class JobsTest < ActionDispatch::IntegrationTest
7   setup do
8       need_javascript
9   end
10
11   def fakepipe_with_log_data
12     content =
13       "2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 1\n" +
14       "2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 2\n" +
15       "2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 3\n"
16     StringIO.new content, 'r'
17   end
18
19   test "add job description" do
20     job = api_fixture('jobs')['nearly_finished_job']
21     visit page_with_token("active", "/jobs/#{job['uuid']}")
22
23     # edit job description
24     within('.arv-description-as-subtitle') do
25       find('.fa-pencil').click
26       find('.editable-input textarea').set('*Textile description for job* - "Go to dashboard":/')
27       find('.editable-submit').click
28     end
29
30     # Verify edited description
31     assert_no_text '*Textile description for job*'
32     assert_text 'Textile description for job'
33     assert_selector 'a[href="/"]', text: 'Go to dashboard'
34   end
35
36   test "view job log" do
37     job = api_fixture('jobs')['job_with_real_log']
38
39     IO.expects(:popen).returns(fakepipe_with_log_data)
40
41     visit page_with_token("active", "/jobs/#{job['uuid']}")
42     assert page.has_text? job['script_version']
43
44     find(:xpath, "//a[@href='#Log']").click
45     wait_for_ajax
46     assert page.has_text? 'Started at'
47     assert page.has_text? 'Finished at'
48     assert page.has_text? 'log message 1'
49     assert page.has_text? 'log message 2'
50     assert page.has_text? 'log message 3'
51     assert page.has_no_text? 'Showing only 100 bytes of this log'
52   end
53
54   test 'view partial job log' do
55     # This config will be restored during teardown by ../test_helper.rb:
56     Rails.configuration.log_viewer_max_bytes = 100
57
58     IO.expects(:popen).returns(fakepipe_with_log_data)
59     job = api_fixture('jobs')['job_with_real_log']
60
61     visit page_with_token("active", "/jobs/#{job['uuid']}")
62     assert page.has_text? job['script_version']
63
64     find(:xpath, "//a[@href='#Log']").click
65     wait_for_ajax
66     assert page.has_text? 'Showing only 100 bytes of this log'
67   end
68
69   [
70     ['foobar', false, false],
71     ['job_with_latest_version', true, false],
72     ['job_with_latest_version', true, true],
73   ].each do |job_name, expect_options, use_latest|
74     test "Rerun #{job_name} job, expect options #{expect_options},
75           and use latest version option #{use_latest}" do
76       job = api_fixture('jobs')[job_name]
77       visit page_with_token 'active', '/jobs/'+job['uuid']
78
79       if expect_options
80         assert_text 'supplied_script_version: master'
81       else
82         assert_text 'supplied_script_version: (none)'
83       end
84
85       assert_triggers_dom_event 'shown.bs.modal' do
86         find('a,button', text: 'Re-run job...').click
87       end
88       within('.modal-dialog') do
89         assert_selector 'a,button', text: 'Cancel'
90         if use_latest
91           page.choose("job_script_version_#{job['supplied_script_version']}")
92         end
93         click_on "Run now"
94       end
95
96       # Re-running jobs doesn't currently work because the test API
97       # server has no git repository to check against.  For now, check
98       # that the error message says something appropriate for that
99       # situation.
100       if expect_options && use_latest
101         assert_text "077ba2ad3ea24a929091a9e6ce545c93199b8e57"
102       else
103         assert_text "Script version #{job['script_version']} does not resolve to a commit"
104       end
105     end
106   end
107 end