Skip to content

Commit

Permalink
[webui] ProjectCreateTest: Simplify tests and remove create_project h…
Browse files Browse the repository at this point in the history
…elper
  • Loading branch information
bgeuken committed Aug 20, 2015
1 parent 600ec67 commit 95a3dec
Showing 1 changed file with 43 additions and 86 deletions.
129 changes: 43 additions & 86 deletions src/api/test/functional/webui/project_create_test.rb
Expand Up @@ -13,126 +13,83 @@ class Webui::ProjectCreateTest < Webui::IntegrationTest
uses_transaction :test_first_case_of_issue_204
uses_transaction :test_second_case_of_issue_204

def create_project new_project
new_project[:expect] ||= :success
new_project[:title] ||= ''
new_project[:description] ||= ''
new_project[:maintenance] ||= false
new_project[:hidden] ||= false
new_project[:namespace] ||= ''

if page.has_text?("Your home project doesn't exist yet. You can create it now")
new_project[:name] ||= current_user
current_user.must_equal new_project[:name]
else
new_project[:name] ||= ''
fill_in 'project_name', with: new_project[:name]
end

new_project[:description].squeeze!(' ')
new_project[:description].gsub!(/ *\n +/, "\n")
new_project[:description].strip!

fill_in 'project_title', with: new_project[:title]
fill_in 'project_description', with: new_project[:description]
find(:id, 'maintenance_project').click if new_project[:maintenance]
find(:id, 'access_protection').click if new_project[:access_protection]
click_button('Create Project')

if new_project[:expect] == :success
flash_message.must_equal "Project '#{new_project[:namespace] + new_project[:name]}' was created successfully"
flash_message_type.must_equal :info

new_project[:description] = 'No description set' if new_project[:description].empty?
assert_equal new_project[:description].gsub(%r{\s+}, ' '), find(:id, 'description_text').text
elsif new_project[:expect] == :invalid_name
flash_message.must_equal "Failed to save project '#{new_project[:namespace] + new_project[:name]}'. Name is illegal."
flash_message_type.must_equal :alert
elsif new_project[:expect] == :no_permission
flash_message.must_equal "Sorry you're not allowed to create this Project"
flash_message_type.must_equal :alert
elsif new_project[:expect] == :already_exists
flash_message.must_equal "Failed to save project '#{new_project[:namespace] + new_project[:name]}'. Name has already been taken."
flash_message_type.must_equal :alert
else
throw 'Invalid value for argument <expect>.'
end
end

def test_create_home_project_for_user
login_user('user1', '123456')
visit root_path
count = Project.count
visit new_project_path

fill_in 'project_name', with: 'home:user1'
click_button('Create Project')

find(:css, '#proceed-document-new .proceed_text a').click
page.must_have_text 'Project Name:'
create_project(title: 'HomeProject Title',
namespace: 'home:',
description: 'Test generated empty home project for second user.')
assert_equal count + 1, Project.count
end

def test_create_global_project
login_king to: new_project_path
count = Project.count

login_king to: project_list_all_path
fill_in 'project_name', with: 'PublicProject'
fill_in 'project_title', with: 'NewTitle'
click_button('Create Project')

click_link('Create new project')
create_project(
name: 'PublicProject1',
title: 'NewTitle' + Time.now.to_i.to_s,
description: "Test generated empty public project by #{current_user}.")
assert_equal count + 1, Project.count
end


def test_create_global_project_as_user
login_Iggy to: new_project_path
count = Project.count

login_Iggy to: project_list_all_path
fill_in 'project_name', with: 'PublicProject1'
fill_in 'project_title', with: 'NewTitle'
click_button('Create Project')

click_link('Create new project')
create_project(
name: 'PublicProj-' + Time.now.to_i.to_s,
title: 'NewTitle' + Time.now.to_i.to_s,
description: 'Test generated empty public project by user. Should give error.',
expect: :no_permission)
assert_equal count, Project.count
flash_message.must_equal "Sorry you're not allowed to create this Project"
flash_message_type.must_equal :alert
end

def test_first_case_of_issue_204
def test_breadcrumbs
login_king to: new_project_path
count = Project.count

fill_in 'project_name', with: "my_project"
fill_in 'project_title', with: 'none'
click_button('Create Project')

prjroot = Faker::Lorem.characters(20)
create_project(
name: prjroot,
title: 'none',
description: 'none')
assert_equal count + 1, Project.count

visit project_subprojects_path project: prjroot
click_link 'Create subproject'
visit project_subprojects_path project: "my_project"
click_link('Create subproject')

fill_in :project_name, with: 'b'
click_button 'Create Project'
click_button('Create Project')

# the parent project should be clickable
within '#breadcrump' do
find(:link, prjroot).text.must_equal prjroot
find(:link, "my_project").text.must_equal "my_project"
end
end

def test_second_case_of_issue_204
prjroot = Faker::Lorem.characters(20)
subproject = prjroot + ':b'

def test_breadcrumps_with_subproject_first
login_king to: new_project_path
count = Project.count

fill_in :project_name, with: subproject
click_button 'Create Project'
fill_in 'project_name', with: "my_other_project:sub"
click_button('Create Project')

assert_equal count + 1, Project.count

# now create the parent project
visit new_project_path
fill_in :project_name, with: prjroot
fill_in :project_name, with: "my_other_project"
click_button 'Create Project'

visit project_show_path project: subproject
assert_equal count + 2, Project.count

visit project_show_path project: "my_other_project:sub"

# the parent project should be clickable
within '#breadcrump' do
find(:link, prjroot).text.must_equal prjroot
find(:link, "my_other_project").text.must_equal "my_other_project"
end
end
end

0 comments on commit 95a3dec

Please sign in to comment.