OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/modules/costs/spec/features/budgets/add_budget_spec.rb

133 lines
4.6 KiB

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe 'adding a new budget', type: :feature, js: true do
let(:project) { FactoryBot.create :project_with_types }
let(:user) { FactoryBot.create :admin }
before do
allow(User).to receive(:current).and_return user
end
it 'shows link to create a new budget' do
visit projects_cost_objects_path(project)
click_on("Add budget")
expect(page).to have_content "New budget"
expect(page).to have_content "Description"
expect(page).to have_content "Subject"
end
describe 'with multiple cost types' do
let!(:cost_type_1) do
FactoryBot.create :cost_type, name: 'Post-war', unit: 'cap', unit_plural: 'caps'
end
let!(:cost_type_2) do
FactoryBot.create :cost_type, name: 'Foobar', unit: 'bar', unit_plural: 'bars'
end
it 'can switch between them' do
visit projects_cost_objects_path(project)
click_on("Add budget")
expect(page).to have_content "New budget"
fill_in 'Subject', with: 'My subject'
fill_in 'cost_object_new_material_budget_item_attributes_0_units', with: 15
# change cost type
select 'Foobar', from: 'cost_object_new_material_budget_item_attributes_0_cost_type_id'
click_on "Create"
expect(page).to have_content "Successful creation"
expect(page).to have_content "My subject"
expect(page).to have_selector('.material_budget_items td.units', text: '15.00')
expect(page).to have_selector('.material_budget_items td', text: 'Foobar')
end
end
it 'create the budget' do
visit new_projects_cost_object_path(project)
fill_in("Subject", with: 'My subject')
click_on "Create"
expect(page).to have_content "Successful creation"
expect(page).to have_content "My subject"
end
context 'with cost items' do
let(:cost_type) do
FactoryBot.create :cost_type, name: 'Post-war', unit: 'cap', unit_plural: 'caps'
end
let(:new_budget_page) { Pages::NewBudget.new project.identifier }
before do
project.add_member! user, FactoryBot.create(:role)
FactoryBot.create :cost_rate, cost_type: cost_type, rate: 50.0
FactoryBot.create :default_hourly_rate, user: user, rate: 25.0
end
it 'creates the budget including the given cost items' do
new_budget_page.visit!
fill_in 'Subject', with: 'First Aid'
new_budget_page.add_unit_costs! 3, comment: 'RadAway'
new_budget_page.add_unit_costs! 2, comment: 'Rad-X'
new_budget_page.add_labor_costs! 5, user_name: user.name, comment: 'treatment'
new_budget_page.add_labor_costs! 2, user_name: user.name, comment: 'attendance'
click_on 'Create'
expect(page).to have_content('Successful creation')
new_budget_page.toggle_unit_costs!
expect(page).to have_selector('td.currency', text: '150.00 EUR')
expect(new_budget_page.unit_costs_at(1)).to have_content '150.00 EUR'
expect(new_budget_page.unit_costs_at(2)).to have_content '100.00 EUR'
expect(new_budget_page.overall_unit_costs).to have_content '250.00 EUR'
new_budget_page.toggle_labor_costs!
expect(page).to have_selector('td.currency', text: '125.00 EUR')
expect(new_budget_page.labor_costs_at(1)).to have_content '125.00 EUR'
expect(new_budget_page.labor_costs_at(2)).to have_content '50.00 EUR'
expect(new_budget_page.overall_labor_costs).to have_content '175.00 EUR'
end
end
end