@ -29,31 +29,35 @@
require 'spec_helper'
describe 'Logging time within the work package view' , type : :feature , js : true do
let ( :project ) { create :project }
let ( :admin ) { create :admin }
let ( :user_without_permissions ) do
create ( :user ,
member_in_project : project ,
member_with_permissions : % i [ view_time_entries view_work_packages edit_work_packages ] )
end
shared_let ( :project ) { create :project }
shared_let ( :admin ) { create :admin }
shared_let ( :work_package ) { create :work_package , project : }
shared_let ( :activity ) { create :time_entry_activity , project : }
let ( :user ) { admin }
let! ( :activity ) { create :time_entry_activity , project : }
let ( :spent_time_field ) { :: SpentTimeEditField . new ( page , 'spentTime' ) }
let ( :work_package ) { create :work_package , project : }
let ( :wp_page ) { Pages :: FullWorkPackage . new ( work_package , project ) }
let ( :time_logging_modal ) { :: Components :: TimeLoggingModal . new }
def log_time_via_modal
def log_time_via_modal ( user_field_visible : true , log_for_user : nil )
time_logging_modal . is_visible true
# the fields are visible
time_logging_modal . has_field_with_value 'spent_on' , Date . today . strftime ( " %Y-%m-%d " )
time_logging_modal . shows_field 'work_package' , false
time_logging_modal . shows_field 'user' , user_field_visible
time_logging_modal . update_field 'activity' , activity . name
if log_for_user
time_logging_modal . update_field 'user' , log_for_user . name
elsif user_field_visible
expect ( page ) . to have_selector ( '.ng-value-label' , text : user . name )
end
# a click on save creates a time entry
time_logging_modal . perform_action I18n . t ( 'js.label_create' )
wp_page . expect_and_dismiss_toaster message : I18n . t ( 'js.notice_successful_create' )
@ -61,7 +65,7 @@ describe 'Logging time within the work package view', type: :feature, js: true d
context 'as an admin' do
before do
login_as ( admin )
login_as ( user )
wp_page . visit!
loading_indicator_saveguard
spent_time_field . time_log_icon_visible true
@ -77,6 +81,30 @@ describe 'Logging time within the work package view', type: :feature, js: true d
spent_time_field . expect_display_value '1 h'
end
context 'with another user in the project' do
let! ( :other_user ) do
create ( :user ,
firstname : 'Loggable' ,
lastname : 'User' ,
member_in_project : project ,
member_with_permissions : % i [ view_work_packages edit_work_packages work_package_assigned ] )
end
it 'can log time for that user' do
# click on button opens modal
spent_time_field . open_time_log_modal
log_time_via_modal log_for_user : other_user
# the value is updated automatically
spent_time_field . expect_display_value '1 h'
time_entry = TimeEntry . last
expect ( time_entry . user ) . to eq other_user
expect ( time_entry . logged_by ) . to eq user
end
end
it 'the context menu entry to log time leads to the modal' do
# click on context menu opens the modal
find ( '#action-show-more-dropdown-menu .button' ) . click
@ -89,7 +117,7 @@ describe 'Logging time within the work package view', type: :feature, js: true d
end
context 'with a user with non-one unit numbers' , with_settings : { available_languages : %w[ en ja ] } do
let ( :admin ) { create :admin , language : 'ja' }
let ( :user ) { create :admin , language : 'ja' }
before do
I18n . locale = 'ja'
@ -105,44 +133,75 @@ describe 'Logging time within the work package view', type: :feature, js: true d
spent_time_field . expect_display_value '1 h'
end
end
end
context 'as a user who cannot log time' do
before do
login_as ( user_without_permissions )
wp_page . visit!
loading_indicator_saveguard
end
context 'as a user who cannot log time' do
let ( :user ) do
create ( :user ,
member_in_project : project ,
member_with_permissions : % i [ view_time_entries view_work_packages edit_work_packages ] )
end
it 'shows no logging button within the display field' do
spent_time_field . time_log_icon_visible false
spent_time_field . expect_display_value '-'
end
before do
login_as ( user )
wp_page . visit!
loading_indicator_saveguard
end
it 'shows no logging button within the display field' do
spent_time_field . time_log_icon_visible false
spent_time_field . expect_display_value '-'
end
end
context 'within the table' do
let ( :wp_table ) { Pages :: WorkPackagesTable . new ( project ) }
let ( :second_work_package ) { create :work_package , project : }
let ( :query ) { create :public_query , project : , column_names : [ 'subject' , 'spent_hours' ] }
context 'as a user who can only log own time' do
let ( :user ) do
create ( :user ,
member_in_project : project ,
member_with_permissions : % i [ view_time_entries view_work_packages log_own_time ] )
end
before do
work_package
second_work_package
login_as ( admin )
before do
login_as ( user )
wp_page . visit!
loading_indicator_saveguard
end
wp_table . visit_query query
loading_indicator_saveguard
end
it 'can log its own time' do
spent_time_field . time_log_icon_visible true
# click on button opens modal
spent_time_field . open_time_log_modal
it 'shows no logging button within the display field' do
wp_table . expect_work_package_listed work_package , second_work_package
log_time_via_modal user_field_visible : false
find ( 'tr:nth-of-type(1) .wp-table--cell-td.spentTime .icon-time' ) . click
# the value is updated automatically
spent_time_field . expect_display_value '1 h'
end
end
log_time_via_modal
context 'when in the table' do
let ( :wp_table ) { Pages :: WorkPackagesTable . new ( project ) }
let ( :second_work_package ) { create :work_package , project : }
let ( :query ) { create :public_query , project : , column_names : [ 'subject' , 'spent_hours' ] }
expect ( page ) . to have_selector ( 'tr:nth-of-type(1) .wp-table--cell-td.spentTime' , text : '1 h' )
expect ( page ) . to have_selector ( 'tr:nth-of-type(2) .wp-table--cell-td.spentTime' , text : '-' )
end
before do
work_package
second_work_package
login_as ( admin )
wp_table . visit_query query
loading_indicator_saveguard
end
it 'shows no logging button within the display field' do
wp_table . expect_work_package_listed work_package , second_work_package
find ( 'tr:nth-of-type(1) .wp-table--cell-td.spentTime .icon-time' ) . click
log_time_via_modal
expect ( page ) . to have_selector ( 'tr:nth-of-type(1) .wp-table--cell-td.spentTime' , text : '1 h' )
expect ( page ) . to have_selector ( 'tr:nth-of-type(2) .wp-table--cell-td.spentTime' , text : '-' )
end
end
end