detail_view_spec.rb 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Mobile > Organization > Can view organization', app: :mobile, type: :system do
  4. let(:organization) { create(:organization, domain: 'domain.com', note: '') }
  5. let(:user) { create(:customer, organization: organization) }
  6. let(:group) { create(:group) }
  7. let(:agent) { create(:agent, groups: [group]) }
  8. def open_organization
  9. visit "/organizations/#{organization.id}"
  10. wait_for_query('organization')
  11. wait_for_subscription_start('organizationUpdates')
  12. end
  13. context 'when visiting as agent', authenticated_as: :agent do
  14. it 'shows general information' do
  15. organization.update!(note: 'This is test organization')
  16. open_organization
  17. expect(page).to have_text(organization.name)
  18. domain = find('section', text: %r{Domain})
  19. expect(domain).to have_text('domain.com')
  20. note = find('section', text: %r{Note})
  21. expect(note).to have_text('This is test organization')
  22. organization.update!(name: 'Some New Name')
  23. wait_for_subscription_update('organizationUpdates')
  24. expect(page).to have_text('Some New Name')
  25. end
  26. it 'shows object attributes', db_strategy: :reset do
  27. screens = { view: { 'ticket.agent': { shown: true, required: false } } }
  28. attribute = create_attribute(
  29. :object_manager_attribute_text,
  30. object_name: 'Organization',
  31. display: 'Custom Text',
  32. screens: screens
  33. )
  34. organization[attribute.name] = 'Attribute Text'
  35. organization.save!
  36. open_organization
  37. domain = find('section', text: %r{Custom Text})
  38. expect(domain).to have_text('Attribute Text')
  39. organization[attribute.name] = 'Updated Text'
  40. organization.save!
  41. wait_for_subscription_update('organizationUpdates')
  42. expect(domain).to have_text('Updated Text')
  43. end
  44. it 'allows editing organization' do
  45. open_organization
  46. expect(page).to have_button('Edit')
  47. end
  48. it 'updates member list' do
  49. members = create_list(:customer, 5, organization: organization)
  50. # Check initial member list.
  51. open_organization
  52. # We are checking for shown avatars because currently the members list is not sorted by the unique identifier.
  53. expect(page).to have_css('a[href*="users"] span[data-test-id="common-avatar"]', count: 3)
  54. expect(page).to have_button('Show 2 more')
  55. # Check updated member list.
  56. members << create(:customer, organization: organization)
  57. wait_for_subscription_update('organizationUpdates')
  58. expect(page).to have_button('Show 3 more')
  59. click_on('Show 3 more')
  60. expect(page).to have_text(members.first.fullname)
  61. .and have_text(members.last.fullname)
  62. members << create(:customer, organization: organization)
  63. wait_for_subscription_update('organizationUpdates', number: 2)
  64. expect(page).to have_text(members.last.fullname)
  65. end
  66. end
  67. context 'when visiting as customer', authenticated_as: :user do
  68. it 'redirects to error' do
  69. visit '/organizations/1'
  70. expect_current_route('/error')
  71. end
  72. end
  73. end