Merge branch 'master' into 4559-long-component-names
[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     Capybara.current_driver = Capybara.javascript_driver
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     Capybara.current_driver = Capybara.javascript_driver
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     Capybara.current_driver = Capybara.javascript_driver
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 end