public_menu_spec.rb 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. # https://github.com/zammad/zammad/issues/266
  4. RSpec.describe 'Admin Panel > Knowledge Base > Public Menu', type: :system do
  5. include_context 'basic Knowledge Base'
  6. include_context 'Knowledge Base menu items'
  7. context 'lists menu items' do
  8. before do
  9. visit '/#manage/knowledge_base'
  10. find('a', text: 'Public Menu').click
  11. end
  12. it { expect(find_locale('Footer Menu', alternative_locale).text).to include menu_item_4.title }
  13. it { expect(find_locale('Header Menu', primary_locale).text).to include menu_item_1.title }
  14. it { expect(find_locale('Header Menu', alternative_locale).text).not_to include menu_item_2.title }
  15. it { expect(find_locale('Header Menu', primary_locale).text).to include menu_item_2.title }
  16. end
  17. context 'menu items color' do
  18. before do
  19. knowledge_base.update! color_header_link: color
  20. visit '/#manage/knowledge_base'
  21. find('a', text: 'Public Menu').click
  22. end
  23. let(:color) { 'rgb(255, 0, 255)' }
  24. it 'applies color for header preview' do
  25. elem = all('.kb-menu-preview a')[0]
  26. expect(elem).to have_computed_style :color, color
  27. end
  28. it 'does not apply color for footer preview' do
  29. elem = all('.kb-menu-preview a')[3]
  30. expect(elem).not_to have_computed_style :color, color
  31. end
  32. end
  33. context 'edit menu items' do
  34. before do
  35. visit '/#manage/knowledge_base'
  36. find('a', text: 'Public Menu').click
  37. find_location('Header Menu').find('a', text: 'Edit').click
  38. end
  39. it 'edit menu item' do
  40. in_modal do
  41. find('input') { |elem| elem.value == menu_item_1.title }.fill_in with: 'test menu'
  42. find('button', text: 'Submit').click
  43. end
  44. expect(find_locale('Header Menu', primary_locale).text).to include 'test menu'
  45. end
  46. it 'adds menu item' do
  47. in_modal do
  48. container = find(:css, 'h2', text: alternative_locale.system_locale.name).find(:xpath, '..')
  49. container.find('a', text: 'Add').click
  50. container.find('input') { |elem| elem['data-name'] == 'title' }.fill_in with: 'new item'
  51. container.find('input') { |elem| elem['data-name'] == 'url' }.fill_in with: '/new_item'
  52. find('button', text: 'Submit').click
  53. end
  54. expect(find_locale('Header Menu', alternative_locale).text).to include 'new item'
  55. end
  56. it 'deletes menu item' do
  57. in_modal do
  58. find('input') { |elem| elem.value == menu_item_1.title }
  59. .ancestor('tr')
  60. .find('.js-remove')
  61. .click
  62. find('button', text: 'Submit').click
  63. end
  64. expect(find_locale('Header Menu', alternative_locale).text).not_to include menu_item_1.title
  65. end
  66. end
  67. def find_locale(location, locale)
  68. find_location(location)
  69. .find('.label', text: %r{#{Regexp.escape locale.system_locale.name}}i)
  70. .ancestor('.kb-menu-preview')
  71. end
  72. def find_location(location)
  73. find('h3', text: location).ancestor('.settings-entry')
  74. end
  75. end