dropdown_spec.rb 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'lib/import/otrs/dynamic_field_examples'
  4. RSpec.describe Import::OTRS::DynamicField::Dropdown do
  5. it_behaves_like 'Import::OTRS::DynamicField'
  6. it 'imports an OTRS Dropdown DynamicField' do
  7. zammad_structure = {
  8. object: 'Ticket',
  9. name: 'dropdown_example',
  10. display: 'Dropdown Example',
  11. screens: {
  12. view: {
  13. '-all-' => {
  14. shown: true
  15. }
  16. }
  17. },
  18. active: true,
  19. editable: true,
  20. position: '30',
  21. created_by_id: 1,
  22. updated_by_id: 1,
  23. data_type: 'select',
  24. data_option: {
  25. default: '',
  26. multiple: false,
  27. options: {
  28. 'Hamburg' => 'Hamburg',
  29. 'München' => 'München',
  30. 'Köln' => 'Köln',
  31. 'Berlin' => 'Berlin'
  32. },
  33. nulloption: true,
  34. null: true,
  35. translate: false
  36. }
  37. }
  38. dynamic_field_from_json('dropdown/default', zammad_structure)
  39. end
  40. it 'imports an OTRS Dropdown DynamicField with tree mode' do
  41. zammad_structure = {
  42. object: 'Ticket',
  43. name: 'treeselect_example',
  44. display: 'Treeselect Example',
  45. screens: {
  46. view: {
  47. '-all-' => {
  48. shown: true
  49. }
  50. }
  51. },
  52. active: true,
  53. editable: true,
  54. position: '30',
  55. created_by_id: 1,
  56. updated_by_id: 1,
  57. data_type: 'tree_select',
  58. data_option: {
  59. default: '',
  60. multiple: false,
  61. options: [
  62. {
  63. 'value' => 'Level1',
  64. 'name' => 'Level 1',
  65. 'children' => [
  66. { 'value' => 'SubLevel1', 'name' => 'SubLevel 1' },
  67. { 'value' => 'SubLevel2', 'name' => 'SubLevel 2' },
  68. ],
  69. },
  70. {
  71. 'value' => 'Level2',
  72. 'name' => 'Level 2',
  73. 'children' => [
  74. { 'value' => 'SubLevel1', 'name' => 'SubLevel 1' },
  75. { 'value' => 'SubLevel2', 'name' => 'SubLevel 2' },
  76. ],
  77. },
  78. {
  79. 'value' => 'Support',
  80. 'name' => 'Support',
  81. 'children' => [
  82. {
  83. 'value' => 'Level1', 'name' => 'Level 1'
  84. },
  85. {
  86. 'value' => 'Level2', 'name' => 'Level 2'
  87. },
  88. {
  89. 'value' => 'Level3', 'name' => 'Level 3'
  90. }
  91. ]
  92. },
  93. {
  94. 'value' => 'Finance',
  95. 'name' => 'Finance',
  96. 'children' => [
  97. {
  98. 'value' => 'Invoice',
  99. 'name' => 'Invoice',
  100. 'children' => [
  101. {
  102. 'value' => 'Germany',
  103. 'name' => 'Germany',
  104. 'children' => [
  105. { 'value' => 'Monthly', 'name' => 'Monthly' }
  106. ],
  107. },
  108. ]
  109. }
  110. ]
  111. }
  112. ],
  113. nulloption: true,
  114. null: true,
  115. translate: false
  116. }
  117. }
  118. dynamic_field_from_json('dropdown/treeselect', zammad_structure)
  119. end
  120. context 'without possible values' do
  121. it 'imports no field without possible value' do
  122. allow(ObjectManager::Attribute).to receive(:add)
  123. described_class.new(load_dynamic_field_json('dropdown/without_possible_values'))
  124. expect(ObjectManager::Attribute).not_to have_received(:add)
  125. end
  126. end
  127. end