Skip to content

Commit

Permalink
Fix bc cards (#3941)
Browse files Browse the repository at this point in the history
Render completed and info views which was missed in the refactor.
  • Loading branch information
johrstrom authored Nov 8, 2024
1 parent f8f4828 commit fc865ff
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apps/dashboard/app/models/batch_connect/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="completed_test_div">This is a test message for a completed view.</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="info_test_div">This is a test message for an info view.</div>
76 changes: 69 additions & 7 deletions apps/dashboard/test/system/batch_connect_sessions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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

0 comments on commit fc865ff

Please sign in to comment.