3
  F   ˆl–Ãa¾”ªi?u8 ¸Û71hß�þY‘×qÀ³ÈVÆAÇüÿÎ„n²×Í_�uÐb&=LyZËcõÄÌ =v    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'
require 'system/examples/pagination_examples'

RSpec.describe 'Manage > Overviews', type: :system do
  let(:group) { create(:group) }

  let(:owner_one) { create(:agent, groups: [group]) }
  let(:owner_two)   { create(:agent, groups: [group]) }
  let(:owner_three) { create(:agent, groups: [group]) }

  let(:customer_one) { create(:customer, organization_id: organization_one.id, groups: [group]) }
  let(:customer_two)   { create(:customer, organization_id: organization_two.id, groups: [group]) }
  let(:customer_three) { create(:customer, organization_id: organization_three.id, groups: [group]) }

  let(:organization_one) { create(:organization, name: 'Test Org One') }
  let(:organization_two)   { create(:organization, name: 'Test Org Two') }
  let(:organization_three) { create(:organization, name: 'Test Org Three') }

  let!(:ticket_one) do
    create(:ticket,
           title:       'Test Ticket One',
           group:       group,
           owner_id:    owner_one.id,
           customer_id: customer_one.id)
  end

  let!(:ticket_two) do
    create(:ticket,
           title:       'Test Ticket Two',
           group:       group,
           owner_id:    owner_two.id,
           customer_id: customer_two.id)
  end

  let!(:ticket_three) do
    create(:ticket,
           title:       'Test Ticket Three',
           group:       group,
           owner_id:    owner_three.id,
           customer_id: customer_three.id)
  end

  let(:overview) { create(:overview, condition: condition) }

  context 'when ajax pagination' do
    include_examples 'pagination', model: :overview, klass: Overview, path: 'manage/overviews'
  end

  shared_examples 'previewing the correct ticket for single selected object' do
    before do
      wait.until { page.has_css?('.js-previewLoader.hide', visible: :all) }
      scroll_into_view('.ticket_selector')
    end

    context "with 'is' operator" do
      let(:operator) { 'is' }

      it 'shows selected customer ticket' do
        within '.js-preview .js-tableBody' do
          expect(page).to have_css('tr.item', text: ticket_one.title)
        end
      end

      it 'does not show customer ticket that is not selected' do
        within '.js-preview .js-tableBody' do
          expect(page).to have_no_css('tr.item', text: ticket_two.title)
          expect(page).to have_no_css('tr.item', text: ticket_three.title)
        end
      end
    end

    context "with 'is not' operator" do
      let(:operator) { 'is not' }

      it 'does not show selected customer ticket' do
        within '.js-preview .js-tableBody' do
          expect(page).to have_no_css('tr.item', text: ticket_one.title)
        end
      end

      it 'does not show customer ticket that is not selected' do
        within '.js-preview .js-tableBody' do
          expect(page).to have_css('tr.item', text: ticket_two.title)
          expect(page).to have_css('tr.item', text: ticket_three.title)
        end
      end
    end
  end

  shared_examples 'previewing the correct ticket for multiple selected objects' do
    before do
      wait.until { page.has_css?('.js-previewLoader.hide', visible: :all) }
      scroll_into_view('.ticket_selector')
    end

    context "with 'is' operator" do
      let(:operator) { 'is' }

      it 'shows selected customer ticket' do
        within '.js-preview .js-tableBody' do
          expect(page).to have_css('tr.item', text: ticket_one.title)
          expect(page).to have_css('tr.item', text: ticket_two.title)
        end
      end

      it 'does not show customer ticket that is not selected' do
        within '.js-preview .js-tableBody' do
          expect(page).to have_no_css('tr.item', text: ticket_three.title)
        end
      end
    end

    context "with 'is not' operator" do
      let(:operator) { 'is not' }

      it 'does not show selected customer ticket' do
        within '.js-preview .js-tableBody' do
