ticket_accounted_time_spec.rb 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Mobile > Ticket > Information > Accounted Time', app: :mobile, authenticated_as: :authenticate, type: :system do
  4. let(:group) { create(:group) }
  5. let(:ticket) { create(:ticket, group: group) }
  6. let(:article) { create(:ticket_article, ticket: ticket) }
  7. let(:time_unit) { Faker::Number.unique.decimal(l_digits: 1, r_digits: 1) }
  8. let(:time_accounting) { create(:'ticket/time_accounting', ticket: ticket, ticket_article: article, time_unit: time_unit) }
  9. let(:accounted_time_element) do
  10. find('section', text: 'Accounted Time')
  11. end
  12. def authenticate
  13. time_accounting
  14. user
  15. end
  16. before do
  17. Setting.set('time_accounting', true)
  18. visit "/tickets/#{ticket.id}/information"
  19. end
  20. shared_examples 'showing accounted time' do |time_accounting_unit = '', display_unit = nil|
  21. before do
  22. Setting.set('time_accounting_unit', time_accounting_unit) if time_accounting_unit.present?
  23. Setting.set('time_accounting_unit_custom', display_unit) if time_accounting_unit == 'custom'
  24. end
  25. it 'shows accounted time', if: !display_unit do
  26. expect(accounted_time_element).to have_text(time_unit)
  27. end
  28. it "shows accounted time in #{display_unit}", if: display_unit do
  29. expect(accounted_time_element).to have_text("#{time_unit} #{display_unit}")
  30. end
  31. end
  32. context 'with agent user' do
  33. context 'with full permissions' do
  34. let(:user) { create(:agent, groups: [group]) }
  35. it_behaves_like 'showing accounted time'
  36. context 'with a pre-defined unit' do
  37. it_behaves_like 'showing accounted time', 'minute', 'minute(s)'
  38. end
  39. context 'with a custom unit' do
  40. it_behaves_like 'showing accounted time', 'custom', 'person day(s)'
  41. end
  42. end
  43. context 'with read permissions' do
  44. let(:user) { create(:agent, groups: [group], group_names_access_map: { group.name => 'read' }) }
  45. it_behaves_like 'showing accounted time'
  46. end
  47. end
  48. context 'with customer user' do
  49. let(:user) { create(:customer) }
  50. let(:ticket) { create(:ticket, customer: user) }
  51. it 'does not show accounted time' do
  52. expect(page).to have_no_css('Accounted Time')
  53. end
  54. end
  55. end