checklist_templates_spec.rb 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Manage > Checklists', current_user_id: 1, type: :system do
  4. context 'when enabling/disabling checklists' do
  5. before do
  6. visit 'manage/checklists'
  7. end
  8. it 'can enable/disable checklists' do
  9. expect(Setting.get('checklist')).to be(true)
  10. find('.js-checklistSetting').click
  11. wait.until { Setting.get('checklist') == false }
  12. end
  13. end
  14. context 'when adding a new checklist' do
  15. before do
  16. visit 'manage/checklists'
  17. end
  18. it 'shows a help text' do
  19. expect(page).to have_content('With checklist templates it is possible to pre-fill new checklists with initial items.')
  20. expect(page).to have_no_css('.js-description')
  21. end
  22. context 'when items are empty' do
  23. it 'shows an error message' do
  24. expect(page).to have_link('New Checklist Template')
  25. click_on('New Checklist Template')
  26. in_modal do
  27. fill_in('Name', with: 'Test Checklist')
  28. click_on('Submit')
  29. expect(page).to have_content('Please add at least one item to the checklist.')
  30. end
  31. end
  32. end
  33. context 'when items are present' do
  34. it 'adds a new checklist' do
  35. expect(page).to have_link('New Checklist Template')
  36. click_on('New Checklist Template')
  37. in_modal do
  38. fill_in('Name', with: 'Test Checklist')
  39. find('.checklist-item-add-item-text').fill_in(with: 'Test Item')
  40. click_on('Add')
  41. click_on('Submit')
  42. end
  43. expect(page).to have_content('Test Checklist')
  44. end
  45. end
  46. end
  47. context 'when editing a checklist' do
  48. before do
  49. create(:checklist_template, name: 'Test Checklist')
  50. visit 'manage/checklists'
  51. end
  52. it 'shows a description button' do
  53. expect(page).to have_no_content('With checklist templates it is possible to pre-fill new checklists with initial items.')
  54. expect(page).to have_css('.js-description')
  55. page.find('.js-description').click
  56. in_modal do
  57. expect(page).to have_content('With checklist templates it is possible to pre-fill new checklists with initial items.')
  58. end
  59. end
  60. it 'successfully updates the checklist' do
  61. expect(page).to have_content('Test Checklist')
  62. find('.js-checklistTemplatesTable tr.item').click
  63. in_modal do
  64. find('.checklist-item-add-item-text').fill_in(with: 'Test Item')
  65. click_on('Add')
  66. click_on('Submit')
  67. end
  68. expect(ChecklistTemplate.last.items.count).to eq(6)
  69. expect(ChecklistTemplate.last.items.last.text).to eq('Test Item')
  70. end
  71. end
  72. context 'when cloning a checklist' do
  73. before do
  74. create(:checklist_template, name: 'Test Checklist')
  75. visit 'manage/checklists'
  76. end
  77. it 'successfully creates a clone' do
  78. expect(page).to have_content('Test Checklist')
  79. find('.js-checklistTemplatesTable tr.item .js-action').click
  80. find('.js-table-action-menu .js-clone').click
  81. in_modal do
  82. click_on('Submit')
  83. end
  84. expect(page).to have_content('Clone: Test Checklist')
  85. expect(ChecklistTemplate.last.items.count).to eq(5)
  86. end
  87. end
  88. context 'when deleting a checklist' do
  89. before do
  90. create(:checklist_template, name: 'Test Checklist')
  91. visit 'manage/checklists'
  92. end
  93. it 'successfully creates a clone' do
  94. expect(page).to have_content('Test Checklist')
  95. find('.js-checklistTemplatesTable tr.item .js-action').click
  96. find('.js-table-action-menu .js-delete').click
  97. in_modal do
  98. click_on('delete')
  99. end
  100. expect(page).to have_no_content('Test Checklist')
  101. expect(ChecklistTemplate.count).to eq(0)
  102. end
  103. end
  104. end