customer_organization_avatars_spec.rb 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket zoom > Customer & Organization Avatars', authenticated_as: :authenticate, type: :system do
  4. let(:group) { create(:group) }
  5. let(:agent) { create(:agent, groups: [group]) }
  6. let(:customer) { create(:customer) }
  7. let(:ticket) { create(:ticket, group: group, customer: customer) }
  8. let(:article) { create(:ticket_article, ticket: ticket) }
  9. def authenticate
  10. ticket && article
  11. agent
  12. end
  13. before do
  14. visit "#ticket/zoom/#{ticket.id}"
  15. end
  16. context 'without organization' do
  17. before do
  18. click('.content.active .tabsSidebar-tab[data-tab="customer"]')
  19. end
  20. shared_examples 'displaying customer avatar' do |containers, vip|
  21. it "displays customer avatar with the crown in: #{containers}", if: vip do
  22. containers.each do |container|
  23. within "#{container} .avatar--unique" do
  24. expect(page).to have_css('.icon-crown')
  25. end
  26. end
  27. end
  28. it "displays customer avatar without the crown in: #{containers}", if: !vip do
  29. containers.each do |container|
  30. within "#{container} .avatar--unique" do
  31. expect(page).to have_no_css('.icon-crown')
  32. end
  33. end
  34. end
  35. end
  36. shared_examples 'not displaying organization avatar' do |container|
  37. it "does not display organization avatar in '#{container}'" do
  38. within container do
  39. expect(page).to have_no_css('.avatar--organization')
  40. end
  41. end
  42. end
  43. it_behaves_like 'not displaying organization avatar', '.ticketZoom-header'
  44. context 'with customer vip status' do
  45. let(:customer) { create(:customer, vip: true) }
  46. it_behaves_like 'displaying customer avatar', ['.ticketZoom-header', '.sidebar[data-tab="customer"]'], true
  47. end
  48. context 'without customer vip status' do
  49. let(:customer) { create(:customer, vip: false) }
  50. it_behaves_like 'displaying customer avatar', ['.ticketZoom-header', '.sidebar[data-tab="customer"]'], false
  51. end
  52. end
  53. context 'with organization' do
  54. let(:organization) { create(:organization, vip: vip_organization) }
  55. let(:customer) { create(:customer, organization: organization) }
  56. before do
  57. click('.content.active .tabsSidebar-tab[data-tab="organization"]')
  58. end
  59. shared_examples 'displaying organization avatar' do |containers, active, vip|
  60. it "displays active organization avatar with the crown in: #{containers}", if: active && vip do
  61. containers.each do |container|
  62. within "#{container} .avatar--organization" do
  63. expect(page).to have_css('.icon-organization').and have_css('.icon-crown-silver')
  64. end
  65. end
  66. end
  67. it "displays active organization avatar without the crown in: #{containers}", if: active && !vip do
  68. containers.each do |container|
  69. within "#{container} .avatar--organization" do
  70. expect(page).to have_css('.icon-organization').and have_no_css('.icon-crown-silver')
  71. end
  72. end
  73. end
  74. it "displays inactive active organization avatar with the crown in: #{containers}", if: !active && vip do
  75. containers.each do |container|
  76. within "#{container} .avatar--organization" do
  77. expect(page).to have_css('.icon-inactive-organization').and have_css('.icon-crown-silver')
  78. end
  79. end
  80. end
  81. it "displays inactive organization avatar without the crown in: #{containers}", if: !active && !vip do
  82. containers.each do |container|
  83. within "#{container} .avatar--organization" do
  84. expect(page).to have_css('.icon-inactive-organization').and have_no_css('.icon-crown-silver')
  85. end
  86. end
  87. end
  88. end
  89. context 'with organization vip status' do
  90. let(:vip_organization) { true }
  91. it_behaves_like 'displaying organization avatar', ['.ticketZoom-header', '.sidebar[data-tab="organization"]'], true, true
  92. end
  93. context 'without organization vip status' do
  94. let(:vip_organization) { false }
  95. it_behaves_like 'displaying organization avatar', ['.ticketZoom-header', '.sidebar[data-tab="organization"]'], true, false
  96. end
  97. context 'with inactive organization' do
  98. let(:organization) { create(:organization, vip: vip_organization, active: false) }
  99. context 'with organization vip status' do
  100. let(:vip_organization) { true }
  101. it_behaves_like 'displaying organization avatar', ['.ticketZoom-header', '.sidebar[data-tab="organization"]'], false, true
  102. end
  103. context 'without organization vip status' do
  104. let(:vip_organization) { false }
  105. it_behaves_like 'displaying organization avatar', ['.ticketZoom-header', '.sidebar[data-tab="organization"]'], false, false
  106. end
  107. end
  108. end
  109. end