Skip to content

Commit

Permalink
add some test cases for bc cards
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Nov 7, 2024
1 parent 50b832f commit 8ba84f1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 7 deletions.
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 8ba84f1

Please sign in to comment.