3782: code review feedback
[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 setup
9     # Set up KEEP_LOCAL_STORE with a file that satisfies
10     # the log collection for job 'job_with_real_log'
11     # TODO: figure out a better way to store this test data
12     # (e.g. in a dummy test fixture)
13     #
14     ENV['KEEP_LOCAL_STORE'] ||= Dir.mktmpdir
15     keepdir = ENV['KEEP_LOCAL_STORE']
16     open(File.join(keepdir, 'cdd549ae79fe6640fa3d5c6261d8303c'), 'w') do |f|
17       f.write("2014-01-01_12:00:01 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 1\n")
18       f.write("2014-01-01_12:00:02 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 2\n")
19       f.write("2014-01-01_12:00:03 zzzzz-8i9sb-0vsrcqi7whchuil 0  log message 3\n")
20     end
21
22     @log_viewer_max_bytes = Rails.configuration.log_viewer_max_bytes
23   end
24
25   def teardown
26     keepdir = ENV.delete 'KEEP_LOCAL_STORE'
27     FileUtils.rm_rf(keepdir) if keepdir
28     Rails.configuration.log_viewer_max_bytes = @log_viewer_max_bytes
29   end
30
31   test "add job description" do
32     Capybara.current_driver = Capybara.javascript_driver
33     visit page_with_token("active", "/jobs")
34
35     # go to job running the script "doesnotexist"
36     within first('tr', text: 'doesnotexist') do
37       find("a").click
38     end
39
40     # edit job description
41     within('.arv-description-as-subtitle') do
42       find('.fa-pencil').click
43       find('.editable-input textarea').set('*Textile description for job* - "Go to dashboard":/')
44       find('.editable-submit').click
45     end
46     wait_for_ajax
47
48     # Verify edited description
49     assert page.has_no_text? '*Textile description for job*'
50     assert page.has_text? 'Textile description for job'
51     assert page.has_link? 'Go to dashboard'
52     click_link 'Go to dashboard'
53     assert page.has_text? 'Active pipelines'
54   end
55
56   test "view job log" do
57     Capybara.current_driver = Capybara.javascript_driver
58     job = api_fixture('jobs')['job_with_real_log']
59
60     visit page_with_token("active", "/jobs/#{job['uuid']}")
61     assert page.has_text? job['script_version']
62
63     click_link 'Log'
64     wait_for_ajax
65     assert page.has_text? 'Started at'
66     assert page.has_text? 'Finished at'
67     assert page.has_text? 'log message 1'
68     assert page.has_text? 'log message 2'
69     assert page.has_text? 'log message 3'
70   end
71
72   test 'view partial job log' do
73     Capybara.current_driver = Capybara.javascript_driver
74     Rails.configuration.log_viewer_max_bytes = 100
75     job = api_fixture('jobs')['job_with_real_log']
76
77     visit page_with_token("active", "/jobs/#{job['uuid']}")
78     assert page.has_text? job['script_version']
79
80     click_link 'Log'
81     wait_for_ajax
82     assert page.has_text? 'Showing only 100 bytes of this log'
83   end
84 end