0
  E   ˆl–Ãa¾”ªi?u8 ¸Û71hß�þE+bYÇÌc![~@ùÄ„‚¿Ã_�uÐb&=LyZËcõÀÂ /R    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

# `path:` and `ticket:` accept a lambda, evaluated in the example, so records are not looked up at file load.
RSpec.shared_examples 'text modules' do |path:, ticket: nil|
  let(:text_modules_path)   { path.is_a?(Proc) ? instance_exec(&path) : path }
  let(:text_modules_ticket) { ticket.is_a?(Proc) ? instance_exec(&ticket) : ticket }

  describe 'basic examples', authenticated_as: :agent do
    let(:agent)                       { create(:agent, groups: [Group.find_by(name: 'Users'), group1, group2]) }
    let!(:agent_fixed_name)           { create(:agent, firstname: 'FFFF1', lastname: 'GGGG1', groups: [Group.find_by(name: 'Users')]) }
    let!(:group1)                     { create(:group) }
    let!(:group2)                     { create(:group) }
    let!(:text_module_without_group1) { create(:text_module, name: 'aaa', keywords: "test dummy #{Faker::Superhero.prefix}") }
    let!(:text_module_without_group2) { create(:text_module, name: 'bbb', keywords: "test dummy #{Faker::Superhero.prefix}") }
    let!(:text_module_group1)         { create(:text_module, name: 'ccc', keywords: "test dummy #{Faker::Superhero.prefix}", groups: [group1]) }
    let!(:text_module_group2)         { create(:text_module, name: 'ddd', keywords: "test dummy #{Faker::Superhero.prefix}", groups: [group2]) }

    it 'shows when send ::' do
      refresh # workaround to get new created objects from db
      visit text_modules_path
      within(:active_content) do
        set_tree_select_value('group_id', Group.first.name)
        find(:richtext).send_keys(':')
        find(:richtext).send_keys(':')
        expect(page).to have_selector(:text_module, text_module_without_group1.id)
      end
    end

    it 'does not break after usage of Ctrl/Command+Backspace' do
      visit text_modules_path
      within(:active_content) do
        find(:richtext).send_keys(':')
        find(:richtext).send_keys(':')
        find(:richtext).send_keys('bur')

        # The click is needed to get the focus back to the field for chrome.
        find(:richtext).click
        find(:richtext).send_keys([magic_key, :backspace])

        find(:richtext).send_keys('Some other text')
        find(:richtext).send_keys(:enter)
        expect(find(:richtext)).to have_text 'Some other text'
      end
    end

    it 'does not show when send :enter:' do
      visit text_modules_path
      within(:active_content) do
        set_tree_select_value('group_id', Group.first.name)
        find(:richtext).send_keys(':')
        find(:richtext).send_keys(:enter)
        find(:richtext).send_keys(':')
        expect(page).to have_no_selector(:text_module, text_module_without_group1.id)
        expect(page).to have_no_selector(:text_module, text_module_without_group2.id)
      end
    end

    it 'does not break search on backspace' do
      visit text_modules_path
      within(:active_content) do
        set_tree_select_value('group_id', Group.first.name)
        find(:richtext).send_keys('@@agen')
        find(:richtext).send_keys(:backspace)
        expect(page).to have_no_text('No results found')
      end
    end

    it 'does delete empty mentions (issue #3636 / FF only)' do
      visit text_modules_path
      within(:active_content) do
        set_tree_select_value('group_id', Group.first.name)
        find(:richtext).send_keys('@@FFFF1')
        await_empty_ajax_queue
        find(:richtext).send_keys(:enter)
        find(:richtext).send_keys(:enter)
        (agent_fixed_name.firstname.length + agent_fixed_name.lastname.length + 2).times do
          find(:richtext).send_keys(:backspace)
        end
        expect(find(:richtext)).to have_no_css('a[data-mention-user-id]', visible: :all)
      end
    end

    it 'does delete empty mentions (issue #3636 / simulation)' do
      visit text_modules_path
      within(:active_content) do
        set_tree_select_value('group_id', Group.first.name)
        find(:richtext).send_key