reply_article_examples.rb 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'mobile app: reply article' do |type_label, note, internal: false, attachments: false|
  3. let(:attributes) do
  4. attributes = {
  5. type_id: type_id,
  6. internal: internal,
  7. body: result_text,
  8. in_reply_to: in_reply_to
  9. }
  10. saved_to = result_to if result_to.present?
  11. saved_to = saved_to.join(', ') if saved_to.is_a?(Array)
  12. saved_cc = cc if cc.present?
  13. saved_cc = saved_cc.join(', ') if saved_cc.is_a?(Array)
  14. saved_subject = article_subject if article_subject.present?
  15. saved_subject = new_subject if new_subject.present?
  16. attributes[:to] = saved_to if saved_to.present?
  17. attributes[:cc] = saved_cc if cc.present?
  18. attributes[:subject] = saved_subject if saved_subject.present?
  19. attributes
  20. end
  21. def assert_fields(type_label, internal)
  22. expect(find_select('Article Type', visible: :all)).to have_selected_option(type_label)
  23. expect(find_select('Visibility', visible: :all)).to have_selected_option(internal ? 'Internal' : 'Public')
  24. expect(find_autocomplete('To')).to have_selected_options(to) if to.present?
  25. expect(find_autocomplete('CC')).to have_selected_options(cc) if cc.present?
  26. expect(find_select('Subject', visible: :all)).to have_value(article_subject) if article_subject.present?
  27. expect(find_editor('Text')).to have_text_value(current_text, exact: text_exact)
  28. end
  29. # test only that reply works, because edge cases are covered by unit tests
  30. it "can reply with #{type_label} #{note || ''}" do
  31. open_article_reply_dialog
  32. after_click.call
  33. assert_fields(type_label, internal)
  34. find_editor('Text').type(new_text, click: false) if new_text
  35. find_autocomplete('To').search_for_option(new_to) if new_to.present?
  36. find_field('Subject', visible: :all).input(new_subject) if new_subject.present?
  37. if attachments
  38. find_field('attachments', visible: :all).attach_file('spec/fixtures/files/image/small.png')
  39. # need to wait until the file is uploaded
  40. expect(page).to have_text('small.png', wait: 60)
  41. else
  42. expect(page).to have_no_field('attachments', visible: :all)
  43. end
  44. find_button('Done', wait: 20).click
  45. find_button('Save', wait: 20).click
  46. wait_for_gql('apps/mobile/pages/ticket/graphql/mutations/update.graphql')
  47. if attachments
  48. attributes[:attachments] = result_attachments
  49. expect(Store.last.filename).to eq('small.png')
  50. end
  51. expect(Ticket::Article.last).to have_attributes(attributes)
  52. end
  53. end