edit_spec.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'system/apps/mobile_old/examples/core_workflow_examples'
  4. RSpec.describe 'Mobile > Organization > Can edit organization', app: :mobile, type: :system do
  5. let(:organization) { create(:organization, domain: 'domain.com', note: '') }
  6. let(:user) { create(:customer, organization: organization) }
  7. let(:group) { create(:group) }
  8. let(:agent) { create(:agent, groups: [group]) }
  9. def open_organization
  10. visit "/organizations/#{organization.id}"
  11. wait_for_gql('shared/entities/organization/graphql/queries/organization.graphql')
  12. end
  13. def save_organization(form_updater_call_number = 2)
  14. wait_for_form_updater(form_updater_call_number)
  15. click('button:not(disabled)', text: 'Save')
  16. end
  17. context 'when visiting as agent', authenticated_as: :agent do
  18. it 'can edit organization' do
  19. open_organization
  20. click('button', text: 'Edit')
  21. wait_for_form_to_settle('organization-edit')
  22. within('#dialog-organization-edit') do
  23. within_form do
  24. find_editor('Note').type('edit field')
  25. end
  26. save_organization
  27. end
  28. wait_for_gql('apps/mobile/entities/organization/graphql/mutations/update.graphql')
  29. organization.reload
  30. expect(organization.note).to eq('<p>edit field</p>')
  31. end
  32. it 'can edit organization with object atrributes', db_strategy: :reset do
  33. screens = { edit: { 'ticket.agent': { shown: true, required: false } } }
  34. attribute = create_attribute(
  35. :object_manager_attribute_text,
  36. object_name: 'Organization',
  37. display: 'Custom Text',
  38. screens: screens
  39. )
  40. open_organization
  41. click('button', text: 'Edit')
  42. wait_for_form_to_settle('organization-edit')
  43. within('#dialog-organization-edit') do
  44. within_form do
  45. find_editor('Name').type('new name')
  46. find_input('Custom Text').type('some text')
  47. end
  48. save_organization(3)
  49. end
  50. wait_for_gql('apps/mobile/entities/organization/graphql/mutations/update.graphql')
  51. organization.reload
  52. expect(organization.name).to eq('new name')
  53. expect(organization[attribute.name]).to eq('some text')
  54. end
  55. end
  56. describe 'Core Workflow' do
  57. include_examples 'mobile app: core workflow' do
  58. let(:object_name) { 'Organization' }
  59. let(:form_updater_gql_number) { 1 }
  60. let(:before_it) do
  61. lambda {
  62. open_organization
  63. click('button', text: 'Edit')
  64. wait_for_form_to_settle('organization-edit')
  65. }
  66. end
  67. end
  68. end
  69. end