Skip to content

Commit

Permalink
Improved testing for Project size feature (#3342)
Browse files Browse the repository at this point in the history
abujeda authored Feb 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent be2321c commit 4efca57
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/projects/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@ json.icon @project.icon
json.directory @project.directory
project_size = @project.size
json.size project_size
json.human_size ::ApplicationController.helpers.number_to_human_size(project_size)
json.human_size number_to_human_size(project_size)
16 changes: 12 additions & 4 deletions apps/dashboard/test/models/projects_test.rb
Original file line number Diff line number Diff line change
@@ -34,12 +34,20 @@ class ProjectsTest < ActiveSupport::TestCase
end

test 'creates project' do
stub_du
Dir.mktmpdir do |tmp|
projects_path = Pathname.new(tmp)
project = create_project(projects_path)
project_id = Project.next_id
project = create_project(projects_path, id: project_id, name: 'MyLocalName', description: 'MyLocalDescription', icon: 'fas://test')

assert project.errors.inspect
assert Dir.entries("#{projects_path}/projects").include?(project.id)
assert Dir.entries("#{projects_path}/projects").include?(project_id)
assert_equal project_id, project.id
assert_equal 'MyLocalName', project.name
assert_equal "#{projects_path}/projects/#{project_id}", project.directory
assert_equal 'MyLocalDescription', project.description
assert_equal 'fas://test', project.icon
assert_equal 2097152, project.size
end
end

@@ -182,9 +190,9 @@ class ProjectsTest < ActiveSupport::TestCase
end
end

def create_project(projects_path, name: 'test-project', icon: 'fas://arrow-right', description: 'description', directory: nil, template: nil)
def create_project(projects_path, id: nil, name: 'test-project', icon: 'fas://arrow-right', description: 'description', directory: nil, template: nil)
OodAppkit.stubs(:dataroot).returns(projects_path)
id = Project.next_id
id ||= Project.next_id
attrs = { name: name, icon: icon, id: id, description: description, directory: directory, template: template }
project = Project.new(attrs)
assert project.save, project.collect_errors
19 changes: 19 additions & 0 deletions apps/dashboard/test/system/jobs_app_test.rb
Original file line number Diff line number Diff line change
@@ -133,6 +133,25 @@ def add_bc_num_hours(project_id, script_id)
find("[href='/projects/#{project_id}']").click
assert_selector 'h1', text: 'Test Project'
assert_selector '.btn.btn-default', text: 'Back'
# project size is hardcoded to 2MB with stub_du
assert_selector '#new-dir-btn', text: 'Project Directory (2 MB)'
end
end

test 'project show should support JSON' do
Dir.mktmpdir do |dir|
project_id = setup_project(dir)

visit project_path(project_id, format: :json)
json_response = find('body').text
project_data = JSON.parse(json_response, symbolize_names: true)
assert_equal project_id, project_data[:id]
assert_equal 'test-project', project_data[:name]
assert_equal 'test-description', project_data[:description]
assert_equal 'fas://arrow-right', project_data[:icon]
assert_equal "#{dir}/projects/#{project_id}", project_data[:directory]
assert_equal 2097152, project_data[:size]
assert_equal '2 MB', project_data[:human_size]
end
end

0 comments on commit 4efca57

Please sign in to comment.