applies_taskbar_state_examples.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'FormUpdater::AppliesTaskbarState' do |taskbar_key:, taskbar_callback:|
  3. context 'when applying taskbar state' do
  4. let(:taskbar) { create(:taskbar, key: taskbar_key, callback: taskbar_callback, user_id: user.id, state: taskbar_state) }
  5. let(:taskbar_state) { { 'title' => 'test' } }
  6. let(:field_name) { 'title' }
  7. let(:field_result) { { value: 'test' } }
  8. let(:additional_data) { { 'taskbarId' => Gql::ZammadSchema.id_from_object(taskbar), 'applyTaskbarState' => true } }
  9. let(:meta) { { additional_data: } }
  10. shared_examples 'skips the field' do
  11. it 'skips the field' do
  12. expect(resolved_result.resolve[field_name]).not_to have_key(:value)
  13. end
  14. end
  15. shared_examples 'applies the form value of the field' do
  16. it 'applies the form value of the field' do
  17. expect(resolved_result.resolve[field_name]).to include(field_result)
  18. end
  19. end
  20. context 'without an associated taskbar' do
  21. let(:additional_data) { {} }
  22. include_examples 'skips the field'
  23. end
  24. context 'with an associated taskbar' do
  25. context 'with simple field' do
  26. include_examples 'applies the form value of the field'
  27. end
  28. context 'with formSenderType field' do
  29. let(:taskbar_state) { { 'formSenderType' => 'phone-in' } }
  30. let(:field_name) { 'articleSenderType' }
  31. let(:field_result) { { value: 'phone-in' } }
  32. include_examples 'applies the form value of the field'
  33. end
  34. context 'with cc field' do
  35. let(:taskbar_state) { { 'cc' => 'recipient1@example.org, recipient2@example.org' } }
  36. let(:field_name) { 'cc' }
  37. let(:field_result) { { value: %w[recipient1@example.org recipient2@example.org] } }
  38. include_examples 'applies the form value of the field'
  39. end
  40. context 'with tags field' do
  41. let(:taskbar_state) { { 'tags' => 'tag1, tag2, tag3' } }
  42. let(:field_name) { 'tags' }
  43. let(:field_result) { { value: %w[tag1 tag2 tag3] } }
  44. include_examples 'applies the form value of the field'
  45. end
  46. context 'with blank field' do
  47. let(:taskbar_state) { { 'title' => '' } }
  48. let(:field_name) { 'title' }
  49. let(:field_result) { { value: '' } }
  50. include_examples 'applies the form value of the field'
  51. end
  52. end
  53. end
  54. end