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