Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved testing for Project size feature #3342

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/projects/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions apps/dashboard/test/system/jobs_app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading