From 50b832f499d6affac7dbff610710e8de522bf8b5 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Thu, 7 Nov 2024 11:32:37 -0500 Subject: [PATCH 1/2] render completed and info views --- apps/dashboard/app/models/batch_connect/session.rb | 2 +- .../app/views/batch_connect/sessions/card/_card_body.html.erb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/app/models/batch_connect/session.rb b/apps/dashboard/app/models/batch_connect/session.rb index 0d34a71996..f3f21640d2 100644 --- a/apps/dashboard/app/models/batch_connect/session.rb +++ b/apps/dashboard/app/models/batch_connect/session.rb @@ -76,7 +76,7 @@ def render_info_view # Return parsed markdown from completed.{md, html}.erb # @return [String, nil] return HTML if no error while parsing, else return nil def render_completed_view - @render_completed_view ||= OodAppkit.markdown.render(ERB.new(self.app.session_completed_view, nil, "-").result(binding)).html_safe if self.app.session_completed_view + @render_completed_view ||= OodAppkit.markdown.render(ERB.new(self.app.session_completed_view, trim_mode: '-').result(binding)).html_safe if self.app.session_completed_view rescue => e @render_completed_view_error_message = "Error when rendering completed view: #{e.class} - #{e.message}" Rails.logger.error(@render_completed_view_error_message) diff --git a/apps/dashboard/app/views/batch_connect/sessions/card/_card_body.html.erb b/apps/dashboard/app/views/batch_connect/sessions/card/_card_body.html.erb index 94ef42aad5..6f8ceb90e2 100644 --- a/apps/dashboard/app/views/batch_connect/sessions/card/_card_body.html.erb +++ b/apps/dashboard/app/views/batch_connect/sessions/card/_card_body.html.erb @@ -7,6 +7,8 @@ <%= render_card_partial('id', session) %> <%= render_card_partial('support_ticket', session) if Configuration.support_ticket_enabled? %> <%= render_card_partial('display_choices', session) %> + <%= render_card_partial('custom_info_view', session) if session.app.session_info_view %> + <%= render_card_partial('completed_view', session) if session.app.session_completed_view && session.completed? %> <%= render_connection(session) %> From 8ba84f1f9cfc6c43508bb4a0c9b7a800ea623147 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Thu, 7 Nov 2024 11:33:07 -0500 Subject: [PATCH 2/2] add some test cases for bc cards --- .../bc_paraview/completed.html.erb | 1 + .../bc_paraview/info.html.erb | 1 + .../system/batch_connect_sessions_test.rb | 76 +++++++++++++++++-- 3 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_paraview/completed.html.erb create mode 100644 apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_paraview/info.html.erb diff --git a/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_paraview/completed.html.erb b/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_paraview/completed.html.erb new file mode 100644 index 0000000000..dd53be731b --- /dev/null +++ b/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_paraview/completed.html.erb @@ -0,0 +1 @@ +
This is a test message for a completed view.
diff --git a/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_paraview/info.html.erb b/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_paraview/info.html.erb new file mode 100644 index 0000000000..6ae8e90dd5 --- /dev/null +++ b/apps/dashboard/test/fixtures/sys_with_gateway_apps/bc_paraview/info.html.erb @@ -0,0 +1 @@ +
This is a test message for an info view.
\ No newline at end of file diff --git a/apps/dashboard/test/system/batch_connect_sessions_test.rb b/apps/dashboard/test/system/batch_connect_sessions_test.rb index f61a6b0142..e14ff3cf19 100644 --- a/apps/dashboard/test/system/batch_connect_sessions_test.rb +++ b/apps/dashboard/test/system/batch_connect_sessions_test.rb @@ -11,14 +11,14 @@ def setup stub_sys_apps end - def test_data + def test_data(token: 'sys/bc_paraview', title: 'Paraview') { 'id': test_bc_id, 'cluster_id': 'owens', "job_id": test_job_id, "created_at": 1_701_184_869, - "token": 'sys/bc_paraview', - "title": 'Code Server', + "token": token, + "title": title, "script_type": 'basic', "cache_completed": false } @@ -32,9 +32,9 @@ def test_bc_id 'abc-123' end - def create_test_file(dir) + def create_test_file(dir, token: 'sys/bc_paraview', title: 'Paraview') BatchConnect::Session.stubs(:db_root).returns(Pathname.new(dir)) - File.write("#{dir}/#{test_bc_id}", test_data.to_json) + File.write("#{dir}/#{test_bc_id}", test_data(token: token, title: title).to_json) end def stub_scheduler(state) @@ -53,12 +53,74 @@ def stub_scheduler(state) create_test_file(dir) stub_scheduler(:queued) visit(batch_connect_sessions_path) - + + card = find("#id_#{test_bc_id}") + assert_not_nil(card) + + header_text = card.find('.h5').text + assert_equal("Paraview (#{test_job_id})\nQueued", header_text) + end + end + + test 'completed session' do + Dir.mktmpdir do |dir| + create_test_file(dir, token: 'sys/bc_jupyter', title: 'Jupyter') + stub_scheduler(:completed) + visit(batch_connect_sessions_path) + + card = find("#id_#{test_bc_id}") + assert_not_nil(card) + + header_text = card.find('.h5').text + assert_equal("Jupyter (#{test_job_id})\nCompleted | |", header_text) + end + end + + test 'completed session with completed view' do + Dir.mktmpdir do |dir| + create_test_file(dir) + stub_scheduler(:completed) + visit(batch_connect_sessions_path) + card = find("#id_#{test_bc_id}") assert_not_nil(card) header_text = card.find('.h5').text - assert_equal("Code Server (#{test_job_id})\nQueued", header_text) + assert_equal("Paraview (#{test_job_id})\nCompleted | |", header_text) + + completed_text = card.find('#completed_test_div').text + assert_equal('This is a test message for a completed view.', completed_text) + end + end + + test 'running session' do + Dir.mktmpdir do |dir| + create_test_file(dir, token: 'sys/bc_jupyter', title: 'Jupyter') + stub_scheduler(:running) + visit(batch_connect_sessions_path) + + card = find("#id_#{test_bc_id}") + assert_not_nil(card) + + header_text = card.find('.h5').text + assert_equal("Jupyter (#{test_job_id})\n0 nodes | 0 cores | Starting", header_text) + end + end + + test 'running session with info view' do + Dir.mktmpdir do |dir| + create_test_file(dir, token: 'sys/bc_paraview', title: 'Paraview') + stub_scheduler(:running) + visit(batch_connect_sessions_path) + + card = find("#id_#{test_bc_id}") + assert_not_nil(card) + + header_text = card.find('.h5').text + assert_equal("Paraview (#{test_job_id})\n0 nodes | 0 cores | Starting", header_text) + + info_text = card.find("#info_test_div").text + assert_equal('This is a test message for an info view.', info_text) end end end