4878: now the test works!
[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, false],
78     ['job_with_latest_version', true, false, false],
79     ['job_with_latest_version', true, true, false],
80     ['job_with_latest_version', true, true, true],
81   ].each do |job_name, expect_options, use_options, click_option|
82     test "Rerun #{job_name} job, expect options #{expect_options},
83           use options #{use_options} and click option #{click_option}" do
84       need_javascript
85
86       job = api_fixture('jobs')[job_name]
87       visit page_with_token 'active', '/jobs/'+job['uuid']
88
89       assert_selector 'a,button', text: 'Re-run same version'
90       if expect_options
91         assert_text 'supplied_script_version: master'
92         assert_selector 'a,button', text: 'Re-run with options'
93       else
94         assert_text 'supplied_script_version: (none)'
95         assert_no_selector 'a,button', text: 'Re-run with options'
96       end
97
98       # Now re-run the job
99       if use_options
100         assert_triggers_dom_event 'shown.bs.modal' do
101           find('a,button', text: 'Re-run with options...').click
102         end
103         within('.modal-dialog') do
104           assert_selector 'a,button', text: 'Run now'
105           assert_selector 'a,button', text: 'Cancel'
106           page.choose('use_script_same') if click_option
107           find('button', text: 'Run now').click
108         end
109       else
110         find('a,button', text: 'Re-run same version').click
111       end
112
113       # We see Fiddlesticks, but let's make sure the correct script version is sought.
114       if use_options && !click_option
115         assert_text "Script version #{job['supplied_script_version']} does not resolve to a commit"
116       else
117         assert_text "Script version #{job['script_version']} does not resolve to a commit"
118       end
119     end
120   end
121 end